From 06a375c4abd3abf6db1f4ef80401d7655bbac7e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Thu, 23 Jul 2026 12:03:33 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20role-based=20command=20pale?= =?UTF-8?q?tte=20with=20quick=20actions=20and=20centered=20search=20bar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - expand and center command palette search bar trigger in top bar header - add role-restricted quick actions: create homework, course, event, exam, note, question, import note - integrate instant actions: toggle theme (dark/light), toggle language (TR/EN), open Celebi AI, open user profile, and log out - implement keyboard navigation (ArrowUp/Down, Enter, Escape) with active state scrolling and OS-aware shortcuts (Ctrl+/⌘) - support auto-opening creation panels on target pages via URL query parameters - add comprehensive Turkish and English i18n translation keys for all command items --- src/components/layout/app-shell.tsx | 47 ++- src/components/layout/command-palette.tsx | 469 ++++++++++++++++++++++ src/components/layout/nav-items.ts | 169 ++++++++ src/components/layout/side-nav.tsx | 175 +------- src/i18n/messages.ts | 87 ++++ src/pages/courses-page.tsx | 9 +- src/pages/events-page.tsx | 12 +- src/pages/exams-page.tsx | 10 +- src/pages/homework-page.tsx | 10 +- src/pages/notes-page.tsx | 12 +- src/pages/questions-page.tsx | 12 +- 11 files changed, 819 insertions(+), 193 deletions(-) create mode 100644 src/components/layout/command-palette.tsx create mode 100644 src/components/layout/nav-items.ts diff --git a/src/components/layout/app-shell.tsx b/src/components/layout/app-shell.tsx index c08b80e..8aa88f6 100644 --- a/src/components/layout/app-shell.tsx +++ b/src/components/layout/app-shell.tsx @@ -1,13 +1,15 @@ import type { ParentProps } from "solid-js"; import { Link, useLocation, useNavigate } from "@tanstack/solid-router"; +import { AccountProfileDialog } from "@/components/users/account-profile-dialog"; import { CelebiPanel } from "@/components/layout/celebi-panel"; import { Show, createMemo, createSignal } from "solid-js"; +import { CommandPalette } from "@/components/layout/command-palette"; import { MobileTabBar } from "@/components/layout/mobile-tab-bar"; import { NavBar } from "@/components/layout/nav-bar"; import { SideNav } from "@/components/layout/side-nav"; import { SidebarAccount } from "@/components/layout/sidebar-account"; import { Button } from "@/components/ui/button"; -import { IconPanelLeft, IconSparkles, IconX } from "@/components/ui/icons"; +import { IconPanelLeft, IconSearch, IconSparkles, IconX } from "@/components/ui/icons"; import { Toaster } from "@/components/ui/toast"; import { useAuth } from "@/stores/auth-context"; import { usePreferences, useT } from "@/stores/preferences-context"; @@ -23,6 +25,8 @@ export function AppShell(props: ParentProps) { const navigate = useNavigate(); const [mobileOpen, setMobileOpen] = createSignal(false); const [celebiOpen, setCelebiOpen] = createSignal(false); + const [commandOpen, setCommandOpen] = createSignal(false); + const [profileOpen, setProfileOpen] = createSignal(false); const collapsed = () => prefs.sidebarCollapsed(); const location = useLocation(); const wide = () => location().pathname.startsWith("/exam-room/") || location().searchStr.includes("answerUser=") || location().pathname === "/messages"; @@ -149,13 +153,35 @@ export function AppShell(props: ParentProps) {
-
- {routeLabel()} +
+
+ {routeLabel()} +
+
+ +
+ +
+ +
+
-
+ setCelebiOpen(true)} + onOpenProfile={() => setProfileOpen(true)} + /> +
diff --git a/src/components/layout/command-palette.tsx b/src/components/layout/command-palette.tsx new file mode 100644 index 0000000..3f82586 --- /dev/null +++ b/src/components/layout/command-palette.tsx @@ -0,0 +1,469 @@ +import { useNavigate } from "@tanstack/solid-router"; +import { For, Show, createEffect, createMemo, createSignal, onCleanup, onMount } from "solid-js"; +import { Dialog, DialogContent, DialogDescription, DialogTitle } from "@/components/ui/dialog"; +import { Input } from "@/components/ui/input"; +import { + IconBook, + IconCalendar, + IconDownload, + IconExam, + IconGlobe, + IconHomework, + IconLogout, + IconMoon, + IconNote, + IconPencilQuestion, + IconSearch, + IconSparkles, + IconSun, + IconUsers, +} from "@/components/ui/icons"; +import { HOME_ITEM, visibleNavGroups } from "@/components/layout/nav-items"; +import { hasMinRole } from "@/lib/roles"; +import { useAuth } from "@/stores/auth-context"; +import { usePreferences, useT } from "@/stores/preferences-context"; +import { cn } from "@/lib/cn"; + +export type CommandPaletteProps = { + open: boolean; + onOpenChange: (open: boolean) => void; + onOpenCelebi?: () => void; + onOpenProfile?: () => void; +}; + +type CommandCategory = "actions" | "pages" | "system"; + +type CommandItem = { + id: string; + category: CommandCategory; + categoryLabel: string; + title: string; + description?: string; + keywords?: string; + icon: typeof IconSearch; + shortcut?: string; + roleBadge?: string; + onSelect: () => void; +}; + +export function CommandPalette(props: CommandPaletteProps) { + const auth = useAuth(); + const prefs = usePreferences(); + const t = useT(); + const navigate = useNavigate(); + + const [query, setQuery] = createSignal(""); + const [selectedIndex, setSelectedIndex] = createSignal(0); + let inputRef: HTMLInputElement | undefined; + let listRef: HTMLDivElement | undefined; + + const role = () => auth.user()?.role; + + const items = createMemo(() => { + const list: CommandItem[] = []; + const userRole = role(); + const isTeacherPlus = hasMinRole(userRole, "teacher"); + const isStudent = userRole === "student"; + + const isMac = typeof navigator !== "undefined" && (navigator.userAgent.includes("Mac") || navigator.platform?.includes("Mac")); + const mod = isMac ? "⌘" : "Ctrl+"; + + // 1. Quick Actions (Hızlı İşlemler) + const actionsCategoryLabel = t("command.group.actions"); + + if (isTeacherPlus) { + list.push({ + id: "action-create-homework", + category: "actions", + categoryLabel: actionsCategoryLabel, + title: t("command.action.createHomework"), + description: t("command.action.createHomeworkDesc"), + keywords: "homework odev ekle olustur ders", + icon: IconHomework, + shortcut: `${mod}H`, + roleBadge: t("role.teacher"), + onSelect: () => void navigate({ to: "/homework", search: { action: "new" } as any }), + }); + + list.push({ + id: "action-create-course", + category: "actions", + categoryLabel: actionsCategoryLabel, + title: t("command.action.createCourse"), + description: t("command.action.createCourseDesc"), + keywords: "course ders kurs olustur egitim", + icon: IconBook, + shortcut: `${mod}C`, + roleBadge: t("role.teacher"), + onSelect: () => void navigate({ to: "/courses", search: { action: "new" } as any }), + }); + + list.push({ + id: "action-create-event", + category: "actions", + categoryLabel: actionsCategoryLabel, + title: t("command.action.createEvent"), + description: t("command.action.createEventDesc"), + keywords: "event etkinlik planla takvim oturum", + icon: IconCalendar, + shortcut: `${mod}E`, + roleBadge: t("role.teacher"), + onSelect: () => void navigate({ to: "/events", search: { action: "new" } as any }), + }); + + list.push({ + id: "action-create-exam", + category: "actions", + categoryLabel: actionsCategoryLabel, + title: t("command.action.createExam"), + description: t("command.action.createExamDesc"), + keywords: "exam sinav test hazirla olustur", + icon: IconExam, + shortcut: `${mod}X`, + roleBadge: t("role.teacher"), + onSelect: () => void navigate({ to: "/exams", search: { action: "new" } as any }), + }); + } + + // Common Quick Actions for all roles + list.push({ + id: "action-create-note", + category: "actions", + categoryLabel: actionsCategoryLabel, + title: t("command.action.createNote"), + description: t("command.action.createNoteDesc"), + keywords: "note not ekle ders notu kaydet", + icon: IconNote, + shortcut: `${mod}N`, + onSelect: () => void navigate({ to: "/notes", search: { action: "new" } as any }), + }); + + list.push({ + id: "action-import-note", + category: "actions", + categoryLabel: actionsCategoryLabel, + title: t("command.action.importNote"), + description: t("command.action.importNoteDesc"), + keywords: "import ice aktar pdf txt markdown assistant", + icon: IconDownload, + onSelect: () => void navigate({ to: "/notes", search: { action: "import" } as any }), + }); + + list.push({ + id: "action-ask-question", + category: "actions", + categoryLabel: actionsCategoryLabel, + title: t("command.action.askQuestion"), + description: t("command.action.askQuestionDesc"), + keywords: "question soru sor havuz ekle topluluk", + icon: IconPencilQuestion, + shortcut: `${mod}Q`, + roleBadge: isStudent ? t("role.student") : undefined, + onSelect: () => void navigate({ to: "/questions", search: { action: "new" } as any }), + }); + + if (props.onOpenCelebi) { + list.push({ + id: "action-ask-celebi", + category: "actions", + categoryLabel: actionsCategoryLabel, + title: t("command.action.askCelebi"), + description: t("command.action.askCelebiDesc"), + keywords: "celebi ai yapay zeka sohbet asistan yardım", + icon: IconSparkles, + onSelect: () => props.onOpenCelebi?.(), + }); + } + + if (props.onOpenProfile) { + list.push({ + id: "action-my-profile", + category: "actions", + categoryLabel: actionsCategoryLabel, + title: t("command.action.myProfile"), + description: t("command.action.myProfileDesc"), + keywords: "profile profil hesabim kullanici sifre", + icon: IconUsers, + onSelect: () => props.onOpenProfile?.(), + }); + } + + // 2. Navigation Pages (Sayfalar & Gezinme) + const pagesCategoryLabel = t("command.group.navigation"); + + list.push({ + id: "page-home", + category: "pages", + categoryLabel: pagesCategoryLabel, + title: t(HOME_ITEM.labelKey), + description: t("app.name"), + keywords: "home anasayfa kontrol paneli dashboard", + icon: HOME_ITEM.Icon, + onSelect: () => void navigate({ to: HOME_ITEM.to }), + }); + + for (const group of visibleNavGroups(userRole)) { + const groupName = t(group.labelKey); + for (const item of group.items) { + list.push({ + id: `page-${item.to}`, + category: "pages", + categoryLabel: pagesCategoryLabel, + title: t(item.labelKey), + description: groupName, + keywords: `${item.to} ${t(item.labelKey)} ${groupName}`, + icon: item.Icon, + onSelect: () => void navigate({ to: item.to }), + }); + } + } + + // 3. System Preferences & Account (Sistem & Tercihler) + const systemCategoryLabel = t("command.group.system"); + + const isDark = prefs.theme() === "dark"; + list.push({ + id: "system-theme-toggle", + category: "system", + categoryLabel: systemCategoryLabel, + title: isDark ? t("command.action.themeLight") : t("command.action.themeDark"), + description: isDark ? "Açık moda geç" : "Koyu moda geç", + keywords: "theme tema koyu acik dark light mode", + icon: isDark ? IconSun : IconMoon, + onSelect: () => prefs.setTheme(isDark ? "light" : "dark"), + }); + + const isTr = prefs.locale() === "tr"; + list.push({ + id: "system-lang-toggle", + category: "system", + categoryLabel: systemCategoryLabel, + title: isTr ? t("command.action.langEn") : t("command.action.langTr"), + description: isTr ? "Switch to English" : "Türkçe diline geç", + keywords: "language dil turkce english tr en", + icon: IconGlobe, + onSelect: () => prefs.setLocale(isTr ? "en" : "tr"), + }); + + list.push({ + id: "system-logout", + category: "system", + categoryLabel: systemCategoryLabel, + title: t("command.action.logout"), + description: t("command.action.logoutDesc"), + keywords: "logout cıkıs oturum kapat ayrıl", + icon: IconLogout, + onSelect: async () => { + await auth.logout(); + void navigate({ to: "/login" }); + }, + }); + + return list; + }); + + const filteredItems = createMemo(() => { + const q = query().trim().toLocaleLowerCase(prefs.locale()); + if (!q) return items(); + return items().filter((item) => + `${item.title} ${item.description ?? ""} ${item.keywords ?? ""} ${item.categoryLabel}` + .toLocaleLowerCase(prefs.locale()) + .includes(q), + ); + }); + + // Group items by category while preserving single flat index order for keyboard navigation + const groupedItems = createMemo(() => { + const list = filteredItems(); + const categories: { category: CommandCategory; label: string; items: { item: CommandItem; globalIndex: number }[] }[] = []; + + const map = new Map(); + + list.forEach((item, idx) => { + if (!map.has(item.category)) { + map.set(item.category, []); + } + map.get(item.category)!.push({ item, globalIndex: idx }); + }); + + const order: CommandCategory[] = ["actions", "pages", "system"]; + for (const cat of order) { + const itemsInCat = map.get(cat); + if (itemsInCat && itemsInCat.length > 0) { + categories.push({ + category: cat, + label: itemsInCat[0].item.categoryLabel, + items: itemsInCat, + }); + } + } + + return categories; + }); + + const executeItem = (item: CommandItem) => { + props.onOpenChange(false); + item.onSelect(); + }; + + createEffect(() => { + if (!props.open) return; + setQuery(""); + setSelectedIndex(0); + queueMicrotask(() => inputRef?.focus()); + }); + + // Reset selected index when query changes + createEffect(() => { + query(); + setSelectedIndex(0); + }); + + // Auto scroll active item into view + createEffect(() => { + const idx = selectedIndex(); + if (!listRef) return; + const activeEl = listRef.querySelector(`[data-index="${idx}"]`); + if (activeEl) { + activeEl.scrollIntoView({ block: "nearest" }); + } + }); + + const handleKeyDown = (event: KeyboardEvent) => { + const list = filteredItems(); + if (!list.length) return; + + if (event.key === "ArrowDown") { + event.preventDefault(); + setSelectedIndex((prev) => (prev + 1) % list.length); + } else if (event.key === "ArrowUp") { + event.preventDefault(); + setSelectedIndex((prev) => (prev - 1 + list.length) % list.length); + } else if (event.key === "Enter") { + event.preventDefault(); + const current = list[selectedIndex()]; + if (current) executeItem(current); + } + }; + + onMount(() => { + const onGlobalKeyDown = (event: KeyboardEvent) => { + if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "k") { + event.preventDefault(); + if (auth.user()) props.onOpenChange(!props.open); + } + if (event.key === "Escape" && props.open) props.onOpenChange(false); + }; + window.addEventListener("keydown", onGlobalKeyDown); + onCleanup(() => window.removeEventListener("keydown", onGlobalKeyDown)); + }); + + return ( + + + {t("dashboard.commandCenter")} + {t("common.searchPlaceholder")} + + {/* Search Bar Header */} +
+ + setQuery(event.currentTarget.value)} + onKeyDown={handleKeyDown} + /> + + + {filteredItems().length} {t("dashboard.ready").toLowerCase()} + + +
+ + {/* Command Items List */} +
+ 0} + fallback={

{t("common.noResults")}

} + > + + {(group) => ( +
+
+ {group.label} +
+ + {({ item, globalIndex }) => { + const isSelected = () => selectedIndex() === globalIndex; + const ItemIcon = item.icon; + return ( + + ); + }} + +
+ )} +
+
+
+ + {/* Command Palette Footer */} +
+ {t("command.shortcutHint")} +
+ ↑↓ + navigasyon + ↵ + seç + Esc + kapat +
+
+
+
+ ); +} diff --git a/src/components/layout/nav-items.ts b/src/components/layout/nav-items.ts new file mode 100644 index 0000000..913bd84 --- /dev/null +++ b/src/components/layout/nav-items.ts @@ -0,0 +1,169 @@ +import type { Component } from "solid-js"; +import type { Role } from "@/api/client"; +import { + IconBook, + IconBriefcase, + IconCalendar, + IconCalendarDays, + IconChart, + IconClock, + IconClipboardCheck, + IconExam, + IconGlobe, + IconHelpCircle, + IconHomework, + IconHome, + IconMessage, + IconNote, + IconReportAnalytics, + IconSchool, + IconSettings, + IconUserCog, + IconUsers, +} from "@/components/ui/icons"; +import type { MessageKey } from "@/i18n/messages"; +import { hasExactRole, hasMinRole, roleInRange } from "@/lib/roles"; + +export type NavItem = { + to: string; + labelKey: MessageKey; + Icon: Component<{ class?: string }>; + minRole?: Role; + /** Inclusive upper bound (e.g. hide from admin with maxRole: "manager"). */ + maxRole?: Role; + /** When set, only this exact role sees the item. */ + exactRole?: Role; + exact?: boolean; +}; + +export type NavGroup = { + id: string; + labelKey: MessageKey; + Icon: Component<{ class?: string }>; + minRole?: Role; + exactRole?: Role; + items: NavItem[]; +}; + +const NAV_GROUPS: NavGroup[] = [ + { + id: "classes", + labelKey: "nav.group.classes", + Icon: IconSchool, + items: [ + { to: "/courses", labelKey: "nav.courses", Icon: IconBook }, + { to: "/studies", labelKey: "nav.studies", Icon: IconClock }, + { to: "/clubs", labelKey: "nav.clubs", Icon: IconUsers }, + { to: "/homework", labelKey: "nav.homework", Icon: IconHomework }, + { to: "/exams", labelKey: "nav.exams", Icon: IconExam }, + { to: "/events", labelKey: "nav.events", Icon: IconCalendar }, + { to: "/calendar", labelKey: "nav.calendar", Icon: IconCalendarDays }, + { to: "/marks", labelKey: "nav.marks", Icon: IconChart, exactRole: "student" }, + { to: "/attendance", labelKey: "nav.attendance", Icon: IconClipboardCheck, exactRole: "student" }, + { to: "/pomodoro", labelKey: "nav.pomodoro", Icon: IconClock, exactRole: "student" }, + ], + }, + { + id: "students", + labelKey: "nav.group.students", + Icon: IconUsers, + exactRole: "parent", + items: [ + { to: "/students", labelKey: "nav.myStudents", Icon: IconUsers, exactRole: "parent" }, + ], + }, + { + id: "grades", + labelKey: "nav.group.grades", + Icon: IconNote, + items: [ + { to: "/notes", labelKey: "nav.notes", Icon: IconNote }, + ], + }, + { + id: "community", + labelKey: "nav.group.community", + Icon: IconGlobe, + items: [ + { to: "/messages", labelKey: "nav.messages", Icon: IconMessage }, + { to: "/questions", labelKey: "nav.questions", Icon: IconHelpCircle }, + ], + }, + { + id: "reports", + labelKey: "nav.group.reports", + Icon: IconReportAnalytics, + minRole: "teacher", + items: [ + { to: "/management/student-marks", labelKey: "nav.studentMarks", Icon: IconChart, minRole: "teacher" }, + { to: "/management/student-attendance", labelKey: "nav.studentAttendance", Icon: IconClipboardCheck, minRole: "teacher" }, + { to: "/management/pomodoros", labelKey: "nav.studentPomodoro", Icon: IconClock, minRole: "teacher" }, + { to: "/work", labelKey: "nav.work", Icon: IconBriefcase, minRole: "teacher", maxRole: "manager" }, + { to: "/management/staff-work", labelKey: "nav.staffWork", Icon: IconBriefcase, minRole: "manager" }, + ], + }, + { + id: "settings", + labelKey: "nav.group.settings", + Icon: IconSettings, + minRole: "manager", + items: [ + { to: "/management/settings", labelKey: "nav.settings", Icon: IconSettings, minRole: "manager" }, + { to: "/management/terms", labelKey: "nav.terms", Icon: IconCalendarDays, minRole: "manager" }, + ], + }, + { + id: "admin", + labelKey: "nav.admin", + Icon: IconUserCog, + minRole: "admin", + items: [ + { to: "/admin/users", labelKey: "nav.users", Icon: IconUsers, minRole: "admin" }, + ], + }, +]; + +export const HOME_ITEM: NavItem = { + to: "/", + labelKey: "nav.home", + Icon: IconHome, + exact: true, +}; + +const PARENT_GROUP: NavGroup = { + id: "students", + labelKey: "nav.group.students", + Icon: IconUsers, + exactRole: "parent", + items: [ + { to: "/students", labelKey: "nav.myStudents", Icon: IconUsers, exactRole: "parent" }, + { to: "/messages", labelKey: "nav.messages", Icon: IconMessage, exactRole: "parent" }, + ], +}; + +function itemVisible(item: NavItem, role: Role | undefined) { + if (role === "parent") return item.to === "/students" || item.to === "/messages"; + if (item.exactRole) return hasExactRole(role, item.exactRole); + if (item.minRole || item.maxRole) return roleInRange(role, item.minRole, item.maxRole); + return true; +} + +export function visibleNavGroups(role: Role | undefined): NavGroup[] { + if (role === "parent") return [PARENT_GROUP]; + return NAV_GROUPS + .filter((group) => { + if (group.exactRole && !hasExactRole(role, group.exactRole)) return false; + if (group.minRole && !hasMinRole(role, group.minRole)) return false; + return true; + }) + .map((group) => ({ + ...group, + items: group.items.filter((item) => itemVisible(item, role)), + })) + .filter((group) => group.items.length > 0); +} + +export function pathActive(pathname: string, to: string, exact?: boolean) { + if (exact) return pathname === to; + return pathname === to || pathname.startsWith(`${to}/`); +} diff --git a/src/components/layout/side-nav.tsx b/src/components/layout/side-nav.tsx index 09fcf8e..3a19fae 100644 --- a/src/components/layout/side-nav.tsx +++ b/src/components/layout/side-nav.tsx @@ -1,5 +1,5 @@ import { Link, useRouterState } from "@tanstack/solid-router"; -import { For, Show, createEffect, createMemo, createSignal, type Component } from "solid-js"; +import { For, Show, createEffect, createMemo, createSignal } from "solid-js"; import { DropdownMenu, DropdownMenuContent, @@ -8,154 +8,9 @@ import { } from "@/components/ui/dropdown-menu"; import { useAuth } from "@/stores/auth-context"; import { useT } from "@/stores/preferences-context"; -import { hasExactRole, hasMinRole, roleInRange } from "@/lib/roles"; import { cn } from "@/lib/cn"; -import type { MessageKey } from "@/i18n/messages"; -import type { Role } from "@/api/client"; -import { - IconBook, - IconBriefcase, - IconCalendar, - IconCalendarDays, - IconChart, - IconChevronRight, - IconClock, - IconClipboardCheck, - IconExam, - IconGlobe, - IconHelpCircle, - IconHomework, - IconHome, - IconMessage, - IconNote, - IconReportAnalytics, - IconSchool, - IconSettings, - IconUserCog, - IconUsers, -} from "@/components/ui/icons"; - -type NavItem = { - to: string; - labelKey: MessageKey; - Icon: Component<{ class?: string }>; - minRole?: Role; - /** Inclusive upper bound (e.g. hide from admin with maxRole: "manager"). */ - maxRole?: Role; - /** When set, only this exact role sees the item. */ - exactRole?: Role; - exact?: boolean; -}; - -type NavGroup = { - id: string; - labelKey: MessageKey; - Icon: Component<{ class?: string }>; - minRole?: Role; - exactRole?: Role; - items: NavItem[]; -}; - -const NAV_GROUPS: NavGroup[] = [ - { - id: "classes", - labelKey: "nav.group.classes", - Icon: IconSchool, - items: [ - { to: "/courses", labelKey: "nav.courses", Icon: IconBook }, - { to: "/studies", labelKey: "nav.studies", Icon: IconClock }, - { to: "/clubs", labelKey: "nav.clubs", Icon: IconUsers }, - { to: "/homework", labelKey: "nav.homework", Icon: IconHomework }, - { to: "/exams", labelKey: "nav.exams", Icon: IconExam }, - { to: "/events", labelKey: "nav.events", Icon: IconCalendar }, - { to: "/calendar", labelKey: "nav.calendar", Icon: IconCalendarDays }, - { to: "/marks", labelKey: "nav.marks", Icon: IconChart, exactRole: "student" }, - { to: "/attendance", labelKey: "nav.attendance", Icon: IconClipboardCheck, exactRole: "student" }, - { to: "/pomodoro", labelKey: "nav.pomodoro", Icon: IconClock, exactRole: "student" }, - ], - }, - { - id: "students", - labelKey: "nav.group.students", - Icon: IconUsers, - exactRole: "parent", - items: [ - { to: "/students", labelKey: "nav.myStudents", Icon: IconUsers, exactRole: "parent" }, - ], - }, - { - id: "grades", - labelKey: "nav.group.grades", - Icon: IconNote, - items: [ - { to: "/notes", labelKey: "nav.notes", Icon: IconNote }, - ], - }, - { - id: "community", - labelKey: "nav.group.community", - Icon: IconGlobe, - items: [ - { to: "/messages", labelKey: "nav.messages", Icon: IconMessage }, - { to: "/questions", labelKey: "nav.questions", Icon: IconHelpCircle }, - ], - }, - { - id: "reports", - labelKey: "nav.group.reports", - Icon: IconReportAnalytics, - minRole: "teacher", - items: [ - { to: "/management/student-marks", labelKey: "nav.studentMarks", Icon: IconChart, minRole: "teacher" }, - { to: "/management/student-attendance", labelKey: "nav.studentAttendance", Icon: IconClipboardCheck, minRole: "teacher" }, - { to: "/management/pomodoros", labelKey: "nav.studentPomodoro", Icon: IconClock, minRole: "teacher" }, - { to: "/work", labelKey: "nav.work", Icon: IconBriefcase, minRole: "teacher", maxRole: "manager" }, - { to: "/management/staff-work", labelKey: "nav.staffWork", Icon: IconBriefcase, minRole: "manager" }, - ], - }, - { - id: "settings", - labelKey: "nav.group.settings", - Icon: IconSettings, - minRole: "manager", - items: [ - { to: "/management/settings", labelKey: "nav.settings", Icon: IconSettings, minRole: "manager" }, - { to: "/management/terms", labelKey: "nav.terms", Icon: IconCalendarDays, minRole: "manager" }, - ], - }, - { - id: "admin", - labelKey: "nav.admin", - Icon: IconUserCog, - minRole: "admin", - items: [ - { to: "/admin/users", labelKey: "nav.users", Icon: IconUsers, minRole: "admin" }, - ], - }, -]; - -const HOME_ITEM: NavItem = { - to: "/", - labelKey: "nav.home", - Icon: IconHome, - exact: true, -}; - -const PARENT_GROUP: NavGroup = { - id: "students", - labelKey: "nav.group.students", - Icon: IconUsers, - exactRole: "parent", - items: [ - { to: "/students", labelKey: "nav.myStudents", Icon: IconUsers, exactRole: "parent" }, - { to: "/messages", labelKey: "nav.messages", Icon: IconMessage, exactRole: "parent" }, - ], -}; - -function pathActive(pathname: string, to: string, exact?: boolean) { - if (exact) return pathname === to; - return pathname === to || pathname.startsWith(`${to}/`); -} +import { IconChevronRight } from "@/components/ui/icons"; +import { HOME_ITEM, pathActive, visibleNavGroups, type NavItem } from "@/components/layout/nav-items"; function NavLink(props: { item: NavItem; @@ -196,30 +51,8 @@ export function SideNav(props: { onNavigate?: () => void; collapsed?: boolean }) const t = useT(); const pathname = useRouterState({ select: (s) => s.location.pathname }); const role = () => auth.user()?.role; - const itemVisible = (item: NavItem) => { - const currentRole = role(); - if (currentRole === "parent") return item.to === "/students" || item.to === "/messages"; - if (item.exactRole) return hasExactRole(currentRole, item.exactRole); - if (item.minRole || item.maxRole) return roleInRange(currentRole, item.minRole, item.maxRole); - return true; - }; - const visibleGroups = createMemo(() => - (role() === "parent" - ? [PARENT_GROUP] - : NAV_GROUPS - .filter((group) => { - const r = role(); - if (group.exactRole && !hasExactRole(r, group.exactRole)) return false; - if (group.minRole && !hasMinRole(r, group.minRole)) return false; - return true; - }) - .map((group) => ({ - ...group, - items: group.items.filter(itemVisible), - })) - .filter((group) => group.items.length > 0)), - ); + const visibleGroups = createMemo(() => visibleNavGroups(role())); const activeGroupId = createMemo( () => visibleGroups().find((group) => group.items.some((item) => pathActive(pathname(), item.to, item.exact)))?.id ?? diff --git a/src/i18n/messages.ts b/src/i18n/messages.ts index 3e394f0..b8ff40f 100644 --- a/src/i18n/messages.ts +++ b/src/i18n/messages.ts @@ -170,6 +170,35 @@ export type MessageKey = | "dashboard.stats.average" | "dashboard.stats.averageHint" | "dashboard.commandCenter" + | "command.group.actions" + | "command.group.navigation" + | "command.group.system" + | "command.action.createHomework" + | "command.action.createHomeworkDesc" + | "command.action.createCourse" + | "command.action.createCourseDesc" + | "command.action.createEvent" + | "command.action.createEventDesc" + | "command.action.createExam" + | "command.action.createExamDesc" + | "command.action.createNote" + | "command.action.createNoteDesc" + | "command.action.importNote" + | "command.action.importNoteDesc" + | "command.action.askQuestion" + | "command.action.askQuestionDesc" + | "command.action.askCelebi" + | "command.action.askCelebiDesc" + | "command.action.myProfile" + | "command.action.myProfileDesc" + | "command.action.themeDark" + | "command.action.themeLight" + | "command.action.themeSystem" + | "command.action.langTr" + | "command.action.langEn" + | "command.action.logout" + | "command.action.logoutDesc" + | "command.shortcutHint" | "dashboard.observationOnly" | "dashboard.today" | "dashboard.reportCard" @@ -938,6 +967,35 @@ const en: Dict = { "dashboard.stats.average": "Average", "dashboard.stats.averageHint": "Overall report card", "dashboard.commandCenter": "Command center", + "command.group.actions": "Quick actions", + "command.group.navigation": "Pages & navigation", + "command.group.system": "System & preferences", + "command.action.createHomework": "Create homework", + "command.action.createHomeworkDesc": "Assign new homework for a course", + "command.action.createCourse": "Create course", + "command.action.createCourseDesc": "Create a new course in system", + "command.action.createEvent": "Schedule event", + "command.action.createEventDesc": "Schedule event or lesson in calendar", + "command.action.createExam": "Create exam", + "command.action.createExamDesc": "Prepare new exam for students", + "command.action.createNote": "Create note", + "command.action.createNoteDesc": "Save a personal or class note", + "command.action.importNote": "Import note assistant", + "command.action.importNoteDesc": "Convert PDF or text files to note", + "command.action.askQuestion": "Ask / add question", + "command.action.askQuestionDesc": "Ask question or add to community pool", + "command.action.askCelebi": "Ask Çelebi AI", + "command.action.askCelebiDesc": "Chat with smart AI assistant", + "command.action.myProfile": "My profile", + "command.action.myProfileDesc": "User account and profile details", + "command.action.themeDark": "Dark theme", + "command.action.themeLight": "Light theme", + "command.action.themeSystem": "System theme", + "command.action.langTr": "Language: Türkçe", + "command.action.langEn": "Language: English", + "command.action.logout": "Log out", + "command.action.logoutDesc": "Sign out of your account", + "command.shortcutHint": "Use arrow keys to navigate, press Enter to select", "dashboard.observationOnly": "Read-only overview of what needs attention.", "dashboard.today": "Today", "dashboard.reportCard": "Report card", @@ -1718,6 +1776,35 @@ const tr: Dict = { "dashboard.stats.average": "Ortalama", "dashboard.stats.averageHint": "Genel karne", "dashboard.commandCenter": "Komuta merkezi", + "command.group.actions": "Hızlı işlemler", + "command.group.navigation": "Sayfalar & gezinme", + "command.group.system": "Sistem & tercihler", + "command.action.createHomework": "Yeni ödev ekle", + "command.action.createHomeworkDesc": "Ders için yeni ödev tanımla", + "command.action.createCourse": "Yeni ders / kurs oluştur", + "command.action.createCourseDesc": "Sisteme yeni ders kaydı ekle", + "command.action.createEvent": "Etkinlik planla", + "command.action.createEventDesc": "Takvime etkinlik veya ders ekle", + "command.action.createExam": "Yeni sınav hazırla", + "command.action.createExamDesc": "Öğrenciler için yeni sınav tanımla", + "command.action.createNote": "Ders notu ekle", + "command.action.createNoteDesc": "Kişisel veya ders notu kaydet", + "command.action.importNote": "Not içe aktar assistant", + "command.action.importNoteDesc": "PDF veya metin belgesini not haline getir", + "command.action.askQuestion": "Soru sor / havuza ekle", + "command.action.askQuestionDesc": "Soru havuzuna yeni soru ekle", + "command.action.askCelebi": "Çelebi AI ile konuş", + "command.action.askCelebiDesc": "Yapay zeka asistanı ile sohbet et", + "command.action.myProfile": "Profil bilgilerim", + "command.action.myProfileDesc": "Kullanıcı hesabı ve profil detayları", + "command.action.themeDark": "Koyu tema", + "command.action.themeLight": "Açık tema", + "command.action.themeSystem": "Sistem teması", + "command.action.langTr": "Dil: Türkçe", + "command.action.langEn": "Dil: English", + "command.action.logout": "Oturumu kapat", + "command.action.logoutDesc": "Mevcut oturumu sonlandır", + "command.shortcutHint": "Yön tuşlarıyla gezinebilir, Enter ile seçebilirsiniz", "dashboard.observationOnly": "Dikkat isteyenlerin salt okunur özeti.", "dashboard.today": "Bugün", "dashboard.reportCard": "Karne", diff --git a/src/pages/courses-page.tsx b/src/pages/courses-page.tsx index 6a6c813..edd2a1a 100644 --- a/src/pages/courses-page.tsx +++ b/src/pages/courses-page.tsx @@ -1,4 +1,4 @@ -import { For, Show, Suspense, createMemo, createResource, createSignal } from "solid-js"; +import { For, Show, Suspense, createEffect, createMemo, createResource, createSignal } from "solid-js"; import type { ColumnDef } from "@tanstack/solid-table"; import { useLocation, useNavigate } from "@tanstack/solid-router"; import { getCourses, postCourse, postCourseTeacher } from "@/api/courses"; @@ -41,7 +41,12 @@ function CoursesContent() { const navigate = useNavigate(); const location = useLocation(); const t = useT(); - const [showForm, setShowForm] = createSignal(false); + const [showForm, setShowForm] = createSignal(location().searchStr.includes("action=new")); + createEffect(() => { + if (location().searchStr.includes("action=new")) { + setShowForm(true); + } + }); const [title, setTitle] = createSignal(""); const [description, setDescription] = createSignal(""); const [termId, setTermId] = createSignal(""); diff --git a/src/pages/events-page.tsx b/src/pages/events-page.tsx index 4538dc4..62e4c5d 100644 --- a/src/pages/events-page.tsx +++ b/src/pages/events-page.tsx @@ -1,5 +1,5 @@ -import { Show, Suspense, createMemo, createResource, createSignal } from "solid-js"; -import { Link, useNavigate } from "@tanstack/solid-router"; +import { Show, Suspense, createEffect, createMemo, createResource, createSignal } from "solid-js"; +import { Link, useLocation, useNavigate } from "@tanstack/solid-router"; import type { ColumnDef } from "@tanstack/solid-table"; import { getEvents } from "@/api/events"; import { postEvent } from "@/api/events"; @@ -37,11 +37,17 @@ export default function EventsPage() { function EventsContent() { const auth = useAuth(); const navigate = useNavigate(); + const location = useLocation(); const { locale } = usePreferences(); const t = useT(); const [error, setError] = createSignal(""); const [flash, setFlash] = createFlash(); - const [showForm, setShowForm] = createSignal(false); + const [showForm, setShowForm] = createSignal(location().searchStr.includes("action=new")); + createEffect(() => { + if (location().searchStr.includes("action=new")) { + setShowForm(true); + } + }); const [timeFilter, setTimeFilter] = createSignal("all"); const canCreate = () => hasMinRole(auth.user()?.role, "teacher"); diff --git a/src/pages/exams-page.tsx b/src/pages/exams-page.tsx index d5f25e1..879e33a 100644 --- a/src/pages/exams-page.tsx +++ b/src/pages/exams-page.tsx @@ -1,6 +1,6 @@ import { For, Show, Suspense, createEffect, createMemo, createResource, createSignal } from "solid-js"; import type { ColumnDef } from "@tanstack/solid-table"; -import { useNavigate } from "@tanstack/solid-router"; +import { useLocation, useNavigate } from "@tanstack/solid-router"; import { getCourseById } from "@/api/courses"; import { getCourses } from "@/api/courses"; import { getExams } from "@/api/exams"; @@ -47,12 +47,18 @@ export default function ExamsPage() { function ExamsContent() { const auth = useAuth(); const navigate = useNavigate(); + const location = useLocation(); const t = useT(); const { locale } = usePreferences(); const now = createNow(); const [statusFilter, setStatusFilter] = createSignal("all"); const [courseFilter, setCourseFilter] = createSignal("all"); - const [createOpen, setCreateOpen] = createSignal(false); + const [createOpen, setCreateOpen] = createSignal(location().searchStr.includes("action=new")); + createEffect(() => { + if (location().searchStr.includes("action=new")) { + setCreateOpen(true); + } + }); const [selectedCourseId, setSelectedCourseId] = createSignal(""); const [editingExam, setEditingExam] = createSignal(null); const [flash, setFlash] = createFlash(); diff --git a/src/pages/homework-page.tsx b/src/pages/homework-page.tsx index f2010eb..9479f64 100644 --- a/src/pages/homework-page.tsx +++ b/src/pages/homework-page.tsx @@ -1,5 +1,5 @@ import { For, Show, Suspense, createEffect, createMemo, createResource, createSignal } from "solid-js"; -import { useNavigate } from "@tanstack/solid-router"; +import { useLocation, useNavigate } from "@tanstack/solid-router"; import type { ColumnDef } from "@tanstack/solid-table"; import { getCourseById, getCourseSubjects, getCourses, postCourseHomework } from "@/api/courses"; import { getHomework } from "@/api/homework"; @@ -54,7 +54,13 @@ function HomeworkContent() { const auth = useAuth(); const { locale } = usePreferences(); const navigate = useNavigate(); - const [createOpen, setCreateOpen] = createSignal(false); + const location = useLocation(); + const [createOpen, setCreateOpen] = createSignal(location().searchStr.includes("action=new")); + createEffect(() => { + if (location().searchStr.includes("action=new")) { + setCreateOpen(true); + } + }); const [selectedCourseId, setSelectedCourseId] = createSignal(""); const [title, setTitle] = createSignal(""); const [description, setDescription] = createSignal(""); diff --git a/src/pages/notes-page.tsx b/src/pages/notes-page.tsx index f83277b..f8c5e10 100644 --- a/src/pages/notes-page.tsx +++ b/src/pages/notes-page.tsx @@ -1,4 +1,5 @@ -import { Show, Suspense, createMemo, createResource, createSignal } from "solid-js"; +import { Show, Suspense, createEffect, createMemo, createResource, createSignal } from "solid-js"; +import { useLocation } from "@tanstack/solid-router"; import { deleteNoteById } from "@/api/notes"; import { getNotes } from "@/api/notes"; import { patchNoteById } from "@/api/notes"; @@ -32,10 +33,15 @@ export default function NotesPage() { function NotesContent() { const t = useT(); + const location = useLocation(); const [error, setError] = createSignal(""); const [flash, setFlash] = createFlash(); - const [createOpen, setCreateOpen] = createSignal(false); - const [importOpen, setImportOpen] = createSignal(false); + const [createOpen, setCreateOpen] = createSignal(location().searchStr.includes("action=new")); + const [importOpen, setImportOpen] = createSignal(location().searchStr.includes("action=import")); + createEffect(() => { + if (location().searchStr.includes("action=new")) setCreateOpen(true); + if (location().searchStr.includes("action=import")) setImportOpen(true); + }); const [page, setPage] = createSignal(0); const [list, { refetch }] = createResource( diff --git a/src/pages/questions-page.tsx b/src/pages/questions-page.tsx index c0382f4..357099a 100644 --- a/src/pages/questions-page.tsx +++ b/src/pages/questions-page.tsx @@ -1,5 +1,5 @@ -import { For, Show, Suspense, createResource, createSignal, lazy } from "solid-js"; -import { Link, useSearch, useNavigate } from "@tanstack/solid-router"; +import { For, Show, Suspense, createEffect, createResource, createSignal, lazy } from "solid-js"; +import { Link, useLocation, useNavigate, useSearch } from "@tanstack/solid-router"; import { getQuestions, postQuestion } from "@/api/shared"; import { getSettings } from "@/api/settings"; import { formatApiError } from "@/api/client"; @@ -37,6 +37,7 @@ function QuestionsContent() { const t = useT(); const auth = useAuth(); const navigate = useNavigate(); + const location = useLocation(); const searchParams = useSearch({ strict: false }); const statusFilter = () => ((searchParams() as any).status === "pending" ? "pending" : "approved"); @@ -46,7 +47,12 @@ function QuestionsContent() { async (params) => (await getQuestions(params.status as "pending" | "approved", params)).items ); - const [askOpen, setAskOpen] = createSignal(false); + const [askOpen, setAskOpen] = createSignal(location().searchStr.includes("action=new")); + createEffect(() => { + if (location().searchStr.includes("action=new")) { + setAskOpen(true); + } + }); return (