-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathPinCompetitionButton.tsx
More file actions
32 lines (29 loc) · 1015 Bytes
/
PinCompetitionButton.tsx
File metadata and controls
32 lines (29 loc) · 1015 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { usePinnedCompetitions } from '@/hooks/UsePinnedCompetitions';
import { useCompetition } from '@/hooks/queries/useCompetition';
import { Button } from '../Button';
export const PinCompetitionButton = ({ competitionId }: { competitionId: string }) => {
const { data, error } = useCompetition(competitionId);
const { pinnedCompetitions, pinCompetition, unpinCompetition } = usePinnedCompetitions();
const isPinned = pinnedCompetitions.some((c) => c.id === competitionId);
return (
<div>
<Button
variant="light"
className="flex items-center justify-center"
onClick={() => {
if (isPinned) {
unpinCompetition(competitionId);
} else if (data) {
pinCompetition(data);
}
}}
disabled={!data && !error}>
{isPinned ? (
<span className="fa fa-bookmark text-yellow-500" />
) : (
<span className="fa-regular fa-bookmark" />
)}
</Button>
</div>
);
};