| 1 | "use client"; |
| 2 | |
| 3 | import { Eye, EyeOff |
| 4 | import { useAction } |
| 5 | import { toast } |
| 6 | |
| 7 | import { Button } |
| 8 | import { |
| 9 | DropdownMenu, |
| 10 | DropdownMenuContent, |
| 11 | DropdownMenuRadioGroup, |
| 12 | DropdownMenuRadioItem, |
| 13 | DropdownMenuTrigger, |
| 14 | } from "@/components/ui/dropdown-menu"; |
| 15 | import { Spinner } |
| 16 | |
| 17 | import { setRepositoryWatch } |
| 18 | import { type WatchLevel, |
| 19 | |
| 20 | const LEVELS: Record |
| 21 | participating: { |
| 22 | label: "Participating and @mentions", |
| 23 | description: "Only threads you take part in or are mentioned in.", |
| 24 | }, |
| 25 | all: { |
| 26 | label: "All activity", |
| 27 | description: "Every issue and pull request.", |
| 28 | }, |
| 29 | ignore: { |
| 30 | label: "Ignore", |
| 31 | description: "Nothing, not even mentions.", |
| 32 | }, |
| 33 | }; |
| 34 | |
| 35 | export function WatchButton({ |
| 36 | username, |
| 37 | repo, |
| 38 | level, |
| 39 | }: { |
| 40 | username: string |
| 41 | repo: string |
| 42 | level: WatchLevel |
| 43 | }) { |
| 44 | const { execute, |
| 45 | onError: ({ error |
| 46 | toast.error(error |
| 47 | }); |
| 48 | const Icon = |
| 49 | |
| 50 | return ( |
| 51 | <DropdownMenu> |
| 52 | <DropdownMenuTrigger asChild> |
| 53 | <Button variant=" |
| 54 | {isExecuting ? <Spinner |
| 55 | {level === "all |
| 56 | </Button> |
| 57 | </DropdownMenuTrigger> |
| 58 | <DropdownMenuContent align=" |
| 59 | <DropdownMenuRadioGroup |
| 60 | value={level} |
| 61 | onValueChange={(next) |
| 62 | execute({ username, |
| 63 | } |
| 64 | > |
| 65 | {watchLevels.map(( |
| 66 | <DropdownMenuRadioItem key={ |
| 67 | <div className="flex flex-col |
| 68 | <span className="font-medium |
| 69 | <span className="text-xs text-muted-foreground |
| 70 | {LEVELS[value]. |
| 71 | </span> |
| 72 | </div> |
| 73 | </DropdownMenuRadioItem> |
| 74 | ))} |
| 75 | </DropdownMenuRadioGroup> |
| 76 | </DropdownMenuContent> |
| 77 | </DropdownMenu> |
| 78 | ); |
| 79 | } |