forge
Explore
Log in

Don't you dare go Hollow

🎨 move appearance (theme/lang/palette) from admin panel to user profile dialog

Browse files at this commit

1f3ec378e5caa62fe6bed47574f68ef26138b656Burak BoduroğluParent: aca0494
  • refactor
    • 🎨 move appearance (theme/lang/palette) from admin panel to user profile dialog
Show full message
refactor(settings): 🎨 move appearance (theme/lang/palette) from admin panel to user profile dialog

- extract TRENDING_PALETTES into shared lib/palettes.ts
- account-profile-dialog: two-column layout (account + appearance section nav)
- appearance panel: theme toggle, language toggle, color palette picker
- user-menu: rename Edit profile → Settings with gear icon
- remove Appearance tab from admin settings page
src/components/layout/user-menu.tsxmodified+3 -3
@@ -13,7 +13,7 @@ import {
13 DropdownMenuSubTrigger,13 DropdownMenuSubTrigger,
14 DropdownMenuTrigger,14 DropdownMenuTrigger,
15 } from "@/components/ui/dropdown-menu";15 } from "@/components/ui/dropdown-menu";
16-import { IconChevronDown, IconEdit, IconGlobe, IconLogout, IconMoon, IconSun } from "@/components/ui/icons";16+import { IconChevronDown, IconGlobe, IconLogout, IconMoon, IconSettings, IconSun } from "@/components/ui/icons";
17 import { useAuth } from "@/stores/auth-context";17 import { useAuth } from "@/stores/auth-context";
18 import { usePreferences, useT } from "@/stores/preferences-context";18 import { usePreferences, useT } from "@/stores/preferences-context";
19 import { cn } from "@/lib/cn";19 import { cn } from "@/lib/cn";
@@ -180,8 +180,8 @@ export function UserMenu() {
180 <DropdownMenuSeparator />180 <DropdownMenuSeparator />
181 181
182 <DropdownMenuItem onSelect={() => setProfileOpen(true)}>182 <DropdownMenuItem onSelect={() => setProfileOpen(true)}>
183- <IconEdit class="h-4 w-4 shrink-0" />183+ <IconSettings class="h-4 w-4 shrink-0" />
184- <span>{t("profile.edit")}</span>184+ <span>{t("nav.settings")}</span>
185 </DropdownMenuItem>185 </DropdownMenuItem>
186 186
187 <DropdownMenuSeparator />187 <DropdownMenuSeparator />
src/components/users/account-profile-dialog.tsxmodified+132 -12
@@ -1,25 +1,145 @@
1-import { Show } from "solid-js";1+import { For, Match, Show, Switch, createSignal, type JSX } from "solid-js";
2-import { FormDialog } from "@/components/ui/form-dialog";2+import { Dialog, DialogContent, DialogTitle } from "@/components/ui/dialog";
3+import { IconCheck, IconSparkles, IconUserCog } from "@/components/ui/icons";
3 import { ProfileForm } from "@/components/users/profile-form";4 import { ProfileForm } from "@/components/users/profile-form";
5+import { cn } from "@/lib/cn";
6+import { TRENDING_PALETTES } from "@/lib/palettes";
4 import { useAuth } from "@/stores/auth-context";7 import { useAuth } from "@/stores/auth-context";
5-import { useT } from "@/stores/preferences-context";8+import { usePreferences, useT } from "@/stores/preferences-context";
6 9
10+type Section = "account" | "appearance";
11+
12+/**
13+ * Per-user settings, opened from the avatar menu. A left section rail (account
14+ * profile · appearance) with the matching panel on the right — appearance
15+ * gathers theme, language and accent colour, all personal browser preferences.
16+ */
7 export function AccountProfileDialog(props: { open: boolean; onOpenChange: (open: boolean) => void }) {17 export function AccountProfileDialog(props: { open: boolean; onOpenChange: (open: boolean) => void }) {
8 const auth = useAuth();18 const auth = useAuth();
19+ const prefs = usePreferences();
9 const t = useT();20 const t = useT();
21+ const [section, setSection] = createSignal<Section>("account");
22+
23+ const navItem = (id: Section, label: string, icon: JSX.Element) => (
24+ <button
25+ type="button"
26+ onClick={() => setSection(id)}
27+ aria-current={section() === id ? "page" : undefined}
28+ class={cn(
29+ "flex w-full items-center gap-2.5 rounded-lg px-3 py-2 text-left text-sm font-medium transition-colors outline-hidden focus-visible:ring-2 focus-visible:ring-ring",
30+ section() === id ? "bg-primary/10 text-primary" : "text-muted-foreground hover:bg-muted/70 hover:text-foreground",
31+ )}
32+ >
33+ {icon}
34+ <span class="truncate">{label}</span>
35+ </button>
36+ );
37+
38+ const seg = (active: boolean, label: string, onClick: () => void) => (
39+ <button
40+ type="button"
41+ aria-pressed={active}
42+ onClick={onClick}
43+ class={cn(
44+ "flex-1 rounded-md px-3 py-1.5 text-sm font-medium transition-colors outline-hidden focus-visible:ring-2 focus-visible:ring-ring",
45+ active ? "bg-background text-foreground shadow-xs" : "text-muted-foreground hover:text-foreground",
46+ )}
47+ >
48+ {label}
49+ </button>
50+ );
10 51
11 return (52 return (
12 <Show when={auth.user()} keyed>53 <Show when={auth.user()} keyed>
13 {(user) => (54 {(user) => (
14- <FormDialog open={props.open} onOpenChange={props.onOpenChange} title={user.username} description={t("profile.edit")}>55+ <Dialog open={props.open} onOpenChange={props.onOpenChange}>
15- <ProfileForm56+ <DialogContent class="max-w-2xl p-0">
16- user={user}57+ <div class="flex h-[min(80vh,32rem)] min-h-0">
17- onSaved={async () => {58+ <nav class="flex w-40 shrink-0 flex-col gap-1 border-r border-border/70 bg-muted/20 p-2">
18- await auth.refresh();59+ <DialogTitle class="px-3 pb-2 pt-1.5 text-sm">{t("nav.settings")}</DialogTitle>
19- props.onOpenChange(false);60+ {navItem("account", t("nav.account"), <IconUserCog class="h-4 w-4 shrink-0" />)}
20- }}61+ {navItem("appearance", t("settings.tabAppearance"), <IconSparkles class="h-4 w-4 shrink-0" />)}
21- />62+ </nav>
22- </FormDialog>63+
64+ <div class="min-w-0 flex-1 overflow-y-auto p-5 pr-12">
65+ <Switch>
66+ <Match when={section() === "account"}>
67+ <ProfileForm
68+ user={user}
69+ onSaved={async () => {
70+ await auth.refresh();
71+ props.onOpenChange(false);
72+ }}
73+ />
74+ </Match>
75+
76+ <Match when={section() === "appearance"}>
77+ <div class="space-y-6">
78+ <div class="space-y-2">
79+ <p class="text-sm font-semibold">{t("theme.toggle")}</p>
80+ <div class="flex max-w-xs gap-0.5 rounded-lg bg-muted p-0.5">
81+ {seg(prefs.theme() === "light", t("theme.light"), () => prefs.setTheme("light"))}
82+ {seg(prefs.theme() === "dark", t("theme.dark"), () => prefs.setTheme("dark"))}
83+ </div>
84+ </div>
85+
86+ <div class="space-y-2">
87+ <p class="text-sm font-semibold">{t("lang.label")}</p>
88+ <div class="flex max-w-xs gap-0.5 rounded-lg bg-muted p-0.5">
89+ {seg(prefs.locale() === "tr", t("lang.tr"), () => prefs.setLocale("tr"))}
90+ {seg(prefs.locale() === "en", t("lang.en"), () => prefs.setLocale("en"))}
91+ </div>
92+ </div>
93+
94+ <div class="space-y-2">
95+ <p class="text-sm font-semibold">{t("settings.colorPalette")}</p>
96+ <p class="text-xs text-muted-foreground">{t("settings.colorPaletteHelp")}</p>
97+ <div class="grid gap-3 sm:grid-cols-2">
98+ <For each={TRENDING_PALETTES}>
99+ {(palette) => (
100+ <div class="overflow-hidden rounded-xl border border-border/70 bg-card shadow-2xs">
101+ <div class="flex h-10" role="group" aria-label={palette.name}>
102+ <For each={palette.colors}>
103+ {(color) => (
104+ <button
105+ type="button"
106+ class="relative flex-1 outline-hidden focus-visible:z-10 focus-visible:ring-2 focus-visible:ring-foreground focus-visible:ring-inset"
107+ style={{ "background-color": color }}
108+ aria-label={`${palette.name} ${color}`}
109+ aria-pressed={prefs.paletteColor() === color}
110+ title={color}
111+ onClick={() => prefs.setPaletteColor(color)}
112+ >
113+ <Show when={prefs.paletteColor() === color}>
114+ <span class="absolute inset-0 grid place-items-center bg-black/15 text-white">
115+ <IconCheck class="h-4 w-4" />
116+ </span>
117+ </Show>
118+ </button>
119+ )}
120+ </For>
121+ </div>
122+ <p class="truncate px-3 py-1.5 text-xs font-medium">{palette.name}</p>
123+ </div>
124+ )}
125+ </For>
126+ </div>
127+ <button
128+ type="button"
129+ class="rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground disabled:pointer-events-none disabled:opacity-40"
130+ disabled={prefs.paletteColor() === null}
131+ onClick={() => prefs.setPaletteColor(null)}
132+ >
133+ {t("settings.defaultColor")}
134+ </button>
135+ </div>
136+ </div>
137+ </Match>
138+ </Switch>
139+ </div>
140+ </div>
141+ </DialogContent>
142+ </Dialog>
23 )}143 )}
24 </Show>144 </Show>
25 );145 );
src/lib/palettes.tsadded+10 -0
@@ -0,0 +1,10 @@
1+// Accent palettes offered in the per-user appearance picker (account menu).
2+// A user picks one accent hex; `preferences-context` turns it into CSS vars.
3+export const TRENDING_PALETTES = [
4+ { name: "Sunny Beach Day", colors: ["#264653", "#2a9d8f", "#e9c46a", "#f4a261", "#e76f51"] },
5+ { name: "Olive Garden Feast", colors: ["#606c38", "#283618", "#fefae0", "#dda15e", "#bc6c25"] },
6+ { name: "Summer Ocean Breeze", colors: ["#e63946", "#f1faee", "#a8dadc", "#457b9d", "#1d3557"] },
7+ { name: "Refreshing Summer Fun", colors: ["#8ecae6", "#219ebc", "#023047", "#ffb703", "#fb8500"] },
8+ { name: "Pastel Dreamland Adventure", colors: ["#cdb4db", "#ffc8dd", "#ffafcc", "#bde0fe", "#a2d2ff"] },
9+ { name: "Golden Summer Fields", colors: ["#ccd5ae", "#e9edc9", "#fefae0", "#faedcd", "#d4a373"] },
10+] as const;
src/pages/settings-page.tsxmodified+3 -64
@@ -1,4 +1,4 @@
1-import { For, Index, Show, Suspense, createEffect, createResource, createSignal } from "solid-js";1+import { Index, Show, Suspense, createEffect, createResource, createSignal } from "solid-js";
2 import { getSettings } from "@/api/settings";2 import { getSettings } from "@/api/settings";
3 import { patchSettings } from "@/api/settings";3 import { patchSettings } from "@/api/settings";
4 import { getLimits } from "@/api/limits";4 import { getLimits } from "@/api/limits";
@@ -10,7 +10,7 @@ import { Alert } from "@/components/ui/alert";
10 import { Badge } from "@/components/ui/badge";10 import { Badge } from "@/components/ui/badge";
11 import { Button } from "@/components/ui/button";11 import { Button } from "@/components/ui/button";
12 import { ErrorAlert } from "@/components/ui/error-alert";12 import { ErrorAlert } from "@/components/ui/error-alert";
13-import { IconCheck, IconPlus, IconTrash } from "@/components/ui/icons";13+import { IconPlus, IconTrash } from "@/components/ui/icons";
14 import { Input } from "@/components/ui/input";14 import { Input } from "@/components/ui/input";
15 import { Label } from "@/components/ui/label";15 import { Label } from "@/components/ui/label";
16 import { PageSpinner } from "@/components/ui/page-spinner";16 import { PageSpinner } from "@/components/ui/page-spinner";
@@ -18,7 +18,7 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
18 import { getAttendanceStatusMeta } from "@/lib/attendance-status";18 import { getAttendanceStatusMeta } from "@/lib/attendance-status";
19 import { cn } from "@/lib/cn";19 import { cn } from "@/lib/cn";
20 import { dirtySettingsPatch, minuteToUtcTime, utcTimeToMinute } from "@/lib/meals";20 import { dirtySettingsPatch, minuteToUtcTime, utcTimeToMinute } from "@/lib/meals";
21-import { usePreferences, useT } from "@/stores/preferences-context";21+import { useT } from "@/stores/preferences-context";
22 22
23 const CORE_ATTENDANCE = new Set(["present", "absent", "late", "excused"]);23 const CORE_ATTENDANCE = new Set(["present", "absent", "late", "excused"]);
24 const CORE_ATTENDANCE_LABELS = {24 const CORE_ATTENDANCE_LABELS = {
@@ -29,14 +29,6 @@ const CORE_ATTENDANCE_LABELS = {
29 } as const;29 } as const;
30 30
31 const BYTES_PER_MIB = 1024 * 1024;31 const BYTES_PER_MIB = 1024 * 1024;
32-const TRENDING_PALETTES = [
33- { name: "Sunny Beach Day", colors: ["#264653", "#2a9d8f", "#e9c46a", "#f4a261", "#e76f51"] },
34- { name: "Olive Garden Feast", colors: ["#606c38", "#283618", "#fefae0", "#dda15e", "#bc6c25"] },
35- { name: "Summer Ocean Breeze", colors: ["#e63946", "#f1faee", "#a8dadc", "#457b9d", "#1d3557"] },
36- { name: "Refreshing Summer Fun", colors: ["#8ecae6", "#219ebc", "#023047", "#ffb703", "#fb8500"] },
37- { name: "Pastel Dreamland Adventure", colors: ["#cdb4db", "#ffc8dd", "#ffafcc", "#bde0fe", "#a2d2ff"] },
38- { name: "Golden Summer Fields", colors: ["#ccd5ae", "#e9edc9", "#fefae0", "#faedcd", "#d4a373"] },
39-] as const;
40 32
41 // Neutralize the Tabs.Content card so it is just a container — the sections33 // Neutralize the Tabs.Content card so it is just a container — the sections
42 // inside already carry their own `data-shell` surfaces.34 // inside already carry their own `data-shell` surfaces.
@@ -56,7 +48,6 @@ export default function SettingsPage() {
56 48
57 function SettingsContent() {49 function SettingsContent() {
58 const t = useT();50 const t = useT();
59- const preferences = usePreferences();
60 const [settings, { refetch, mutate }] = createResource(() => getSettings());51 const [settings, { refetch, mutate }] = createResource(() => getSettings());
61 const [examKinds, setExamKinds] = createSignal<ExamKindSetting[]>([]);52 const [examKinds, setExamKinds] = createSignal<ExamKindSetting[]>([]);
62 const [attendanceStatuses, setAttendanceStatuses] = createSignal<string[]>([]);53 const [attendanceStatuses, setAttendanceStatuses] = createSignal<string[]>([]);
@@ -187,7 +178,6 @@ function SettingsContent() {
187 <TabsTrigger value="assessment">{t("settings.tabAssessment")}</TabsTrigger>178 <TabsTrigger value="assessment">{t("settings.tabAssessment")}</TabsTrigger>
188 <TabsTrigger value="meals">{t("settings.tabMeals")}</TabsTrigger>179 <TabsTrigger value="meals">{t("settings.tabMeals")}</TabsTrigger>
189 <TabsTrigger value="system">{t("settings.tabSystem")}</TabsTrigger>180 <TabsTrigger value="system">{t("settings.tabSystem")}</TabsTrigger>
190- <TabsTrigger value="appearance">{t("settings.tabAppearance")}</TabsTrigger>
191 </TabsList>181 </TabsList>
192 182
193 <Suspense fallback={<PageSpinner />}>183 <Suspense fallback={<PageSpinner />}>
@@ -590,57 +580,6 @@ function SettingsContent() {
590 </Show>580 </Show>
591 </TabsContent>581 </TabsContent>
592 </Suspense>582 </Suspense>
593-
594- <TabsContent value="appearance" class={TAB_PANEL}>
595- <section class="data-shell space-y-4 p-4">
596- <div>
597- <h2 class="font-display text-base font-semibold">{t("settings.colorPalette")}</h2>
598- <p class="mt-1 text-sm text-muted-foreground">{t("settings.colorPaletteHelp")}</p>
599- </div>
600-
601- <div class="grid gap-3 md:grid-cols-2 xl:grid-cols-3">
602- <For each={TRENDING_PALETTES}>
603- {(palette) => (
604- <div class="overflow-hidden rounded-xl border border-border/70 bg-card shadow-2xs">
605- <div class="flex h-12" role="group" aria-label={palette.name}>
606- <For each={palette.colors}>
607- {(color) => (
608- <button
609- type="button"
610- class="relative flex-1 outline-hidden focus-visible:z-10 focus-visible:ring-2 focus-visible:ring-foreground focus-visible:ring-inset"
611- style={{ "background-color": color }}
612- aria-label={`${palette.name} ${color}`}
613- aria-pressed={preferences.paletteColor() === color}
614- title={color}
615- onClick={() => preferences.setPaletteColor(color)}
616- >
617- <Show when={preferences.paletteColor() === color}>
618- <span class="absolute inset-0 grid place-items-center bg-black/15 text-white drop-shadow-md">
619- <IconCheck class="h-4 w-4" />
620- </span>
621- </Show>
622- </button>
623- )}
624- </For>
625- </div>
626- <p class="truncate px-3 py-2 text-xs font-medium">{palette.name}</p>
627- </div>
628- )}
629- </For>
630- </div>
631-
632- <Button
633- type="button"
634- variant="outline"
635- size="sm"
636- class="rounded-lg"
637- disabled={preferences.paletteColor() === null}
638- onClick={() => preferences.setPaletteColor(null)}
639- >
640- {t("settings.defaultColor")}
641- </Button>
642- </section>
643- </TabsContent>
644 </Tabs>583 </Tabs>
645 </div>584 </div>
646 );585 );