|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; |
| 4 | +import { UserAvatar } from "@/components/userAvatar"; |
| 5 | +import { HomeView, useHomeView } from "@/hooks/useHomeView"; |
| 6 | +import { useKeymapType } from "@/hooks/useKeymapType"; |
| 7 | +import { KeymapType } from "@/lib/types"; |
| 8 | +import { useTheme } from "next-themes"; |
| 9 | +import { useMemo } from "react"; |
| 10 | +import { BasicSettingsCard, SettingsCard, SettingsCardGroup } from "../components/settingsCard"; |
| 11 | + |
| 12 | +const themeOptions = [ |
| 13 | + { value: "light", label: "Light" }, |
| 14 | + { value: "dark", label: "Dark" }, |
| 15 | + { value: "system", label: "System" }, |
| 16 | +] as const; |
| 17 | + |
| 18 | +const homeViewOptions = [ |
| 19 | + { value: "search", label: "Code Search" }, |
| 20 | + { value: "ask", label: "Ask" }, |
| 21 | +] as const; |
| 22 | + |
| 23 | +const keymapOptions = [ |
| 24 | + { value: "default", label: "Standard" }, |
| 25 | + { value: "vim", label: "Vim" }, |
| 26 | +] as const; |
| 27 | + |
| 28 | +interface GeneralPageProps { |
| 29 | + userName?: string; |
| 30 | + userEmail?: string; |
| 31 | + userImage?: string; |
| 32 | +} |
| 33 | + |
| 34 | +export function GeneralPage({ userName, userEmail, userImage }: GeneralPageProps) { |
| 35 | + const { theme: _theme, setTheme } = useTheme(); |
| 36 | + const [homeView, setHomeView] = useHomeView(); |
| 37 | + const [keymapType, setKeymapType] = useKeymapType(); |
| 38 | + |
| 39 | + const theme = useMemo(() => { |
| 40 | + return _theme ?? "light"; |
| 41 | + }, [_theme]); |
| 42 | + |
| 43 | + return ( |
| 44 | + <div className="flex flex-col gap-6"> |
| 45 | + <div> |
| 46 | + <h3 className="text-lg font-medium">General</h3> |
| 47 | + <p className="text-sm text-muted-foreground"> |
| 48 | + Manage your profile and preferences. |
| 49 | + </p> |
| 50 | + </div> |
| 51 | + |
| 52 | + <div className="flex flex-col gap-2"> |
| 53 | + <h4 className="text-sm font-medium text-muted-foreground">Profile</h4> |
| 54 | + <SettingsCard> |
| 55 | + <div className="flex items-center gap-4"> |
| 56 | + <UserAvatar |
| 57 | + email={userEmail} |
| 58 | + imageUrl={userImage} |
| 59 | + className="h-12 w-12" |
| 60 | + /> |
| 61 | + <div className="flex flex-col"> |
| 62 | + <span className="font-medium">{userName ?? "User"}</span> |
| 63 | + {userEmail && ( |
| 64 | + <span className="text-sm text-muted-foreground">{userEmail}</span> |
| 65 | + )} |
| 66 | + </div> |
| 67 | + </div> |
| 68 | + </SettingsCard> |
| 69 | + </div> |
| 70 | + |
| 71 | + <div className="flex flex-col gap-2"> |
| 72 | + <h4 className="text-sm font-medium text-muted-foreground">Preferences</h4> |
| 73 | + <SettingsCardGroup> |
| 74 | + <BasicSettingsCard name="Default home view" description="Choose which page to show when you open Sourcebot."> |
| 75 | + <Select value={homeView} onValueChange={(value) => setHomeView(value as HomeView)}> |
| 76 | + <SelectTrigger className="w-36"> |
| 77 | + <SelectValue /> |
| 78 | + </SelectTrigger> |
| 79 | + <SelectContent> |
| 80 | + {homeViewOptions.map((option) => ( |
| 81 | + <SelectItem key={option.value} value={option.value}> |
| 82 | + {option.label} |
| 83 | + </SelectItem> |
| 84 | + ))} |
| 85 | + </SelectContent> |
| 86 | + </Select> |
| 87 | + </BasicSettingsCard> |
| 88 | + <BasicSettingsCard name="Appearance" description="Choose how Sourcebot looks to you."> |
| 89 | + <Select value={theme} onValueChange={setTheme}> |
| 90 | + <SelectTrigger className="w-36"> |
| 91 | + <SelectValue /> |
| 92 | + </SelectTrigger> |
| 93 | + <SelectContent> |
| 94 | + {themeOptions.map((option) => ( |
| 95 | + <SelectItem key={option.value} value={option.value}> |
| 96 | + {option.label} |
| 97 | + </SelectItem> |
| 98 | + ))} |
| 99 | + </SelectContent> |
| 100 | + </Select> |
| 101 | + </BasicSettingsCard> |
| 102 | + <BasicSettingsCard name="Editor keymap" description="Choose the keyboard shortcuts used in the code viewer."> |
| 103 | + <Select value={keymapType} onValueChange={(value) => setKeymapType(value as KeymapType)}> |
| 104 | + <SelectTrigger className="w-36"> |
| 105 | + <SelectValue /> |
| 106 | + </SelectTrigger> |
| 107 | + <SelectContent> |
| 108 | + {keymapOptions.map((option) => ( |
| 109 | + <SelectItem key={option.value} value={option.value}> |
| 110 | + {option.label} |
| 111 | + </SelectItem> |
| 112 | + ))} |
| 113 | + </SelectContent> |
| 114 | + </Select> |
| 115 | + </BasicSettingsCard> |
| 116 | + </SettingsCardGroup> |
| 117 | + </div> |
| 118 | + </div> |
| 119 | + ); |
| 120 | +} |
0 commit comments