✨ role-based command palette with quick actions and centered search bar
Browse files at this commit06a375c4abd3abf6db1f4ef80401d7655bbac7e3Parent: c563a97- feat
- ✨ role-based command palette with quick actions and centered search bar
11 changed files +819 -193
- src/components/layout/app-shell.tsx +40 -7
- src/components/layout/command-palette.tsx +469 -0
- src/components/layout/nav-items.ts +169 -0
- src/components/layout/side-nav.tsx +4 -171
- src/i18n/messages.ts +87 -0
- src/pages/courses-page.tsx +7 -2
- src/pages/events-page.tsx +9 -3
- src/pages/exams-page.tsx +8 -2
- src/pages/homework-page.tsx +8 -2
- src/pages/notes-page.tsx +9 -3
- src/pages/questions-page.tsx +9 -3
src/components/layout/app-shell.tsxmodified+40 -7
| @@ -1,13 +1,15 @@ | |||
| 1 | import type { ParentProps } from "solid-js"; | 1 | import type { ParentProps } from "solid-js"; |
| 2 | import { Link, useLocation, useNavigate } from "@tanstack/solid-router"; | 2 | import { Link, useLocation, useNavigate } from "@tanstack/solid-router"; |
| 3 | +import { AccountProfileDialog } from "@/components/users/account-profile-dialog"; | ||
| 3 | import { CelebiPanel } from "@/components/layout/celebi-panel"; | 4 | import { CelebiPanel } from "@/components/layout/celebi-panel"; |
| 4 | import { Show, createMemo, createSignal } from "solid-js"; | 5 | import { Show, createMemo, createSignal } from "solid-js"; |
| 6 | +import { CommandPalette } from "@/components/layout/command-palette"; | ||
| 5 | import { MobileTabBar } from "@/components/layout/mobile-tab-bar"; | 7 | import { MobileTabBar } from "@/components/layout/mobile-tab-bar"; |
| 6 | import { NavBar } from "@/components/layout/nav-bar"; | 8 | import { NavBar } from "@/components/layout/nav-bar"; |
| 7 | import { SideNav } from "@/components/layout/side-nav"; | 9 | import { SideNav } from "@/components/layout/side-nav"; |
| 8 | import { SidebarAccount } from "@/components/layout/sidebar-account"; | 10 | import { SidebarAccount } from "@/components/layout/sidebar-account"; |
| 9 | import { Button } from "@/components/ui/button"; | 11 | import { Button } from "@/components/ui/button"; |
| 10 | -import { IconPanelLeft, IconSparkles, IconX } from "@/components/ui/icons"; | 12 | +import { IconPanelLeft, IconSearch, IconSparkles, IconX } from "@/components/ui/icons"; |
| 11 | import { Toaster } from "@/components/ui/toast"; | 13 | import { Toaster } from "@/components/ui/toast"; |
| 12 | import { useAuth } from "@/stores/auth-context"; | 14 | import { useAuth } from "@/stores/auth-context"; |
| 13 | import { usePreferences, useT } from "@/stores/preferences-context"; | 15 | import { usePreferences, useT } from "@/stores/preferences-context"; |
| @@ -23,6 +25,8 @@ export function AppShell(props: ParentProps) { | |||
| 23 | const navigate = useNavigate(); | 25 | const navigate = useNavigate(); |
| 24 | const [mobileOpen, setMobileOpen] = createSignal(false); | 26 | const [mobileOpen, setMobileOpen] = createSignal(false); |
| 25 | const [celebiOpen, setCelebiOpen] = createSignal(false); | 27 | const [celebiOpen, setCelebiOpen] = createSignal(false); |
| 28 | + const [commandOpen, setCommandOpen] = createSignal(false); | ||
| 29 | + const [profileOpen, setProfileOpen] = createSignal(false); | ||
| 26 | const collapsed = () => prefs.sidebarCollapsed(); | 30 | const collapsed = () => prefs.sidebarCollapsed(); |
| 27 | const location = useLocation(); | 31 | const location = useLocation(); |
| 28 | const wide = () => location().pathname.startsWith("/exam-room/") || location().searchStr.includes("answerUser=") || location().pathname === "/messages"; | 32 | const wide = () => location().pathname.startsWith("/exam-room/") || location().searchStr.includes("answerUser=") || location().pathname === "/messages"; |
| @@ -149,13 +153,35 @@ export function AppShell(props: ParentProps) { | |||
| 149 | <main class="min-w-0 flex-1"> | 153 | <main class="min-w-0 flex-1"> |
| 150 | <Show when={auth.user() && !fullScreen()}> | 154 | <Show when={auth.user() && !fullScreen()}> |
| 151 | <header class="sticky top-0 z-30 hig-translucent-bar flex h-14 items-center justify-between gap-3 px-4 sm:px-6 lg:px-8"> | 155 | <header class="sticky top-0 z-30 hig-translucent-bar flex h-14 items-center justify-between gap-3 px-4 sm:px-6 lg:px-8"> |
| 152 | - <div class="min-w-0 rounded-full border border-black/[0.06] dark:border-white/[0.08] bg-card/80 px-3.5 py-1 text-xs font-semibold text-muted-foreground shadow-sm"> | 156 | + <div class="flex flex-1 items-center justify-start min-w-0"> |
| 153 | - <span class="block truncate">{routeLabel()}</span> | 157 | + <div class="rounded-full border border-black/[0.06] dark:border-white/[0.08] bg-card/80 px-3.5 py-1 text-xs font-semibold text-muted-foreground shadow-sm"> |
| 158 | + <span class="block truncate max-w-[120px] sm:max-w-none">{routeLabel()}</span> | ||
| 159 | + </div> | ||
| 160 | + </div> | ||
| 161 | + | ||
| 162 | + <div class="flex flex-1 items-center justify-center max-w-md min-w-0"> | ||
| 163 | + <button | ||
| 164 | + type="button" | ||
| 165 | + onClick={() => setCommandOpen(true)} | ||
| 166 | + class="flex h-9 w-full items-center justify-between gap-2.5 rounded-full border border-black/[0.08] dark:border-white/[0.12] bg-secondary/60 px-3.5 text-xs font-medium text-muted-foreground shadow-2xs transition-all hover:bg-secondary hover:text-foreground hover:border-border/80" | ||
| 167 | + title={t("dashboard.commandCenter")} | ||
| 168 | + > | ||
| 169 | + <div class="flex items-center gap-2 min-w-0"> | ||
| 170 | + <IconSearch class="h-3.5 w-3.5 shrink-0 text-muted-foreground" /> | ||
| 171 | + <span class="truncate">{t("dashboard.commandCenter")}...</span> | ||
| 172 | + </div> | ||
| 173 | + <kbd class="hidden shrink-0 rounded-md border border-border/80 bg-background/80 px-1.5 py-0.5 font-mono text-[10px] font-semibold text-muted-foreground sm:inline-block"> | ||
| 174 | + Ctrl/Cmd K | ||
| 175 | + </kbd> | ||
| 176 | + </button> | ||
| 177 | + </div> | ||
| 178 | + | ||
| 179 | + <div class="flex flex-1 items-center justify-end min-w-0"> | ||
| 180 | + <Button type="button" variant="default" size="sm" class="h-9 rounded-full shrink-0" onClick={() => setCelebiOpen(true)}> | ||
| 181 | + <IconSparkles class="h-4 w-4" /> | ||
| 182 | + <span class="hidden sm:inline">{t("ai.askCelebi")}</span> | ||
| 183 | + </Button> | ||
| 154 | </div> | 184 | </div> |
| 155 | - <Button type="button" variant="default" size="sm" class="h-9 rounded-full" onClick={() => setCelebiOpen(true)}> | ||
| 156 | - <IconSparkles class="h-4 w-4" /> | ||
| 157 | - {t("ai.askCelebi")} | ||
| 158 | - </Button> | ||
| 159 | </header> | 185 | </header> |
| 160 | </Show> | 186 | </Show> |
| 161 | <div | 187 | <div |
| @@ -174,6 +200,13 @@ export function AppShell(props: ParentProps) { | |||
| 174 | </Show> | 200 | </Show> |
| 175 | <Show when={auth.user()}> | 201 | <Show when={auth.user()}> |
| 176 | <CelebiPanel open={celebiOpen()} onOpenChange={setCelebiOpen} /> | 202 | <CelebiPanel open={celebiOpen()} onOpenChange={setCelebiOpen} /> |
| 203 | + <CommandPalette | ||
| 204 | + open={commandOpen()} | ||
| 205 | + onOpenChange={setCommandOpen} | ||
| 206 | + onOpenCelebi={() => setCelebiOpen(true)} | ||
| 207 | + onOpenProfile={() => setProfileOpen(true)} | ||
| 208 | + /> | ||
| 209 | + <AccountProfileDialog open={profileOpen()} onOpenChange={setProfileOpen} /> | ||
| 177 | </Show> | 210 | </Show> |
| 178 | <Toaster /> | 211 | <Toaster /> |
| 179 | </div> | 212 | </div> |
src/components/layout/command-palette.tsxadded+469 -0
| @@ -0,0 +1,469 @@ | |||
| 1 | +import { useNavigate } from "@tanstack/solid-router"; | ||
| 2 | +import { For, Show, createEffect, createMemo, createSignal, onCleanup, onMount } from "solid-js"; | ||
| 3 | +import { Dialog, DialogContent, DialogDescription, DialogTitle } from "@/components/ui/dialog"; | ||
| 4 | +import { Input } from "@/components/ui/input"; | ||
| 5 | +import { | ||
| 6 | + IconBook, | ||
| 7 | + IconCalendar, | ||
| 8 | + IconDownload, | ||
| 9 | + IconExam, | ||
| 10 | + IconGlobe, | ||
| 11 | + IconHomework, | ||
| 12 | + IconLogout, | ||
| 13 | + IconMoon, | ||
| 14 | + IconNote, | ||
| 15 | + IconPencilQuestion, | ||
| 16 | + IconSearch, | ||
| 17 | + IconSparkles, | ||
| 18 | + IconSun, | ||
| 19 | + IconUsers, | ||
| 20 | +} from "@/components/ui/icons"; | ||
| 21 | +import { HOME_ITEM, visibleNavGroups } from "@/components/layout/nav-items"; | ||
| 22 | +import { hasMinRole } from "@/lib/roles"; | ||
| 23 | +import { useAuth } from "@/stores/auth-context"; | ||
| 24 | +import { usePreferences, useT } from "@/stores/preferences-context"; | ||
| 25 | +import { cn } from "@/lib/cn"; | ||
| 26 | + | ||
| 27 | +export type CommandPaletteProps = { | ||
| 28 | + open: boolean; | ||
| 29 | + onOpenChange: (open: boolean) => void; | ||
| 30 | + onOpenCelebi?: () => void; | ||
| 31 | + onOpenProfile?: () => void; | ||
| 32 | +}; | ||
| 33 | + | ||
| 34 | +type CommandCategory = "actions" | "pages" | "system"; | ||
| 35 | + | ||
| 36 | +type CommandItem = { | ||
| 37 | + id: string; | ||
| 38 | + category: CommandCategory; | ||
| 39 | + categoryLabel: string; | ||
| 40 | + title: string; | ||
| 41 | + description?: string; | ||
| 42 | + keywords?: string; | ||
| 43 | + icon: typeof IconSearch; | ||
| 44 | + shortcut?: string; | ||
| 45 | + roleBadge?: string; | ||
| 46 | + onSelect: () => void; | ||
| 47 | +}; | ||
| 48 | + | ||
| 49 | +export function CommandPalette(props: CommandPaletteProps) { | ||
| 50 | + const auth = useAuth(); | ||
| 51 | + const prefs = usePreferences(); | ||
| 52 | + const t = useT(); | ||
| 53 | + const navigate = useNavigate(); | ||
| 54 | + | ||
| 55 | + const [query, setQuery] = createSignal(""); | ||
| 56 | + const [selectedIndex, setSelectedIndex] = createSignal(0); | ||
| 57 | + let inputRef: HTMLInputElement | undefined; | ||
| 58 | + let listRef: HTMLDivElement | undefined; | ||
| 59 | + | ||
| 60 | + const role = () => auth.user()?.role; | ||
| 61 | + | ||
| 62 | + const items = createMemo<CommandItem[]>(() => { | ||
| 63 | + const list: CommandItem[] = []; | ||
| 64 | + const userRole = role(); | ||
| 65 | + const isTeacherPlus = hasMinRole(userRole, "teacher"); | ||
| 66 | + const isStudent = userRole === "student"; | ||
| 67 | + | ||
| 68 | + const isMac = typeof navigator !== "undefined" && (navigator.userAgent.includes("Mac") || navigator.platform?.includes("Mac")); | ||
| 69 | + const mod = isMac ? "⌘" : "Ctrl+"; | ||
| 70 | + | ||
| 71 | + // 1. Quick Actions (Hızlı İşlemler) | ||
| 72 | + const actionsCategoryLabel = t("command.group.actions"); | ||
| 73 | + | ||
| 74 | + if (isTeacherPlus) { | ||
| 75 | + list.push({ | ||
| 76 | + id: "action-create-homework", | ||
| 77 | + category: "actions", | ||
| 78 | + categoryLabel: actionsCategoryLabel, | ||
| 79 | + title: t("command.action.createHomework"), | ||
| 80 | + description: t("command.action.createHomeworkDesc"), | ||
| 81 | + keywords: "homework odev ekle olustur ders", | ||
| 82 | + icon: IconHomework, | ||
| 83 | + shortcut: `${mod}H`, | ||
| 84 | + roleBadge: t("role.teacher"), | ||
| 85 | + onSelect: () => void navigate({ to: "/homework", search: { action: "new" } as any }), | ||
| 86 | + }); | ||
| 87 | + | ||
| 88 | + list.push({ | ||
| 89 | + id: "action-create-course", | ||
| 90 | + category: "actions", | ||
| 91 | + categoryLabel: actionsCategoryLabel, | ||
| 92 | + title: t("command.action.createCourse"), | ||
| 93 | + description: t("command.action.createCourseDesc"), | ||
| 94 | + keywords: "course ders kurs olustur egitim", | ||
| 95 | + icon: IconBook, | ||
| 96 | + shortcut: `${mod}C`, | ||
| 97 | + roleBadge: t("role.teacher"), | ||
| 98 | + onSelect: () => void navigate({ to: "/courses", search: { action: "new" } as any }), | ||
| 99 | + }); | ||
| 100 | + | ||
| 101 | + list.push({ | ||
| 102 | + id: "action-create-event", | ||
| 103 | + category: "actions", | ||
| 104 | + categoryLabel: actionsCategoryLabel, | ||
| 105 | + title: t("command.action.createEvent"), | ||
| 106 | + description: t("command.action.createEventDesc"), | ||
| 107 | + keywords: "event etkinlik planla takvim oturum", | ||
| 108 | + icon: IconCalendar, | ||
| 109 | + shortcut: `${mod}E`, | ||
| 110 | + roleBadge: t("role.teacher"), | ||
| 111 | + onSelect: () => void navigate({ to: "/events", search: { action: "new" } as any }), | ||
| 112 | + }); | ||
| 113 | + | ||
| 114 | + list.push({ | ||
| 115 | + id: "action-create-exam", | ||
| 116 | + category: "actions", | ||
| 117 | + categoryLabel: actionsCategoryLabel, | ||
| 118 | + title: t("command.action.createExam"), | ||
| 119 | + description: t("command.action.createExamDesc"), | ||
| 120 | + keywords: "exam sinav test hazirla olustur", | ||
| 121 | + icon: IconExam, | ||
| 122 | + shortcut: `${mod}X`, | ||
| 123 | + roleBadge: t("role.teacher"), | ||
| 124 | + onSelect: () => void navigate({ to: "/exams", search: { action: "new" } as any }), | ||
| 125 | + }); | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + // Common Quick Actions for all roles | ||
| 129 | + list.push({ | ||
| 130 | + id: "action-create-note", | ||
| 131 | + category: "actions", | ||
| 132 | + categoryLabel: actionsCategoryLabel, | ||
| 133 | + title: t("command.action.createNote"), | ||
| 134 | + description: t("command.action.createNoteDesc"), | ||
| 135 | + keywords: "note not ekle ders notu kaydet", | ||
| 136 | + icon: IconNote, | ||
| 137 | + shortcut: `${mod}N`, | ||
| 138 | + onSelect: () => void navigate({ to: "/notes", search: { action: "new" } as any }), | ||
| 139 | + }); | ||
| 140 | + | ||
| 141 | + list.push({ | ||
| 142 | + id: "action-import-note", | ||
| 143 | + category: "actions", | ||
| 144 | + categoryLabel: actionsCategoryLabel, | ||
| 145 | + title: t("command.action.importNote"), | ||
| 146 | + description: t("command.action.importNoteDesc"), | ||
| 147 | + keywords: "import ice aktar pdf txt markdown assistant", | ||
| 148 | + icon: IconDownload, | ||
| 149 | + onSelect: () => void navigate({ to: "/notes", search: { action: "import" } as any }), | ||
| 150 | + }); | ||
| 151 | + | ||
| 152 | + list.push({ | ||
| 153 | + id: "action-ask-question", | ||
| 154 | + category: "actions", | ||
| 155 | + categoryLabel: actionsCategoryLabel, | ||
| 156 | + title: t("command.action.askQuestion"), | ||
| 157 | + description: t("command.action.askQuestionDesc"), | ||
| 158 | + keywords: "question soru sor havuz ekle topluluk", | ||
| 159 | + icon: IconPencilQuestion, | ||
| 160 | + shortcut: `${mod}Q`, | ||
| 161 | + roleBadge: isStudent ? t("role.student") : undefined, | ||
| 162 | + onSelect: () => void navigate({ to: "/questions", search: { action: "new" } as any }), | ||
| 163 | + }); | ||
| 164 | + | ||
| 165 | + if (props.onOpenCelebi) { | ||
| 166 | + list.push({ | ||
| 167 | + id: "action-ask-celebi", | ||
| 168 | + category: "actions", | ||
| 169 | + categoryLabel: actionsCategoryLabel, | ||
| 170 | + title: t("command.action.askCelebi"), | ||
| 171 | + description: t("command.action.askCelebiDesc"), | ||
| 172 | + keywords: "celebi ai yapay zeka sohbet asistan yardım", | ||
| 173 | + icon: IconSparkles, | ||
| 174 | + onSelect: () => props.onOpenCelebi?.(), | ||
| 175 | + }); | ||
| 176 | + } | ||
| 177 | + | ||
| 178 | + if (props.onOpenProfile) { | ||
| 179 | + list.push({ | ||
| 180 | + id: "action-my-profile", | ||
| 181 | + category: "actions", | ||
| 182 | + categoryLabel: actionsCategoryLabel, | ||
| 183 | + title: t("command.action.myProfile"), | ||
| 184 | + description: t("command.action.myProfileDesc"), | ||
| 185 | + keywords: "profile profil hesabim kullanici sifre", | ||
| 186 | + icon: IconUsers, | ||
| 187 | + onSelect: () => props.onOpenProfile?.(), | ||
| 188 | + }); | ||
| 189 | + } | ||
| 190 | + | ||
| 191 | + // 2. Navigation Pages (Sayfalar & Gezinme) | ||
| 192 | + const pagesCategoryLabel = t("command.group.navigation"); | ||
| 193 | + | ||
| 194 | + list.push({ | ||
| 195 | + id: "page-home", | ||
| 196 | + category: "pages", | ||
| 197 | + categoryLabel: pagesCategoryLabel, | ||
| 198 | + title: t(HOME_ITEM.labelKey), | ||
| 199 | + description: t("app.name"), | ||
| 200 | + keywords: "home anasayfa kontrol paneli dashboard", | ||
| 201 | + icon: HOME_ITEM.Icon, | ||
| 202 | + onSelect: () => void navigate({ to: HOME_ITEM.to }), | ||
| 203 | + }); | ||
| 204 | + | ||
| 205 | + for (const group of visibleNavGroups(userRole)) { | ||
| 206 | + const groupName = t(group.labelKey); | ||
| 207 | + for (const item of group.items) { | ||
| 208 | + list.push({ | ||
| 209 | + id: `page-${item.to}`, | ||
| 210 | + category: "pages", | ||
| 211 | + categoryLabel: pagesCategoryLabel, | ||
| 212 | + title: t(item.labelKey), | ||
| 213 | + description: groupName, | ||
| 214 | + keywords: `${item.to} ${t(item.labelKey)} ${groupName}`, | ||
| 215 | + icon: item.Icon, | ||
| 216 | + onSelect: () => void navigate({ to: item.to }), | ||
| 217 | + }); | ||
| 218 | + } | ||
| 219 | + } | ||
| 220 | + | ||
| 221 | + // 3. System Preferences & Account (Sistem & Tercihler) | ||
| 222 | + const systemCategoryLabel = t("command.group.system"); | ||
| 223 | + | ||
| 224 | + const isDark = prefs.theme() === "dark"; | ||
| 225 | + list.push({ | ||
| 226 | + id: "system-theme-toggle", | ||
| 227 | + category: "system", | ||
| 228 | + categoryLabel: systemCategoryLabel, | ||
| 229 | + title: isDark ? t("command.action.themeLight") : t("command.action.themeDark"), | ||
| 230 | + description: isDark ? "Açık moda geç" : "Koyu moda geç", | ||
| 231 | + keywords: "theme tema koyu acik dark light mode", | ||
| 232 | + icon: isDark ? IconSun : IconMoon, | ||
| 233 | + onSelect: () => prefs.setTheme(isDark ? "light" : "dark"), | ||
| 234 | + }); | ||
| 235 | + | ||
| 236 | + const isTr = prefs.locale() === "tr"; | ||
| 237 | + list.push({ | ||
| 238 | + id: "system-lang-toggle", | ||
| 239 | + category: "system", | ||
| 240 | + categoryLabel: systemCategoryLabel, | ||
| 241 | + title: isTr ? t("command.action.langEn") : t("command.action.langTr"), | ||
| 242 | + description: isTr ? "Switch to English" : "Türkçe diline geç", | ||
| 243 | + keywords: "language dil turkce english tr en", | ||
| 244 | + icon: IconGlobe, | ||
| 245 | + onSelect: () => prefs.setLocale(isTr ? "en" : "tr"), | ||
| 246 | + }); | ||
| 247 | + | ||
| 248 | + list.push({ | ||
| 249 | + id: "system-logout", | ||
| 250 | + category: "system", | ||
| 251 | + categoryLabel: systemCategoryLabel, | ||
| 252 | + title: t("command.action.logout"), | ||
| 253 | + description: t("command.action.logoutDesc"), | ||
| 254 | + keywords: "logout cıkıs oturum kapat ayrıl", | ||
| 255 | + icon: IconLogout, | ||
| 256 | + onSelect: async () => { | ||
| 257 | + await auth.logout(); | ||
| 258 | + void navigate({ to: "/login" }); | ||
| 259 | + }, | ||
| 260 | + }); | ||
| 261 | + | ||
| 262 | + return list; | ||
| 263 | + }); | ||
| 264 | + | ||
| 265 | + const filteredItems = createMemo(() => { | ||
| 266 | + const q = query().trim().toLocaleLowerCase(prefs.locale()); | ||
| 267 | + if (!q) return items(); | ||
| 268 | + return items().filter((item) => | ||
| 269 | + `${item.title} ${item.description ?? ""} ${item.keywords ?? ""} ${item.categoryLabel}` | ||
| 270 | + .toLocaleLowerCase(prefs.locale()) | ||
| 271 | + .includes(q), | ||
| 272 | + ); | ||
| 273 | + }); | ||
| 274 | + | ||
| 275 | + // Group items by category while preserving single flat index order for keyboard navigation | ||
| 276 | + const groupedItems = createMemo(() => { | ||
| 277 | + const list = filteredItems(); | ||
| 278 | + const categories: { category: CommandCategory; label: string; items: { item: CommandItem; globalIndex: number }[] }[] = []; | ||
| 279 | + | ||
| 280 | + const map = new Map<CommandCategory, { item: CommandItem; globalIndex: number }[]>(); | ||
| 281 | + | ||
| 282 | + list.forEach((item, idx) => { | ||
| 283 | + if (!map.has(item.category)) { | ||
| 284 | + map.set(item.category, []); | ||
| 285 | + } | ||
| 286 | + map.get(item.category)!.push({ item, globalIndex: idx }); | ||
| 287 | + }); | ||
| 288 | + | ||
| 289 | + const order: CommandCategory[] = ["actions", "pages", "system"]; | ||
| 290 | + for (const cat of order) { | ||
| 291 | + const itemsInCat = map.get(cat); | ||
| 292 | + if (itemsInCat && itemsInCat.length > 0) { | ||
| 293 | + categories.push({ | ||
| 294 | + category: cat, | ||
| 295 | + label: itemsInCat[0].item.categoryLabel, | ||
| 296 | + items: itemsInCat, | ||
| 297 | + }); | ||
| 298 | + } | ||
| 299 | + } | ||
| 300 | + | ||
| 301 | + return categories; | ||
| 302 | + }); | ||
| 303 | + | ||
| 304 | + const executeItem = (item: CommandItem) => { | ||
| 305 | + props.onOpenChange(false); | ||
| 306 | + item.onSelect(); | ||
| 307 | + }; | ||
| 308 | + | ||
| 309 | + createEffect(() => { | ||
| 310 | + if (!props.open) return; | ||
| 311 | + setQuery(""); | ||
| 312 | + setSelectedIndex(0); | ||
| 313 | + queueMicrotask(() => inputRef?.focus()); | ||
| 314 | + }); | ||
| 315 | + | ||
| 316 | + // Reset selected index when query changes | ||
| 317 | + createEffect(() => { | ||
| 318 | + query(); | ||
| 319 | + setSelectedIndex(0); | ||
| 320 | + }); | ||
| 321 | + | ||
| 322 | + // Auto scroll active item into view | ||
| 323 | + createEffect(() => { | ||
| 324 | + const idx = selectedIndex(); | ||
| 325 | + if (!listRef) return; | ||
| 326 | + const activeEl = listRef.querySelector(`[data-index="${idx}"]`); | ||
| 327 | + if (activeEl) { | ||
| 328 | + activeEl.scrollIntoView({ block: "nearest" }); | ||
| 329 | + } | ||
| 330 | + }); | ||
| 331 | + | ||
| 332 | + const handleKeyDown = (event: KeyboardEvent) => { | ||
| 333 | + const list = filteredItems(); | ||
| 334 | + if (!list.length) return; | ||
| 335 | + | ||
| 336 | + if (event.key === "ArrowDown") { | ||
| 337 | + event.preventDefault(); | ||
| 338 | + setSelectedIndex((prev) => (prev + 1) % list.length); | ||
| 339 | + } else if (event.key === "ArrowUp") { | ||
| 340 | + event.preventDefault(); | ||
| 341 | + setSelectedIndex((prev) => (prev - 1 + list.length) % list.length); | ||
| 342 | + } else if (event.key === "Enter") { | ||
| 343 | + event.preventDefault(); | ||
| 344 | + const current = list[selectedIndex()]; | ||
| 345 | + if (current) executeItem(current); | ||
| 346 | + } | ||
| 347 | + }; | ||
| 348 | + | ||
| 349 | + onMount(() => { | ||
| 350 | + const onGlobalKeyDown = (event: KeyboardEvent) => { | ||
| 351 | + if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "k") { | ||
| 352 | + event.preventDefault(); | ||
| 353 | + if (auth.user()) props.onOpenChange(!props.open); | ||
| 354 | + } | ||
| 355 | + if (event.key === "Escape" && props.open) props.onOpenChange(false); | ||
| 356 | + }; | ||
| 357 | + window.addEventListener("keydown", onGlobalKeyDown); | ||
| 358 | + onCleanup(() => window.removeEventListener("keydown", onGlobalKeyDown)); | ||
| 359 | + }); | ||
| 360 | + | ||
| 361 | + return ( | ||
| 362 | + <Dialog open={props.open} onOpenChange={props.onOpenChange}> | ||
| 363 | + <DialogContent class="max-h-[min(85vh,38rem)] max-w-2xl overflow-hidden rounded-2xl p-0 shadow-2xl border border-black/[0.08] dark:border-white/[0.12] bg-popover/95 backdrop-blur-xl"> | ||
| 364 | + <DialogTitle class="sr-only">{t("dashboard.commandCenter")}</DialogTitle> | ||
| 365 | + <DialogDescription class="sr-only">{t("common.searchPlaceholder")}</DialogDescription> | ||
| 366 | + | ||
| 367 | + {/* Search Bar Header */} | ||
| 368 | + <div class="flex items-center gap-3 border-b border-border/80 px-4 py-3.5"> | ||
| 369 | + <IconSearch class="h-4 w-4 text-muted-foreground shrink-0" /> | ||
| 370 | + <Input | ||
| 371 | + ref={inputRef} | ||
| 372 | + value={query()} | ||
| 373 | + placeholder={t("common.searchPlaceholder")} | ||
| 374 | + class="h-9 border-0 bg-transparent px-0 text-base font-medium shadow-none hover:bg-transparent focus:bg-transparent focus-visible:ring-0 focus-visible:ring-offset-0" | ||
| 375 | + onInput={(event) => setQuery(event.currentTarget.value)} | ||
| 376 | + onKeyDown={handleKeyDown} | ||
| 377 | + /> | ||
| 378 | + <Show when={query()}> | ||
| 379 | + <span class="rounded-md bg-secondary px-2 py-0.5 text-xs font-medium text-muted-foreground shrink-0"> | ||
| 380 | + {filteredItems().length} {t("dashboard.ready").toLowerCase()} | ||
| 381 | + </span> | ||
| 382 | + </Show> | ||
| 383 | + </div> | ||
| 384 | + | ||
| 385 | + {/* Command Items List */} | ||
| 386 | + <div ref={listRef} class="max-h-[min(65vh,28rem)] overflow-y-auto p-2 space-y-4"> | ||
| 387 | + <Show | ||
| 388 | + when={filteredItems().length > 0} | ||
| 389 | + fallback={<p class="px-3 py-12 text-center text-sm text-muted-foreground">{t("common.noResults")}</p>} | ||
| 390 | + > | ||
| 391 | + <For each={groupedItems()}> | ||
| 392 | + {(group) => ( | ||
| 393 | + <div class="space-y-1"> | ||
| 394 | + <div class="px-3 py-1 text-xs font-semibold uppercase tracking-wider text-muted-foreground/70"> | ||
| 395 | + {group.label} | ||
| 396 | + </div> | ||
| 397 | + <For each={group.items}> | ||
| 398 | + {({ item, globalIndex }) => { | ||
| 399 | + const isSelected = () => selectedIndex() === globalIndex; | ||
| 400 | + const ItemIcon = item.icon; | ||
| 401 | + return ( | ||
| 402 | + <button | ||
| 403 | + type="button" | ||
| 404 | + data-index={globalIndex} | ||
| 405 | + onClick={() => executeItem(item)} | ||
| 406 | + onMouseEnter={() => setSelectedIndex(globalIndex)} | ||
| 407 | + class={cn( | ||
| 408 | + "flex w-full min-w-0 items-center gap-3 rounded-xl px-3 py-2.5 text-left outline-none transition-colors duration-150", | ||
| 409 | + isSelected() | ||
| 410 | + ? "bg-accent text-accent-foreground font-medium shadow-sm" | ||
| 411 | + : "text-foreground hover:bg-secondary/60", | ||
| 412 | + )} | ||
| 413 | + > | ||
| 414 | + <div | ||
| 415 | + class={cn( | ||
| 416 | + "flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition-colors", | ||
| 417 | + isSelected() | ||
| 418 | + ? "bg-primary text-primary-foreground" | ||
| 419 | + : "bg-muted text-muted-foreground", | ||
| 420 | + )} | ||
| 421 | + > | ||
| 422 | + <ItemIcon class="h-4 w-4" /> | ||
| 423 | + </div> | ||
| 424 | + | ||
| 425 | + <div class="min-w-0 flex-1"> | ||
| 426 | + <div class="flex items-center gap-2"> | ||
| 427 | + <span class="truncate text-sm font-medium">{item.title}</span> | ||
| 428 | + <Show when={item.roleBadge}> | ||
| 429 | + <span class="rounded-full bg-secondary border border-border px-2 py-0.2 text-[10px] font-semibold text-muted-foreground"> | ||
| 430 | + {item.roleBadge} | ||
| 431 | + </span> | ||
| 432 | + </Show> | ||
| 433 | + </div> | ||
| 434 | + <Show when={item.description}> | ||
| 435 | + <p class="truncate text-xs text-muted-foreground">{item.description}</p> | ||
| 436 | + </Show> | ||
| 437 | + </div> | ||
| 438 | + | ||
| 439 | + <Show when={item.shortcut}> | ||
| 440 | + <kbd class="hidden shrink-0 rounded-md border border-border/80 bg-muted/60 px-2 py-0.5 font-mono text-[10px] font-semibold text-muted-foreground sm:inline-block"> | ||
| 441 | + {item.shortcut} | ||
| 442 | + </kbd> | ||
| 443 | + </Show> | ||
| 444 | + </button> | ||
| 445 | + ); | ||
| 446 | + }} | ||
| 447 | + </For> | ||
| 448 | + </div> | ||
| 449 | + )} | ||
| 450 | + </For> | ||
| 451 | + </Show> | ||
| 452 | + </div> | ||
| 453 | + | ||
| 454 | + {/* Command Palette Footer */} | ||
| 455 | + <div class="flex items-center justify-between border-t border-border/60 bg-muted/30 px-4 py-2 text-xs text-muted-foreground"> | ||
| 456 | + <span class="truncate">{t("command.shortcutHint")}</span> | ||
| 457 | + <div class="flex items-center gap-2 font-mono shrink-0"> | ||
| 458 | + <kbd class="rounded border border-border bg-background px-1.5 py-0.5 text-[10px] font-semibold">↑↓</kbd> | ||
| 459 | + <span>navigasyon</span> | ||
| 460 | + <kbd class="rounded border border-border bg-background px-1.5 py-0.5 text-[10px] font-semibold">↵</kbd> | ||
| 461 | + <span>seç</span> | ||
| 462 | + <kbd class="rounded border border-border bg-background px-1.5 py-0.5 text-[10px] font-semibold">Esc</kbd> | ||
| 463 | + <span>kapat</span> | ||
| 464 | + </div> | ||
| 465 | + </div> | ||
| 466 | + </DialogContent> | ||
| 467 | + </Dialog> | ||
| 468 | + ); | ||
| 469 | +} | ||
src/components/layout/nav-items.tsadded+169 -0
| @@ -0,0 +1,169 @@ | |||
| 1 | +import type { Component } from "solid-js"; | ||
| 2 | +import type { Role } from "@/api/client"; | ||
| 3 | +import { | ||
| 4 | + IconBook, | ||
| 5 | + IconBriefcase, | ||
| 6 | + IconCalendar, | ||
| 7 | + IconCalendarDays, | ||
| 8 | + IconChart, | ||
| 9 | + IconClock, | ||
| 10 | + IconClipboardCheck, | ||
| 11 | + IconExam, | ||
| 12 | + IconGlobe, | ||
| 13 | + IconHelpCircle, | ||
| 14 | + IconHomework, | ||
| 15 | + IconHome, | ||
| 16 | + IconMessage, | ||
| 17 | + IconNote, | ||
| 18 | + IconReportAnalytics, | ||
| 19 | + IconSchool, | ||
| 20 | + IconSettings, | ||
| 21 | + IconUserCog, | ||
| 22 | + IconUsers, | ||
| 23 | +} from "@/components/ui/icons"; | ||
| 24 | +import type { MessageKey } from "@/i18n/messages"; | ||
| 25 | +import { hasExactRole, hasMinRole, roleInRange } from "@/lib/roles"; | ||
| 26 | + | ||
| 27 | +export type NavItem = { | ||
| 28 | + to: string; | ||
| 29 | + labelKey: MessageKey; | ||
| 30 | + Icon: Component<{ class?: string }>; | ||
| 31 | + minRole?: Role; | ||
| 32 | + /** Inclusive upper bound (e.g. hide from admin with maxRole: "manager"). */ | ||
| 33 | + maxRole?: Role; | ||
| 34 | + /** When set, only this exact role sees the item. */ | ||
| 35 | + exactRole?: Role; | ||
| 36 | + exact?: boolean; | ||
| 37 | +}; | ||
| 38 | + | ||
| 39 | +export type NavGroup = { | ||
| 40 | + id: string; | ||
| 41 | + labelKey: MessageKey; | ||
| 42 | + Icon: Component<{ class?: string }>; | ||
| 43 | + minRole?: Role; | ||
| 44 | + exactRole?: Role; | ||
| 45 | + items: NavItem[]; | ||
| 46 | +}; | ||
| 47 | + | ||
| 48 | +const NAV_GROUPS: NavGroup[] = [ | ||
| 49 | + { | ||
| 50 | + id: "classes", | ||
| 51 | + labelKey: "nav.group.classes", | ||
| 52 | + Icon: IconSchool, | ||
| 53 | + items: [ | ||
| 54 | + { to: "/courses", labelKey: "nav.courses", Icon: IconBook }, | ||
| 55 | + { to: "/studies", labelKey: "nav.studies", Icon: IconClock }, | ||
| 56 | + { to: "/clubs", labelKey: "nav.clubs", Icon: IconUsers }, | ||
| 57 | + { to: "/homework", labelKey: "nav.homework", Icon: IconHomework }, | ||
| 58 | + { to: "/exams", labelKey: "nav.exams", Icon: IconExam }, | ||
| 59 | + { to: "/events", labelKey: "nav.events", Icon: IconCalendar }, | ||
| 60 | + { to: "/calendar", labelKey: "nav.calendar", Icon: IconCalendarDays }, | ||
| 61 | + { to: "/marks", labelKey: "nav.marks", Icon: IconChart, exactRole: "student" }, | ||
| 62 | + { to: "/attendance", labelKey: "nav.attendance", Icon: IconClipboardCheck, exactRole: "student" }, | ||
| 63 | + { to: "/pomodoro", labelKey: "nav.pomodoro", Icon: IconClock, exactRole: "student" }, | ||
| 64 | + ], | ||
| 65 | + }, | ||
| 66 | + { | ||
| 67 | + id: "students", | ||
| 68 | + labelKey: "nav.group.students", | ||
| 69 | + Icon: IconUsers, | ||
| 70 | + exactRole: "parent", | ||
| 71 | + items: [ | ||
| 72 | + { to: "/students", labelKey: "nav.myStudents", Icon: IconUsers, exactRole: "parent" }, | ||
| 73 | + ], | ||
| 74 | + }, | ||
| 75 | + { | ||
| 76 | + id: "grades", | ||
| 77 | + labelKey: "nav.group.grades", | ||
| 78 | + Icon: IconNote, | ||
| 79 | + items: [ | ||
| 80 | + { to: "/notes", labelKey: "nav.notes", Icon: IconNote }, | ||
| 81 | + ], | ||
| 82 | + }, | ||
| 83 | + { | ||
| 84 | + id: "community", | ||
| 85 | + labelKey: "nav.group.community", | ||
| 86 | + Icon: IconGlobe, | ||
| 87 | + items: [ | ||
| 88 | + { to: "/messages", labelKey: "nav.messages", Icon: IconMessage }, | ||
| 89 | + { to: "/questions", labelKey: "nav.questions", Icon: IconHelpCircle }, | ||
| 90 | + ], | ||
| 91 | + }, | ||
| 92 | + { | ||
| 93 | + id: "reports", | ||
| 94 | + labelKey: "nav.group.reports", | ||
| 95 | + Icon: IconReportAnalytics, | ||
| 96 | + minRole: "teacher", | ||
| 97 | + items: [ | ||
| 98 | + { to: "/management/student-marks", labelKey: "nav.studentMarks", Icon: IconChart, minRole: "teacher" }, | ||
| 99 | + { to: "/management/student-attendance", labelKey: "nav.studentAttendance", Icon: IconClipboardCheck, minRole: "teacher" }, | ||
| 100 | + { to: "/management/pomodoros", labelKey: "nav.studentPomodoro", Icon: IconClock, minRole: "teacher" }, | ||
| 101 | + { to: "/work", labelKey: "nav.work", Icon: IconBriefcase, minRole: "teacher", maxRole: "manager" }, | ||
| 102 | + { to: "/management/staff-work", labelKey: "nav.staffWork", Icon: IconBriefcase, minRole: "manager" }, | ||
| 103 | + ], | ||
| 104 | + }, | ||
| 105 | + { | ||
| 106 | + id: "settings", | ||
| 107 | + labelKey: "nav.group.settings", | ||
| 108 | + Icon: IconSettings, | ||
| 109 | + minRole: "manager", | ||
| 110 | + items: [ | ||
| 111 | + { to: "/management/settings", labelKey: "nav.settings", Icon: IconSettings, minRole: "manager" }, | ||
| 112 | + { to: "/management/terms", labelKey: "nav.terms", Icon: IconCalendarDays, minRole: "manager" }, | ||
| 113 | + ], | ||
| 114 | + }, | ||
| 115 | + { | ||
| 116 | + id: "admin", | ||
| 117 | + labelKey: "nav.admin", | ||
| 118 | + Icon: IconUserCog, | ||
| 119 | + minRole: "admin", | ||
| 120 | + items: [ | ||
| 121 | + { to: "/admin/users", labelKey: "nav.users", Icon: IconUsers, minRole: "admin" }, | ||
| 122 | + ], | ||
| 123 | + }, | ||
| 124 | +]; | ||
| 125 | + | ||
| 126 | +export const HOME_ITEM: NavItem = { | ||
| 127 | + to: "/", | ||
| 128 | + labelKey: "nav.home", | ||
| 129 | + Icon: IconHome, | ||
| 130 | + exact: true, | ||
| 131 | +}; | ||
| 132 | + | ||
| 133 | +const PARENT_GROUP: NavGroup = { | ||
| 134 | + id: "students", | ||
| 135 | + labelKey: "nav.group.students", | ||
| 136 | + Icon: IconUsers, | ||
| 137 | + exactRole: "parent", | ||
| 138 | + items: [ | ||
| 139 | + { to: "/students", labelKey: "nav.myStudents", Icon: IconUsers, exactRole: "parent" }, | ||
| 140 | + { to: "/messages", labelKey: "nav.messages", Icon: IconMessage, exactRole: "parent" }, | ||
| 141 | + ], | ||
| 142 | +}; | ||
| 143 | + | ||
| 144 | +function itemVisible(item: NavItem, role: Role | undefined) { | ||
| 145 | + if (role === "parent") return item.to === "/students" || item.to === "/messages"; | ||
| 146 | + if (item.exactRole) return hasExactRole(role, item.exactRole); | ||
| 147 | + if (item.minRole || item.maxRole) return roleInRange(role, item.minRole, item.maxRole); | ||
| 148 | + return true; | ||
| 149 | +} | ||
| 150 | + | ||
| 151 | +export function visibleNavGroups(role: Role | undefined): NavGroup[] { | ||
| 152 | + if (role === "parent") return [PARENT_GROUP]; | ||
| 153 | + return NAV_GROUPS | ||
| 154 | + .filter((group) => { | ||
| 155 | + if (group.exactRole && !hasExactRole(role, group.exactRole)) return false; | ||
| 156 | + if (group.minRole && !hasMinRole(role, group.minRole)) return false; | ||
| 157 | + return true; | ||
| 158 | + }) | ||
| 159 | + .map((group) => ({ | ||
| 160 | + ...group, | ||
| 161 | + items: group.items.filter((item) => itemVisible(item, role)), | ||
| 162 | + })) | ||
| 163 | + .filter((group) => group.items.length > 0); | ||
| 164 | +} | ||
| 165 | + | ||
| 166 | +export function pathActive(pathname: string, to: string, exact?: boolean) { | ||
| 167 | + if (exact) return pathname === to; | ||
| 168 | + return pathname === to || pathname.startsWith(`${to}/`); | ||
| 169 | +} | ||
src/components/layout/side-nav.tsxmodified+4 -171
| @@ -1,5 +1,5 @@ | |||
| 1 | import { Link, useRouterState } from "@tanstack/solid-router"; | 1 | import { Link, useRouterState } from "@tanstack/solid-router"; |
| 2 | -import { For, Show, createEffect, createMemo, createSignal, type Component } from "solid-js"; | 2 | +import { For, Show, createEffect, createMemo, createSignal } from "solid-js"; |
| 3 | import { | 3 | import { |
| 4 | DropdownMenu, | 4 | DropdownMenu, |
| 5 | DropdownMenuContent, | 5 | DropdownMenuContent, |
| @@ -8,154 +8,9 @@ import { | |||
| 8 | } from "@/components/ui/dropdown-menu"; | 8 | } from "@/components/ui/dropdown-menu"; |
| 9 | import { useAuth } from "@/stores/auth-context"; | 9 | import { useAuth } from "@/stores/auth-context"; |
| 10 | import { useT } from "@/stores/preferences-context"; | 10 | import { useT } from "@/stores/preferences-context"; |
| 11 | -import { hasExactRole, hasMinRole, roleInRange } from "@/lib/roles"; | ||
| 12 | import { cn } from "@/lib/cn"; | 11 | import { cn } from "@/lib/cn"; |
| 13 | -import type { MessageKey } from "@/i18n/messages"; | 12 | +import { IconChevronRight } from "@/components/ui/icons"; |
| 14 | -import type { Role } from "@/api/client"; | 13 | +import { HOME_ITEM, pathActive, visibleNavGroups, type NavItem } from "@/components/layout/nav-items"; |
| 15 | -import { | ||
| 16 | - IconBook, | ||
| 17 | - IconBriefcase, | ||
| 18 | - IconCalendar, | ||
| 19 | - IconCalendarDays, | ||
| 20 | - IconChart, | ||
| 21 | - IconChevronRight, | ||
| 22 | - IconClock, | ||
| 23 | - IconClipboardCheck, | ||
| 24 | - IconExam, | ||
| 25 | - IconGlobe, | ||
| 26 | - IconHelpCircle, | ||
| 27 | - IconHomework, | ||
| 28 | - IconHome, | ||
| 29 | - IconMessage, | ||
| 30 | - IconNote, | ||
| 31 | - IconReportAnalytics, | ||
| 32 | - IconSchool, | ||
| 33 | - IconSettings, | ||
| 34 | - IconUserCog, | ||
| 35 | - IconUsers, | ||
| 36 | -} from "@/components/ui/icons"; | ||
| 37 | - | ||
| 38 | -type NavItem = { | ||
| 39 | - to: string; | ||
| 40 | - labelKey: MessageKey; | ||
| 41 | - Icon: Component<{ class?: string }>; | ||
| 42 | - minRole?: Role; | ||
| 43 | - /** Inclusive upper bound (e.g. hide from admin with maxRole: "manager"). */ | ||
| 44 | - maxRole?: Role; | ||
| 45 | - /** When set, only this exact role sees the item. */ | ||
| 46 | - exactRole?: Role; | ||
| 47 | - exact?: boolean; | ||
| 48 | -}; | ||
| 49 | - | ||
| 50 | -type NavGroup = { | ||
| 51 | - id: string; | ||
| 52 | - labelKey: MessageKey; | ||
| 53 | - Icon: Component<{ class?: string }>; | ||
| 54 | - minRole?: Role; | ||
| 55 | - exactRole?: Role; | ||
| 56 | - items: NavItem[]; | ||
| 57 | -}; | ||
| 58 | - | ||
| 59 | -const NAV_GROUPS: NavGroup[] = [ | ||
| 60 | - { | ||
| 61 | - id: "classes", | ||
| 62 | - labelKey: "nav.group.classes", | ||
| 63 | - Icon: IconSchool, | ||
| 64 | - items: [ | ||
| 65 | - { to: "/courses", labelKey: "nav.courses", Icon: IconBook }, | ||
| 66 | - { to: "/studies", labelKey: "nav.studies", Icon: IconClock }, | ||
| 67 | - { to: "/clubs", labelKey: "nav.clubs", Icon: IconUsers }, | ||
| 68 | - { to: "/homework", labelKey: "nav.homework", Icon: IconHomework }, | ||
| 69 | - { to: "/exams", labelKey: "nav.exams", Icon: IconExam }, | ||
| 70 | - { to: "/events", labelKey: "nav.events", Icon: IconCalendar }, | ||
| 71 | - { to: "/calendar", labelKey: "nav.calendar", Icon: IconCalendarDays }, | ||
| 72 | - { to: "/marks", labelKey: "nav.marks", Icon: IconChart, exactRole: "student" }, | ||
| 73 | - { to: "/attendance", labelKey: "nav.attendance", Icon: IconClipboardCheck, exactRole: "student" }, | ||
| 74 | - { to: "/pomodoro", labelKey: "nav.pomodoro", Icon: IconClock, exactRole: "student" }, | ||
| 75 | - ], | ||
| 76 | - }, | ||
| 77 | - { | ||
| 78 | - id: "students", | ||
| 79 | - labelKey: "nav.group.students", | ||
| 80 | - Icon: IconUsers, | ||
| 81 | - exactRole: "parent", | ||
| 82 | - items: [ | ||
| 83 | - { to: "/students", labelKey: "nav.myStudents", Icon: IconUsers, exactRole: "parent" }, | ||
| 84 | - ], | ||
| 85 | - }, | ||
| 86 | - { | ||
| 87 | - id: "grades", | ||
| 88 | - labelKey: "nav.group.grades", | ||
| 89 | - Icon: IconNote, | ||
| 90 | - items: [ | ||
| 91 | - { to: "/notes", labelKey: "nav.notes", Icon: IconNote }, | ||
| 92 | - ], | ||
| 93 | - }, | ||
| 94 | - { | ||
| 95 | - id: "community", | ||
| 96 | - labelKey: "nav.group.community", | ||
| 97 | - Icon: IconGlobe, | ||
| 98 | - items: [ | ||
| 99 | - { to: "/messages", labelKey: "nav.messages", Icon: IconMessage }, | ||
| 100 | - { to: "/questions", labelKey: "nav.questions", Icon: IconHelpCircle }, | ||
| 101 | - ], | ||
| 102 | - }, | ||
| 103 | - { | ||
| 104 | - id: "reports", | ||
| 105 | - labelKey: "nav.group.reports", | ||
| 106 | - Icon: IconReportAnalytics, | ||
| 107 | - minRole: "teacher", | ||
| 108 | - items: [ | ||
| 109 | - { to: "/management/student-marks", labelKey: "nav.studentMarks", Icon: IconChart, minRole: "teacher" }, | ||
| 110 | - { to: "/management/student-attendance", labelKey: "nav.studentAttendance", Icon: IconClipboardCheck, minRole: "teacher" }, | ||
| 111 | - { to: "/management/pomodoros", labelKey: "nav.studentPomodoro", Icon: IconClock, minRole: "teacher" }, | ||
| 112 | - { to: "/work", labelKey: "nav.work", Icon: IconBriefcase, minRole: "teacher", maxRole: "manager" }, | ||
| 113 | - { to: "/management/staff-work", labelKey: "nav.staffWork", Icon: IconBriefcase, minRole: "manager" }, | ||
| 114 | - ], | ||
| 115 | - }, | ||
| 116 | - { | ||
| 117 | - id: "settings", | ||
| 118 | - labelKey: "nav.group.settings", | ||
| 119 | - Icon: IconSettings, | ||
| 120 | - minRole: "manager", | ||
| 121 | - items: [ | ||
| 122 | - { to: "/management/settings", labelKey: "nav.settings", Icon: IconSettings, minRole: "manager" }, | ||
| 123 | - { to: "/management/terms", labelKey: "nav.terms", Icon: IconCalendarDays, minRole: "manager" }, | ||
| 124 | - ], | ||
| 125 | - }, | ||
| 126 | - { | ||
| 127 | - id: "admin", | ||
| 128 | - labelKey: "nav.admin", | ||
| 129 | - Icon: IconUserCog, | ||
| 130 | - minRole: "admin", | ||
| 131 | - items: [ | ||
| 132 | - { to: "/admin/users", labelKey: "nav.users", Icon: IconUsers, minRole: "admin" }, | ||
| 133 | - ], | ||
| 134 | - }, | ||
| 135 | -]; | ||
| 136 | - | ||
| 137 | -const HOME_ITEM: NavItem = { | ||
| 138 | - to: "/", | ||
| 139 | - labelKey: "nav.home", | ||
| 140 | - Icon: IconHome, | ||
| 141 | - exact: true, | ||
| 142 | -}; | ||
| 143 | - | ||
| 144 | -const PARENT_GROUP: NavGroup = { | ||
| 145 | - id: "students", | ||
| 146 | - labelKey: "nav.group.students", | ||
| 147 | - Icon: IconUsers, | ||
| 148 | - exactRole: "parent", | ||
| 149 | - items: [ | ||
| 150 | - { to: "/students", labelKey: "nav.myStudents", Icon: IconUsers, exactRole: "parent" }, | ||
| 151 | - { to: "/messages", labelKey: "nav.messages", Icon: IconMessage, exactRole: "parent" }, | ||
| 152 | - ], | ||
| 153 | -}; | ||
| 154 | - | ||
| 155 | -function pathActive(pathname: string, to: string, exact?: boolean) { | ||
| 156 | - if (exact) return pathname === to; | ||
| 157 | - return pathname === to || pathname.startsWith(`${to}/`); | ||
| 158 | -} | ||
| 159 | 14 | ||
| 160 | function NavLink(props: { | 15 | function NavLink(props: { |
| 161 | item: NavItem; | 16 | item: NavItem; |
| @@ -196,30 +51,8 @@ export function SideNav(props: { onNavigate?: () => void; collapsed?: boolean }) | |||
| 196 | const t = useT(); | 51 | const t = useT(); |
| 197 | const pathname = useRouterState({ select: (s) => s.location.pathname }); | 52 | const pathname = useRouterState({ select: (s) => s.location.pathname }); |
| 198 | const role = () => auth.user()?.role; | 53 | const role = () => auth.user()?.role; |
| 199 | - const itemVisible = (item: NavItem) => { | ||
| 200 | - const currentRole = role(); | ||
| 201 | - if (currentRole === "parent") return item.to === "/students" || item.to === "/messages"; | ||
| 202 | - if (item.exactRole) return hasExactRole(currentRole, item.exactRole); | ||
| 203 | - if (item.minRole || item.maxRole) return roleInRange(currentRole, item.minRole, item.maxRole); | ||
| 204 | - return true; | ||
| 205 | - }; | ||
| 206 | 54 | ||
| 207 | - const visibleGroups = createMemo(() => | 55 | + const visibleGroups = createMemo(() => visibleNavGroups(role())); |
| 208 | - (role() === "parent" | ||
| 209 | - ? [PARENT_GROUP] | ||
| 210 | - : NAV_GROUPS | ||
| 211 | - .filter((group) => { | ||
| 212 | - const r = role(); | ||
| 213 | - if (group.exactRole && !hasExactRole(r, group.exactRole)) return false; | ||
| 214 | - if (group.minRole && !hasMinRole(r, group.minRole)) return false; | ||
| 215 | - return true; | ||
| 216 | - }) | ||
| 217 | - .map((group) => ({ | ||
| 218 | - ...group, | ||
| 219 | - items: group.items.filter(itemVisible), | ||
| 220 | - })) | ||
| 221 | - .filter((group) => group.items.length > 0)), | ||
| 222 | - ); | ||
| 223 | const activeGroupId = createMemo( | 56 | const activeGroupId = createMemo( |
| 224 | () => | 57 | () => |
| 225 | visibleGroups().find((group) => group.items.some((item) => pathActive(pathname(), item.to, item.exact)))?.id ?? | 58 | visibleGroups().find((group) => group.items.some((item) => pathActive(pathname(), item.to, item.exact)))?.id ?? |
src/i18n/messages.tsmodified+87 -0
| @@ -170,6 +170,35 @@ export type MessageKey = | |||
| 170 | | "dashboard.stats.average" | 170 | | "dashboard.stats.average" |
| 171 | | "dashboard.stats.averageHint" | 171 | | "dashboard.stats.averageHint" |
| 172 | | "dashboard.commandCenter" | 172 | | "dashboard.commandCenter" |
| 173 | + | "command.group.actions" | ||
| 174 | + | "command.group.navigation" | ||
| 175 | + | "command.group.system" | ||
| 176 | + | "command.action.createHomework" | ||
| 177 | + | "command.action.createHomeworkDesc" | ||
| 178 | + | "command.action.createCourse" | ||
| 179 | + | "command.action.createCourseDesc" | ||
| 180 | + | "command.action.createEvent" | ||
| 181 | + | "command.action.createEventDesc" | ||
| 182 | + | "command.action.createExam" | ||
| 183 | + | "command.action.createExamDesc" | ||
| 184 | + | "command.action.createNote" | ||
| 185 | + | "command.action.createNoteDesc" | ||
| 186 | + | "command.action.importNote" | ||
| 187 | + | "command.action.importNoteDesc" | ||
| 188 | + | "command.action.askQuestion" | ||
| 189 | + | "command.action.askQuestionDesc" | ||
| 190 | + | "command.action.askCelebi" | ||
| 191 | + | "command.action.askCelebiDesc" | ||
| 192 | + | "command.action.myProfile" | ||
| 193 | + | "command.action.myProfileDesc" | ||
| 194 | + | "command.action.themeDark" | ||
| 195 | + | "command.action.themeLight" | ||
| 196 | + | "command.action.themeSystem" | ||
| 197 | + | "command.action.langTr" | ||
| 198 | + | "command.action.langEn" | ||
| 199 | + | "command.action.logout" | ||
| 200 | + | "command.action.logoutDesc" | ||
| 201 | + | "command.shortcutHint" | ||
| 173 | | "dashboard.observationOnly" | 202 | | "dashboard.observationOnly" |
| 174 | | "dashboard.today" | 203 | | "dashboard.today" |
| 175 | | "dashboard.reportCard" | 204 | | "dashboard.reportCard" |
| @@ -938,6 +967,35 @@ const en: Dict = { | |||
| 938 | "dashboard.stats.average": "Average", | 967 | "dashboard.stats.average": "Average", |
| 939 | "dashboard.stats.averageHint": "Overall report card", | 968 | "dashboard.stats.averageHint": "Overall report card", |
| 940 | "dashboard.commandCenter": "Command center", | 969 | "dashboard.commandCenter": "Command center", |
| 970 | + "command.group.actions": "Quick actions", | ||
| 971 | + "command.group.navigation": "Pages & navigation", | ||
| 972 | + "command.group.system": "System & preferences", | ||
| 973 | + "command.action.createHomework": "Create homework", | ||
| 974 | + "command.action.createHomeworkDesc": "Assign new homework for a course", | ||
| 975 | + "command.action.createCourse": "Create course", | ||
| 976 | + "command.action.createCourseDesc": "Create a new course in system", | ||
| 977 | + "command.action.createEvent": "Schedule event", | ||
| 978 | + "command.action.createEventDesc": "Schedule event or lesson in calendar", | ||
| 979 | + "command.action.createExam": "Create exam", | ||
| 980 | + "command.action.createExamDesc": "Prepare new exam for students", | ||
| 981 | + "command.action.createNote": "Create note", | ||
| 982 | + "command.action.createNoteDesc": "Save a personal or class note", | ||
| 983 | + "command.action.importNote": "Import note assistant", | ||
| 984 | + "command.action.importNoteDesc": "Convert PDF or text files to note", | ||
| 985 | + "command.action.askQuestion": "Ask / add question", | ||
| 986 | + "command.action.askQuestionDesc": "Ask question or add to community pool", | ||
| 987 | + "command.action.askCelebi": "Ask Çelebi AI", | ||
| 988 | + "command.action.askCelebiDesc": "Chat with smart AI assistant", | ||
| 989 | + "command.action.myProfile": "My profile", | ||
| 990 | + "command.action.myProfileDesc": "User account and profile details", | ||
| 991 | + "command.action.themeDark": "Dark theme", | ||
| 992 | + "command.action.themeLight": "Light theme", | ||
| 993 | + "command.action.themeSystem": "System theme", | ||
| 994 | + "command.action.langTr": "Language: Türkçe", | ||
| 995 | + "command.action.langEn": "Language: English", | ||
| 996 | + "command.action.logout": "Log out", | ||
| 997 | + "command.action.logoutDesc": "Sign out of your account", | ||
| 998 | + "command.shortcutHint": "Use arrow keys to navigate, press Enter to select", | ||
| 941 | "dashboard.observationOnly": "Read-only overview of what needs attention.", | 999 | "dashboard.observationOnly": "Read-only overview of what needs attention.", |
| 942 | "dashboard.today": "Today", | 1000 | "dashboard.today": "Today", |
| 943 | "dashboard.reportCard": "Report card", | 1001 | "dashboard.reportCard": "Report card", |
| @@ -1718,6 +1776,35 @@ const tr: Dict = { | |||
| 1718 | "dashboard.stats.average": "Ortalama", | 1776 | "dashboard.stats.average": "Ortalama", |
| 1719 | "dashboard.stats.averageHint": "Genel karne", | 1777 | "dashboard.stats.averageHint": "Genel karne", |
| 1720 | "dashboard.commandCenter": "Komuta merkezi", | 1778 | "dashboard.commandCenter": "Komuta merkezi", |
| 1779 | + "command.group.actions": "Hızlı işlemler", | ||
| 1780 | + "command.group.navigation": "Sayfalar & gezinme", | ||
| 1781 | + "command.group.system": "Sistem & tercihler", | ||
| 1782 | + "command.action.createHomework": "Yeni ödev ekle", | ||
| 1783 | + "command.action.createHomeworkDesc": "Ders için yeni ödev tanımla", | ||
| 1784 | + "command.action.createCourse": "Yeni ders / kurs oluştur", | ||
| 1785 | + "command.action.createCourseDesc": "Sisteme yeni ders kaydı ekle", | ||
| 1786 | + "command.action.createEvent": "Etkinlik planla", | ||
| 1787 | + "command.action.createEventDesc": "Takvime etkinlik veya ders ekle", | ||
| 1788 | + "command.action.createExam": "Yeni sınav hazırla", | ||
| 1789 | + "command.action.createExamDesc": "Öğrenciler için yeni sınav tanımla", | ||
| 1790 | + "command.action.createNote": "Ders notu ekle", | ||
| 1791 | + "command.action.createNoteDesc": "Kişisel veya ders notu kaydet", | ||
| 1792 | + "command.action.importNote": "Not içe aktar assistant", | ||
| 1793 | + "command.action.importNoteDesc": "PDF veya metin belgesini not haline getir", | ||
| 1794 | + "command.action.askQuestion": "Soru sor / havuza ekle", | ||
| 1795 | + "command.action.askQuestionDesc": "Soru havuzuna yeni soru ekle", | ||
| 1796 | + "command.action.askCelebi": "Çelebi AI ile konuş", | ||
| 1797 | + "command.action.askCelebiDesc": "Yapay zeka asistanı ile sohbet et", | ||
| 1798 | + "command.action.myProfile": "Profil bilgilerim", | ||
| 1799 | + "command.action.myProfileDesc": "Kullanıcı hesabı ve profil detayları", | ||
| 1800 | + "command.action.themeDark": "Koyu tema", | ||
| 1801 | + "command.action.themeLight": "Açık tema", | ||
| 1802 | + "command.action.themeSystem": "Sistem teması", | ||
| 1803 | + "command.action.langTr": "Dil: Türkçe", | ||
| 1804 | + "command.action.langEn": "Dil: English", | ||
| 1805 | + "command.action.logout": "Oturumu kapat", | ||
| 1806 | + "command.action.logoutDesc": "Mevcut oturumu sonlandır", | ||
| 1807 | + "command.shortcutHint": "Yön tuşlarıyla gezinebilir, Enter ile seçebilirsiniz", | ||
| 1721 | "dashboard.observationOnly": "Dikkat isteyenlerin salt okunur özeti.", | 1808 | "dashboard.observationOnly": "Dikkat isteyenlerin salt okunur özeti.", |
| 1722 | "dashboard.today": "Bugün", | 1809 | "dashboard.today": "Bugün", |
| 1723 | "dashboard.reportCard": "Karne", | 1810 | "dashboard.reportCard": "Karne", |
src/pages/courses-page.tsxmodified+7 -2
| @@ -1,4 +1,4 @@ | |||
| 1 | -import { For, Show, Suspense, createMemo, createResource, createSignal } from "solid-js"; | 1 | +import { For, Show, Suspense, createEffect, createMemo, createResource, createSignal } from "solid-js"; |
| 2 | import type { ColumnDef } from "@tanstack/solid-table"; | 2 | import type { ColumnDef } from "@tanstack/solid-table"; |
| 3 | import { useLocation, useNavigate } from "@tanstack/solid-router"; | 3 | import { useLocation, useNavigate } from "@tanstack/solid-router"; |
| 4 | import { getCourses, postCourse, postCourseTeacher } from "@/api/courses"; | 4 | import { getCourses, postCourse, postCourseTeacher } from "@/api/courses"; |
| @@ -41,7 +41,12 @@ function CoursesContent() { | |||
| 41 | const navigate = useNavigate(); | 41 | const navigate = useNavigate(); |
| 42 | const location = useLocation(); | 42 | const location = useLocation(); |
| 43 | const t = useT(); | 43 | const t = useT(); |
| 44 | - const [showForm, setShowForm] = createSignal(false); | 44 | + const [showForm, setShowForm] = createSignal(location().searchStr.includes("action=new")); |
| 45 | + createEffect(() => { | ||
| 46 | + if (location().searchStr.includes("action=new")) { | ||
| 47 | + setShowForm(true); | ||
| 48 | + } | ||
| 49 | + }); | ||
| 45 | const [title, setTitle] = createSignal(""); | 50 | const [title, setTitle] = createSignal(""); |
| 46 | const [description, setDescription] = createSignal(""); | 51 | const [description, setDescription] = createSignal(""); |
| 47 | const [termId, setTermId] = createSignal(""); | 52 | const [termId, setTermId] = createSignal(""); |
src/pages/events-page.tsxmodified+9 -3
| @@ -1,5 +1,5 @@ | |||
| 1 | -import { Show, Suspense, createMemo, createResource, createSignal } from "solid-js"; | 1 | +import { Show, Suspense, createEffect, createMemo, createResource, createSignal } from "solid-js"; |
| 2 | -import { Link, useNavigate } from "@tanstack/solid-router"; | 2 | +import { Link, useLocation, useNavigate } from "@tanstack/solid-router"; |
| 3 | import type { ColumnDef } from "@tanstack/solid-table"; | 3 | import type { ColumnDef } from "@tanstack/solid-table"; |
| 4 | import { getEvents } from "@/api/events"; | 4 | import { getEvents } from "@/api/events"; |
| 5 | import { postEvent } from "@/api/events"; | 5 | import { postEvent } from "@/api/events"; |
| @@ -37,11 +37,17 @@ export default function EventsPage() { | |||
| 37 | function EventsContent() { | 37 | function EventsContent() { |
| 38 | const auth = useAuth(); | 38 | const auth = useAuth(); |
| 39 | const navigate = useNavigate(); | 39 | const navigate = useNavigate(); |
| 40 | + const location = useLocation(); | ||
| 40 | const { locale } = usePreferences(); | 41 | const { locale } = usePreferences(); |
| 41 | const t = useT(); | 42 | const t = useT(); |
| 42 | const [error, setError] = createSignal(""); | 43 | const [error, setError] = createSignal(""); |
| 43 | const [flash, setFlash] = createFlash(); | 44 | const [flash, setFlash] = createFlash(); |
| 44 | - const [showForm, setShowForm] = createSignal(false); | 45 | + const [showForm, setShowForm] = createSignal(location().searchStr.includes("action=new")); |
| 46 | + createEffect(() => { | ||
| 47 | + if (location().searchStr.includes("action=new")) { | ||
| 48 | + setShowForm(true); | ||
| 49 | + } | ||
| 50 | + }); | ||
| 45 | const [timeFilter, setTimeFilter] = createSignal("all"); | 51 | const [timeFilter, setTimeFilter] = createSignal("all"); |
| 46 | const canCreate = () => hasMinRole(auth.user()?.role, "teacher"); | 52 | const canCreate = () => hasMinRole(auth.user()?.role, "teacher"); |
| 47 | 53 | ||
src/pages/exams-page.tsxmodified+8 -2
| @@ -1,6 +1,6 @@ | |||
| 1 | import { For, Show, Suspense, createEffect, createMemo, createResource, createSignal } from "solid-js"; | 1 | import { For, Show, Suspense, createEffect, createMemo, createResource, createSignal } from "solid-js"; |
| 2 | import type { ColumnDef } from "@tanstack/solid-table"; | 2 | import type { ColumnDef } from "@tanstack/solid-table"; |
| 3 | -import { useNavigate } from "@tanstack/solid-router"; | 3 | +import { useLocation, useNavigate } from "@tanstack/solid-router"; |
| 4 | import { getCourseById } from "@/api/courses"; | 4 | import { getCourseById } from "@/api/courses"; |
| 5 | import { getCourses } from "@/api/courses"; | 5 | import { getCourses } from "@/api/courses"; |
| 6 | import { getExams } from "@/api/exams"; | 6 | import { getExams } from "@/api/exams"; |
| @@ -47,12 +47,18 @@ export default function ExamsPage() { | |||
| 47 | function ExamsContent() { | 47 | function ExamsContent() { |
| 48 | const auth = useAuth(); | 48 | const auth = useAuth(); |
| 49 | const navigate = useNavigate(); | 49 | const navigate = useNavigate(); |
| 50 | + const location = useLocation(); | ||
| 50 | const t = useT(); | 51 | const t = useT(); |
| 51 | const { locale } = usePreferences(); | 52 | const { locale } = usePreferences(); |
| 52 | const now = createNow(); | 53 | const now = createNow(); |
| 53 | const [statusFilter, setStatusFilter] = createSignal<ExamDisplayStatus | "all">("all"); | 54 | const [statusFilter, setStatusFilter] = createSignal<ExamDisplayStatus | "all">("all"); |
| 54 | const [courseFilter, setCourseFilter] = createSignal("all"); | 55 | const [courseFilter, setCourseFilter] = createSignal("all"); |
| 55 | - const [createOpen, setCreateOpen] = createSignal(false); | 56 | + const [createOpen, setCreateOpen] = createSignal(location().searchStr.includes("action=new")); |
| 57 | + createEffect(() => { | ||
| 58 | + if (location().searchStr.includes("action=new")) { | ||
| 59 | + setCreateOpen(true); | ||
| 60 | + } | ||
| 61 | + }); | ||
| 56 | const [selectedCourseId, setSelectedCourseId] = createSignal(""); | 62 | const [selectedCourseId, setSelectedCourseId] = createSignal(""); |
| 57 | const [editingExam, setEditingExam] = createSignal<Exam | null>(null); | 63 | const [editingExam, setEditingExam] = createSignal<Exam | null>(null); |
| 58 | const [flash, setFlash] = createFlash(); | 64 | const [flash, setFlash] = createFlash(); |
src/pages/homework-page.tsxmodified+8 -2
| @@ -1,5 +1,5 @@ | |||
| 1 | import { For, Show, Suspense, createEffect, createMemo, createResource, createSignal } from "solid-js"; | 1 | import { For, Show, Suspense, createEffect, createMemo, createResource, createSignal } from "solid-js"; |
| 2 | -import { useNavigate } from "@tanstack/solid-router"; | 2 | +import { useLocation, useNavigate } from "@tanstack/solid-router"; |
| 3 | import type { ColumnDef } from "@tanstack/solid-table"; | 3 | import type { ColumnDef } from "@tanstack/solid-table"; |
| 4 | import { getCourseById, getCourseSubjects, getCourses, postCourseHomework } from "@/api/courses"; | 4 | import { getCourseById, getCourseSubjects, getCourses, postCourseHomework } from "@/api/courses"; |
| 5 | import { getHomework } from "@/api/homework"; | 5 | import { getHomework } from "@/api/homework"; |
| @@ -54,7 +54,13 @@ function HomeworkContent() { | |||
| 54 | const auth = useAuth(); | 54 | const auth = useAuth(); |
| 55 | const { locale } = usePreferences(); | 55 | const { locale } = usePreferences(); |
| 56 | const navigate = useNavigate(); | 56 | const navigate = useNavigate(); |
| 57 | - const [createOpen, setCreateOpen] = createSignal(false); | 57 | + const location = useLocation(); |
| 58 | + const [createOpen, setCreateOpen] = createSignal(location().searchStr.includes("action=new")); | ||
| 59 | + createEffect(() => { | ||
| 60 | + if (location().searchStr.includes("action=new")) { | ||
| 61 | + setCreateOpen(true); | ||
| 62 | + } | ||
| 63 | + }); | ||
| 58 | const [selectedCourseId, setSelectedCourseId] = createSignal(""); | 64 | const [selectedCourseId, setSelectedCourseId] = createSignal(""); |
| 59 | const [title, setTitle] = createSignal(""); | 65 | const [title, setTitle] = createSignal(""); |
| 60 | const [description, setDescription] = createSignal(""); | 66 | const [description, setDescription] = createSignal(""); |
src/pages/notes-page.tsxmodified+9 -3
| @@ -1,4 +1,5 @@ | |||
| 1 | -import { Show, Suspense, createMemo, createResource, createSignal } from "solid-js"; | 1 | +import { Show, Suspense, createEffect, createMemo, createResource, createSignal } from "solid-js"; |
| 2 | +import { useLocation } from "@tanstack/solid-router"; | ||
| 2 | import { deleteNoteById } from "@/api/notes"; | 3 | import { deleteNoteById } from "@/api/notes"; |
| 3 | import { getNotes } from "@/api/notes"; | 4 | import { getNotes } from "@/api/notes"; |
| 4 | import { patchNoteById } from "@/api/notes"; | 5 | import { patchNoteById } from "@/api/notes"; |
| @@ -32,10 +33,15 @@ export default function NotesPage() { | |||
| 32 | 33 | ||
| 33 | function NotesContent() { | 34 | function NotesContent() { |
| 34 | const t = useT(); | 35 | const t = useT(); |
| 36 | + const location = useLocation(); | ||
| 35 | const [error, setError] = createSignal(""); | 37 | const [error, setError] = createSignal(""); |
| 36 | const [flash, setFlash] = createFlash(); | 38 | const [flash, setFlash] = createFlash(); |
| 37 | - const [createOpen, setCreateOpen] = createSignal(false); | 39 | + const [createOpen, setCreateOpen] = createSignal(location().searchStr.includes("action=new")); |
| 38 | - const [importOpen, setImportOpen] = createSignal(false); | 40 | + const [importOpen, setImportOpen] = createSignal(location().searchStr.includes("action=import")); |
| 41 | + createEffect(() => { | ||
| 42 | + if (location().searchStr.includes("action=new")) setCreateOpen(true); | ||
| 43 | + if (location().searchStr.includes("action=import")) setImportOpen(true); | ||
| 44 | + }); | ||
| 39 | const [page, setPage] = createSignal(0); | 45 | const [page, setPage] = createSignal(0); |
| 40 | 46 | ||
| 41 | const [list, { refetch }] = createResource( | 47 | const [list, { refetch }] = createResource( |
src/pages/questions-page.tsxmodified+9 -3
| @@ -1,5 +1,5 @@ | |||
| 1 | -import { For, Show, Suspense, createResource, createSignal, lazy } from "solid-js"; | 1 | +import { For, Show, Suspense, createEffect, createResource, createSignal, lazy } from "solid-js"; |
| 2 | -import { Link, useSearch, useNavigate } from "@tanstack/solid-router"; | 2 | +import { Link, useLocation, useNavigate, useSearch } from "@tanstack/solid-router"; |
| 3 | import { getQuestions, postQuestion } from "@/api/shared"; | 3 | import { getQuestions, postQuestion } from "@/api/shared"; |
| 4 | import { getSettings } from "@/api/settings"; | 4 | import { getSettings } from "@/api/settings"; |
| 5 | import { formatApiError } from "@/api/client"; | 5 | import { formatApiError } from "@/api/client"; |
| @@ -37,6 +37,7 @@ function QuestionsContent() { | |||
| 37 | const t = useT(); | 37 | const t = useT(); |
| 38 | const auth = useAuth(); | 38 | const auth = useAuth(); |
| 39 | const navigate = useNavigate(); | 39 | const navigate = useNavigate(); |
| 40 | + const location = useLocation(); | ||
| 40 | const searchParams = useSearch({ strict: false }); | 41 | const searchParams = useSearch({ strict: false }); |
| 41 | 42 | ||
| 42 | const statusFilter = () => ((searchParams() as any).status === "pending" ? "pending" : "approved"); | 43 | const statusFilter = () => ((searchParams() as any).status === "pending" ? "pending" : "approved"); |
| @@ -46,7 +47,12 @@ function QuestionsContent() { | |||
| 46 | async (params) => (await getQuestions(params.status as "pending" | "approved", params)).items | 47 | async (params) => (await getQuestions(params.status as "pending" | "approved", params)).items |
| 47 | ); | 48 | ); |
| 48 | 49 | ||
| 49 | - const [askOpen, setAskOpen] = createSignal(false); | 50 | + const [askOpen, setAskOpen] = createSignal(location().searchStr.includes("action=new")); |
| 51 | + createEffect(() => { | ||
| 52 | + if (location().searchStr.includes("action=new")) { | ||
| 53 | + setAskOpen(true); | ||
| 54 | + } | ||
| 55 | + }); | ||
| 50 | 56 | ||
| 51 | return ( | 57 | return ( |
| 52 | <div class="space-y-6"> | 58 | <div class="space-y-6"> |