✨ server-time validation, notes notebook redesign, course/event filters
Browse files at this commitbb8263a83f699737e68e1da6c58f40ea4e60a58dParent: c8ee30d- feat
- ✨ server-time validation, notes notebook redesign, course/event filters
9 changed files +183 -58
- docs/frontend-next-steps.md +6 -6
- src/components/events/event-form.tsx +4 -1
- src/components/exams/exam-form.tsx +3 -1
- src/components/notes/note-card.tsx +35 -20
- src/components/notes/note-reader-dialog.tsx +30 -0
- src/components/sessions/course-sessions-panel.tsx +12 -6
- src/i18n/messages.ts +6 -0
- src/pages/courses-page.tsx +27 -8
- src/pages/events-page.tsx +60 -16
docs/frontend-next-steps.mdmodified+6 -6
| @@ -122,7 +122,7 @@ Current classification: | |||
| 122 | 122 | ||
| 123 | Known follow-ups: | 123 | Known follow-ups: |
| 124 | 124 | ||
| 125 | -- Ask backend for server-side pagination/search params before claiming true pagination on courses, exams, events, users, work log, or large detail tables. | 125 | +- Backend pagination/search params have been requested; do not claim true server-side pagination until those params exist in the backend README/API contract. |
| 126 | - If backend adds pagination, update `src/api/*` helpers first and then move toolbar/search/filter state into request params. | 126 | - If backend adds pagination, update `src/api/*` helpers first and then move toolbar/search/filter state into request params. |
| 127 | 127 | ||
| 128 | ## Priority 3: Docs Cleanup | 128 | ## Priority 3: Docs Cleanup |
| @@ -137,8 +137,8 @@ Known follow-ups: | |||
| 137 | ### Notes UX | 137 | ### Notes UX |
| 138 | 138 | ||
| 139 | - Note create/edit `FormDialog` has been visually aligned with the newer form system. | 139 | - Note create/edit `FormDialog` has been visually aligned with the newer form system. |
| 140 | -- Decide whether note create/edit should remain a modal, move to `SidePanel`, or become a richer notebook writing layout. | 140 | +- Note create/edit stays in dialogs; note reading also opens a dialog. |
| 141 | -- Decide whether the notes page should stay card-based or become a more structured notebook view. | 141 | +- Notes now render as richer notebook-style pages, with the read dialog using the same paper-like visual language. |
| 142 | - Keep note detail work lightweight unless notes become a durable resource with its own full page. | 142 | - Keep note detail work lightweight unless notes become a durable resource with its own full page. |
| 143 | 143 | ||
| 144 | ### Exam Question Authoring | 144 | ### Exam Question Authoring |
| @@ -150,19 +150,19 @@ Known follow-ups: | |||
| 150 | ### Schedule Validation | 150 | ### Schedule Validation |
| 151 | 151 | ||
| 152 | - Lesson session creation currently validates date shape and end-after-start in the client; backend still enforces not-in-the-past with server time. | 152 | - Lesson session creation currently validates date shape and end-after-start in the client; backend still enforces not-in-the-past with server time. |
| 153 | -- Consider adding a shared server-time helper around `GET /time` before warning users that event/exam/session schedule values are in the past. | 153 | +- Event, exam, and lesson session forms use `GET /time` before warning users that newly scheduled start/end values are in the past. |
| 154 | - Keep client validation advisory only; backend remains authoritative. | 154 | - Keep client validation advisory only; backend remains authoritative. |
| 155 | 155 | ||
| 156 | ### Course Table Polish | 156 | ### Course Table Polish |
| 157 | 157 | ||
| 158 | -- Add a term filter to the courses page. | 158 | +- Courses page has client-side search plus a term/unassigned filter while backend pagination/filter params are pending. |
| 159 | - Consider an enrolled/all filter for students if the list becomes large. | 159 | - Consider an enrolled/all filter for students if the list becomes large. |
| 160 | - Keep the table compact and preserve the full detail page for course resources. | 160 | - Keep the table compact and preserve the full detail page for course resources. |
| 161 | 161 | ||
| 162 | ### Visual Consistency | 162 | ### Visual Consistency |
| 163 | 163 | ||
| 164 | - Settings, terms, notes, attendance, course sessions, and course detail section headers have been visually aligned with the newer radius/form/action language. | 164 | - Settings, terms, notes, attendance, course sessions, and course detail section headers have been visually aligned with the newer radius/form/action language. |
| 165 | -- Decide how far to extend the table/toolbar pattern to `events-page` and remaining card-based views. | 165 | +- Events page keeps card rendering but now uses the shared toolbar pattern for search and upcoming/past filters. |
| 166 | - Preserve non-table layouts only where cards communicate the domain better than rows. | 166 | - Preserve non-table layouts only where cards communicate the domain better than rows. |
| 167 | 167 | ||
| 168 | ## Request Budget Targets | 168 | ## Request Budget Targets |
src/components/events/event-form.tsxmodified+4 -1
| @@ -1,5 +1,6 @@ | |||
| 1 | -import { createSignal, Show } from "solid-js"; | 1 | +import { createResource, createSignal, Show } from "solid-js"; |
| 2 | import { formatApiError } from "@/api/client"; | 2 | import { formatApiError } from "@/api/client"; |
| 3 | +import { getTime } from "@/api/getTime"; | ||
| 3 | import type { Event } from "@/api/types"; | 4 | import type { Event } from "@/api/types"; |
| 4 | import { Button } from "@/components/ui/button"; | 5 | import { Button } from "@/components/ui/button"; |
| 5 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; | 6 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; |
| @@ -67,6 +68,7 @@ export function EventForm(props: { | |||
| 67 | const [pending, setPending] = createSignal(false); | 68 | const [pending, setPending] = createSignal(false); |
| 68 | const [confirmOpen, setConfirmOpen] = createSignal(false); | 69 | const [confirmOpen, setConfirmOpen] = createSignal(false); |
| 69 | const [pendingValues, setPendingValues] = createSignal<EventFormValues | null>(null); | 70 | const [pendingValues, setPendingValues] = createSignal<EventFormValues | null>(null); |
| 71 | + const [serverTime] = createResource(() => getTime().catch(() => ({ now: Date.now() }))); | ||
| 70 | 72 | ||
| 71 | const resolveTime = (date: string, time: string, touched: boolean): number | null | undefined => { | 73 | const resolveTime = (date: string, time: string, touched: boolean): number | null | undefined => { |
| 72 | if (isEdit && !touched) return undefined; | 74 | if (isEdit && !touched) return undefined; |
| @@ -86,6 +88,7 @@ export function EventForm(props: { | |||
| 86 | if (startsTouched() && (startsDate().trim() || startsTime().trim()) && starts == null) return t("form.timeOrder"); | 88 | if (startsTouched() && (startsDate().trim() || startsTime().trim()) && starts == null) return t("form.timeOrder"); |
| 87 | if (endsTouched() && (endsDate().trim() || endsTime().trim()) && ends == null) return t("form.timeOrder"); | 89 | if (endsTouched() && (endsDate().trim() || endsTime().trim()) && ends == null) return t("form.timeOrder"); |
| 88 | if (s != null && e != null && e < s) return t("form.timeOrder"); | 90 | if (s != null && e != null && e < s) return t("form.timeOrder"); |
| 91 | + if ((!isEdit || startsTouched() || endsTouched()) && ((s != null && s < (serverTime()?.now ?? Date.now())) || (e != null && e < (serverTime()?.now ?? Date.now())))) return t("form.timePast"); | ||
| 89 | return null; | 92 | return null; |
| 90 | }; | 93 | }; |
| 91 | 94 | ||
src/components/exams/exam-form.tsxmodified+3 -1
| @@ -2,6 +2,7 @@ import { createEffect, createMemo, createResource, createSignal, Show } from "so | |||
| 2 | import { formatApiError } from "@/api/client"; | 2 | import { formatApiError } from "@/api/client"; |
| 3 | import { For } from "solid-js"; | 3 | import { For } from "solid-js"; |
| 4 | import { getSettings } from "@/api/getSettings"; | 4 | import { getSettings } from "@/api/getSettings"; |
| 5 | +import { getTime } from "@/api/getTime"; | ||
| 5 | import type { Exam } from "@/api/types"; | 6 | import type { Exam } from "@/api/types"; |
| 6 | import { EXAM_KINDS, EXAM_MODES } from "@/api/types"; | 7 | import { EXAM_KINDS, EXAM_MODES } from "@/api/types"; |
| 7 | import { Button } from "@/components/ui/button"; | 8 | import { Button } from "@/components/ui/button"; |
| @@ -88,6 +89,7 @@ export function ExamForm(props: { | |||
| 88 | const [pendingValues, setPendingValues] = createSignal<ExamFormValues | null>(null); | 89 | const [pendingValues, setPendingValues] = createSignal<ExamFormValues | null>(null); |
| 89 | const isEdit = () => !!props.initial?.id; | 90 | const isEdit = () => !!props.initial?.id; |
| 90 | const [settings] = createResource(() => getSettings()); | 91 | const [settings] = createResource(() => getSettings()); |
| 92 | + const [serverTime] = createResource(() => getTime().catch(() => ({ now: Date.now() }))); | ||
| 91 | const examKinds = createMemo(() => { | 93 | const examKinds = createMemo(() => { |
| 92 | const names = settings()?.exam_kinds.map((item) => item.name) ?? EXAM_KINDS; | 94 | const names = settings()?.exam_kinds.map((item) => item.name) ?? EXAM_KINDS; |
| 93 | return names.includes(kind()) ? names : [kind(), ...names]; | 95 | return names.includes(kind()) ? names : [kind(), ...names]; |
| @@ -109,7 +111,7 @@ export function ExamForm(props: { | |||
| 109 | if (mode() === "sync" || mode() === "async") { | 111 | if (mode() === "sync" || mode() === "async") { |
| 110 | if (starts == null || ends == null) return t("exams.scheduleRequired"); | 112 | if (starts == null || ends == null) return t("exams.scheduleRequired"); |
| 111 | if (ends <= starts) return t("form.timeOrder"); | 113 | if (ends <= starts) return t("form.timeOrder"); |
| 112 | - if (!isEdit() && (starts < Date.now() || ends < Date.now())) return t("form.timePast"); | 114 | + if (!isEdit() && (starts < (serverTime()?.now ?? Date.now()) || ends < (serverTime()?.now ?? Date.now()))) return t("form.timePast"); |
| 113 | } | 115 | } |
| 114 | if (mode() === "async") { | 116 | if (mode() === "async") { |
| 115 | if (duration == null) return t("exams.durationRequired"); | 117 | if (duration == null) return t("exams.durationRequired"); |
src/components/notes/note-card.tsxmodified+35 -20
| @@ -2,10 +2,11 @@ import { createSignal } from "solid-js"; | |||
| 2 | import { formatApiError } from "@/api/client"; | 2 | import { formatApiError } from "@/api/client"; |
| 3 | import type { Note } from "@/api/types"; | 3 | import type { Note } from "@/api/types"; |
| 4 | import { NoteForm } from "@/components/notes/note-form"; | 4 | import { NoteForm } from "@/components/notes/note-form"; |
| 5 | -import { Button } from "@/components/ui/button"; | 5 | +import { NoteReaderDialog } from "@/components/notes/note-reader-dialog"; |
| 6 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; | 6 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; |
| 7 | import { FormDialog } from "@/components/ui/form-dialog"; | 7 | import { FormDialog } from "@/components/ui/form-dialog"; |
| 8 | -import { IconTrash } from "@/components/ui/icons"; | 8 | +import { IconEdit, IconTrash } from "@/components/ui/icons"; |
| 9 | +import { TableRowActions } from "@/components/ui/table-row-actions"; | ||
| 9 | import { useT } from "@/stores/preferences-context"; | 10 | import { useT } from "@/stores/preferences-context"; |
| 10 | 11 | ||
| 11 | export function NoteCard(props: { | 12 | export function NoteCard(props: { |
| @@ -14,37 +15,51 @@ export function NoteCard(props: { | |||
| 14 | onDelete: (id: string) => Promise<void>; | 15 | onDelete: (id: string) => Promise<void>; |
| 15 | }) { | 16 | }) { |
| 16 | const t = useT(); | 17 | const t = useT(); |
| 18 | + const [reading, setReading] = createSignal(false); | ||
| 17 | const [editing, setEditing] = createSignal(false); | 19 | const [editing, setEditing] = createSignal(false); |
| 18 | const [error, setError] = createSignal(""); | 20 | const [error, setError] = createSignal(""); |
| 19 | const [deleteOpen, setDeleteOpen] = createSignal(false); | 21 | const [deleteOpen, setDeleteOpen] = createSignal(false); |
| 20 | 22 | ||
| 21 | return ( | 23 | return ( |
| 22 | - <article class="data-shell flex h-full min-h-40 flex-col overflow-hidden transition-colors hover:border-primary/35"> | 24 | + <article |
| 23 | - <div class="flex items-start justify-between gap-3 border-b border-border bg-muted/25 px-3 py-3"> | 25 | + role="button" |
| 26 | + tabindex="0" | ||
| 27 | + class="group flex h-full min-h-72 cursor-pointer flex-col overflow-hidden rounded-2xl border border-amber-200/70 bg-card shadow-sm transition-all hover:-translate-y-0.5 hover:border-amber-400/60 hover:shadow-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring dark:border-amber-500/20" | ||
| 28 | + onClick={() => setReading(true)} | ||
| 29 | + onKeyDown={(event) => { | ||
| 30 | + if (event.key === "Enter" || event.key === " ") setReading(true); | ||
| 31 | + }} | ||
| 32 | + > | ||
| 33 | + <div class="flex items-start justify-between gap-3 border-b border-amber-200/70 bg-amber-50/60 px-4 py-3 dark:border-amber-500/20 dark:bg-amber-500/10"> | ||
| 24 | <h3 class="line-clamp-2 min-w-0 font-display text-base font-semibold leading-snug">{props.note.title}</h3> | 34 | <h3 class="line-clamp-2 min-w-0 font-display text-base font-semibold leading-snug">{props.note.title}</h3> |
| 25 | - <div class="flex shrink-0 gap-1"> | 35 | + <div class="shrink-0" onClick={(event) => event.stopPropagation()}> |
| 26 | - <Button type="button" variant="ghost" size="sm" class="h-7 rounded-sm px-2" onClick={() => setEditing(true)}> | 36 | + <TableRowActions |
| 27 | - {t("common.edit")} | 37 | + label={t("common.actions")} |
| 28 | - </Button> | 38 | + actions={[ |
| 29 | - <Button | 39 | + { |
| 30 | - type="button" | 40 | + label: t("common.edit"), |
| 31 | - variant="ghost" | 41 | + icon: <IconEdit class="h-4 w-4" />, |
| 32 | - size="sm" | 42 | + onSelect: () => setEditing(true), |
| 33 | - class="h-7 rounded-sm px-2 text-destructive hover:bg-destructive/10 hover:text-destructive" | 43 | + }, |
| 34 | - onClick={() => setDeleteOpen(true)} | 44 | + { |
| 35 | - > | 45 | + label: t("common.delete"), |
| 36 | - <IconTrash class="h-4 w-4" /> | 46 | + icon: <IconTrash class="h-4 w-4" />, |
| 37 | - {t("common.delete")} | 47 | + destructive: true, |
| 38 | - </Button> | 48 | + onSelect: () => setDeleteOpen(true), |
| 49 | + }, | ||
| 50 | + ]} | ||
| 51 | + /> | ||
| 39 | </div> | 52 | </div> |
| 40 | </div> | 53 | </div> |
| 41 | - <div class="flex flex-1 flex-col gap-4 p-3"> | 54 | + <div class="flex flex-1 flex-col gap-4 bg-[linear-gradient(90deg,rgba(245,158,11,0.12)_0,rgba(245,158,11,0.12)_2.25rem,transparent_2.25rem),repeating-linear-gradient(0deg,transparent_0,transparent_2.05rem,rgba(120,113,108,0.14)_2.1rem)] px-4 py-4 pl-12 dark:bg-[linear-gradient(90deg,rgba(245,158,11,0.1)_0,rgba(245,158,11,0.1)_2.25rem,transparent_2.25rem),repeating-linear-gradient(0deg,transparent_0,transparent_2.05rem,rgba(214,211,209,0.1)_2.1rem)]"> |
| 42 | - <p class="whitespace-pre-wrap text-[13px] leading-relaxed text-muted-foreground"> | 55 | + <p class="line-clamp-6 whitespace-pre-wrap text-[13px] leading-8 text-muted-foreground group-hover:text-foreground"> |
| 43 | {props.note.content || t("notes.noContent")} | 56 | {props.note.content || t("notes.noContent")} |
| 44 | </p> | 57 | </p> |
| 45 | {error() && <p class="text-sm text-destructive">{error()}</p>} | 58 | {error() && <p class="text-sm text-destructive">{error()}</p>} |
| 46 | </div> | 59 | </div> |
| 47 | 60 | ||
| 61 | + <NoteReaderDialog note={props.note} open={reading()} onOpenChange={setReading} /> | ||
| 62 | + | ||
| 48 | <FormDialog | 63 | <FormDialog |
| 49 | open={editing()} | 64 | open={editing()} |
| 50 | onOpenChange={setEditing} | 65 | onOpenChange={setEditing} |
src/components/notes/note-reader-dialog.tsxadded+30 -0
| @@ -0,0 +1,30 @@ | |||
| 1 | +import { For, Show, createMemo } from "solid-js"; | ||
| 2 | +import type { Note } from "@/api/types"; | ||
| 3 | +import { FormDialog } from "@/components/ui/form-dialog"; | ||
| 4 | +import { useT } from "@/stores/preferences-context"; | ||
| 5 | + | ||
| 6 | +export function NoteReaderDialog(props: { | ||
| 7 | + note: Note; | ||
| 8 | + open: boolean; | ||
| 9 | + onOpenChange: (open: boolean) => void; | ||
| 10 | +}) { | ||
| 11 | + const t = useT(); | ||
| 12 | + const paragraphs = createMemo(() => props.note.content.split(/\n{2,}/).map((part) => part.trim()).filter(Boolean)); | ||
| 13 | + | ||
| 14 | + return ( | ||
| 15 | + <FormDialog open={props.open} onOpenChange={props.onOpenChange} title={props.note.title} description={t("notes.subtitle")}> | ||
| 16 | + <article class="overflow-hidden rounded-2xl border border-amber-200/70 bg-[linear-gradient(90deg,rgba(245,158,11,0.14)_0,rgba(245,158,11,0.14)_3rem,transparent_3rem),repeating-linear-gradient(0deg,transparent_0,transparent_2.45rem,rgba(120,113,108,0.16)_2.5rem)] shadow-sm dark:border-amber-500/20 dark:bg-[linear-gradient(90deg,rgba(245,158,11,0.12)_0,rgba(245,158,11,0.12)_3rem,transparent_3rem),repeating-linear-gradient(0deg,transparent_0,transparent_2.45rem,rgba(214,211,209,0.12)_2.5rem)]"> | ||
| 17 | + <div class="min-h-80 space-y-4 px-5 py-5 pl-16"> | ||
| 18 | + <Show | ||
| 19 | + when={paragraphs().length > 0} | ||
| 20 | + fallback={<p class="text-sm italic leading-8 text-muted-foreground">{t("notes.noContent")}</p>} | ||
| 21 | + > | ||
| 22 | + <For each={paragraphs()}> | ||
| 23 | + {(paragraph) => <p class="whitespace-pre-wrap text-sm leading-8 text-foreground">{paragraph}</p>} | ||
| 24 | + </For> | ||
| 25 | + </Show> | ||
| 26 | + </div> | ||
| 27 | + </article> | ||
| 28 | + </FormDialog> | ||
| 29 | + ); | ||
| 30 | +} | ||
src/components/sessions/course-sessions-panel.tsxmodified+12 -6
| @@ -2,6 +2,7 @@ import { For, Show, Suspense, createEffect, createMemo, createResource, createSi | |||
| 2 | import { deleteSessionById } from "@/api/deleteSessionById"; | 2 | import { deleteSessionById } from "@/api/deleteSessionById"; |
| 3 | import { getCourseSessions } from "@/api/getCourseSessions"; | 3 | import { getCourseSessions } from "@/api/getCourseSessions"; |
| 4 | import { getSessionAttendance } from "@/api/getSessionAttendance"; | 4 | import { getSessionAttendance } from "@/api/getSessionAttendance"; |
| 5 | +import { getTime } from "@/api/getTime"; | ||
| 5 | import { postCourseSession } from "@/api/postCourseSession"; | 6 | import { postCourseSession } from "@/api/postCourseSession"; |
| 6 | import { postSessionAttendance } from "@/api/postSessionAttendance"; | 7 | import { postSessionAttendance } from "@/api/postSessionAttendance"; |
| 7 | import { formatApiError } from "@/api/client"; | 8 | import { formatApiError } from "@/api/client"; |
| @@ -60,6 +61,7 @@ export function CourseSessionsPanel(props: { | |||
| 60 | const [endsTime, setEndsTime] = createSignal(""); | 61 | const [endsTime, setEndsTime] = createSignal(""); |
| 61 | const [error, setError] = createSignal(""); | 62 | const [error, setError] = createSignal(""); |
| 62 | const [pending, setPending] = createSignal(false); | 63 | const [pending, setPending] = createSignal(false); |
| 64 | + const [serverTime] = createResource(() => getTime().catch(() => ({ now: Date.now() }))); | ||
| 63 | 65 | ||
| 64 | const resetCreateForm = () => { | 66 | const resetCreateForm = () => { |
| 65 | setTopic(""); | 67 | setTopic(""); |
| @@ -87,6 +89,10 @@ export function CourseSessionsPanel(props: { | |||
| 87 | setError(t("form.timeOrder")); | 89 | setError(t("form.timeOrder")); |
| 88 | return; | 90 | return; |
| 89 | } | 91 | } |
| 92 | + if (starts_at < (serverTime()?.now ?? Date.now()) || (ends_at != null && ends_at < (serverTime()?.now ?? Date.now()))) { | ||
| 93 | + setError(t("form.timePast")); | ||
| 94 | + return; | ||
| 95 | + } | ||
| 90 | setPending(true); | 96 | setPending(true); |
| 91 | try { | 97 | try { |
| 92 | const body = { | 98 | const body = { |
| @@ -161,16 +167,16 @@ export function CourseSessionsPanel(props: { | |||
| 161 | <div class="grid gap-3"> | 167 | <div class="grid gap-3"> |
| 162 | <div class="space-y-1.5"> | 168 | <div class="space-y-1.5"> |
| 163 | <Label for="session-starts">{t("events.starts")}</Label> | 169 | <Label for="session-starts">{t("events.starts")}</Label> |
| 164 | - <div class="grid grid-cols-[minmax(0,1fr)_6.5rem] gap-2"> | 170 | + <div class="grid grid-cols-2 gap-2"> |
| 165 | - <DatePicker id="session-starts" placeholder={t("form.datePlaceholder")} value={startsDate()} required onChange={setStartsDate} /> | 171 | + <DatePicker id="session-starts" class="h-10" placeholder={t("form.datePlaceholder")} value={startsDate()} required onChange={setStartsDate} /> |
| 166 | - <Input class="font-mono placeholder:text-muted-foreground/35" placeholder="09:00" value={startsTime()} required onInput={(e) => setStartsTime(e.currentTarget.value)} /> | 172 | + <Input class="h-10 rounded-sm font-mono placeholder:text-muted-foreground/35" placeholder="09:00" value={startsTime()} required onInput={(e) => setStartsTime(e.currentTarget.value)} /> |
| 167 | </div> | 173 | </div> |
| 168 | </div> | 174 | </div> |
| 169 | <div class="space-y-1.5"> | 175 | <div class="space-y-1.5"> |
| 170 | <Label for="session-ends">{t("events.ends")}</Label> | 176 | <Label for="session-ends">{t("events.ends")}</Label> |
| 171 | - <div class="grid grid-cols-[minmax(0,1fr)_6.5rem] gap-2"> | 177 | + <div class="grid grid-cols-2 gap-2"> |
| 172 | - <DatePicker id="session-ends" placeholder={t("form.datePlaceholder")} value={endsDate()} onChange={setEndsDate} /> | 178 | + <DatePicker id="session-ends" class="h-10" placeholder={t("form.datePlaceholder")} value={endsDate()} onChange={setEndsDate} /> |
| 173 | - <Input class="font-mono placeholder:text-muted-foreground/35" placeholder="10:00" value={endsTime()} onInput={(e) => setEndsTime(e.currentTarget.value)} /> | 179 | + <Input class="h-10 rounded-sm font-mono placeholder:text-muted-foreground/35" placeholder="10:00" value={endsTime()} onInput={(e) => setEndsTime(e.currentTarget.value)} /> |
| 174 | </div> | 180 | </div> |
| 175 | </div> | 181 | </div> |
| 176 | </div> | 182 | </div> |
src/i18n/messages.tsmodified+6 -0
| @@ -190,6 +190,8 @@ export type MessageKey = | |||
| 190 | | "events.helpBody" | 190 | | "events.helpBody" |
| 191 | | "events.clearStart" | 191 | | "events.clearStart" |
| 192 | | "events.clearEnd" | 192 | | "events.clearEnd" |
| 193 | + | "events.upcoming" | ||
| 194 | + | "events.past" | ||
| 193 | | "exams.title" | 195 | | "exams.title" |
| 194 | | "exams.subtitle" | 196 | | "exams.subtitle" |
| 195 | | "exams.create" | 197 | | "exams.create" |
| @@ -670,6 +672,8 @@ const en: Dict = { | |||
| 670 | "Students mark themselves present / absent / late / excused with the big status buttons, then save attendance. Teachers create events and can mark others by user id. Managers can edit any event.", | 672 | "Students mark themselves present / absent / late / excused with the big status buttons, then save attendance. Teachers create events and can mark others by user id. Managers can edit any event.", |
| 671 | "events.clearStart": "Will clear start time", | 673 | "events.clearStart": "Will clear start time", |
| 672 | "events.clearEnd": "Will clear end time", | 674 | "events.clearEnd": "Will clear end time", |
| 675 | + "events.upcoming": "Upcoming", | ||
| 676 | + "events.past": "Past", | ||
| 673 | "exams.title": "Exams", | 677 | "exams.title": "Exams", |
| 674 | "exams.subtitle": "All exams across courses — create them under a course.", | 678 | "exams.subtitle": "All exams across courses — create them under a course.", |
| 675 | "exams.create": "Create exam", | 679 | "exams.create": "Create exam", |
| @@ -1160,6 +1164,8 @@ const tr: Dict = { | |||
| 1160 | "Öğrenciler büyük durum butonlarıyla var/yok/geç/mazeretli seçip yoklamayı kaydeder. Öğretmenler etkinlik oluşturur ve başkasını işaretleyebilir. Yöneticiler her etkinliği düzenleyebilir.", | 1164 | "Öğrenciler büyük durum butonlarıyla var/yok/geç/mazeretli seçip yoklamayı kaydeder. Öğretmenler etkinlik oluşturur ve başkasını işaretleyebilir. Yöneticiler her etkinliği düzenleyebilir.", |
| 1161 | "events.clearStart": "Başlangıç saati temizlenecek", | 1165 | "events.clearStart": "Başlangıç saati temizlenecek", |
| 1162 | "events.clearEnd": "Bitiş saati temizlenecek", | 1166 | "events.clearEnd": "Bitiş saati temizlenecek", |
| 1167 | + "events.upcoming": "Yaklaşan", | ||
| 1168 | + "events.past": "Geçmiş", | ||
| 1163 | "exams.title": "Sınavlar", | 1169 | "exams.title": "Sınavlar", |
| 1164 | "exams.subtitle": "Tüm derslerin sınavları — yeni sınav ders içinden eklenir.", | 1170 | "exams.subtitle": "Tüm derslerin sınavları — yeni sınav ders içinden eklenir.", |
| 1165 | "exams.create": "Sınav oluştur", | 1171 | "exams.create": "Sınav oluştur", |
src/pages/courses-page.tsxmodified+27 -8
| @@ -61,6 +61,7 @@ function CoursesContent() { | |||
| 61 | const [error, setError] = createSignal(""); | 61 | const [error, setError] = createSignal(""); |
| 62 | const [pending, setPending] = createSignal(false); | 62 | const [pending, setPending] = createSignal(false); |
| 63 | const [query, setQuery] = createSignal(""); | 63 | const [query, setQuery] = createSignal(""); |
| 64 | + const [termFilter, setTermFilter] = createSignal("all"); | ||
| 64 | const [page, setPage] = createSignal(0); | 65 | const [page, setPage] = createSignal(0); |
| 65 | const canCreate = () => hasMinRole(auth.user()?.role, "teacher"); | 66 | const canCreate = () => hasMinRole(auth.user()?.role, "teacher"); |
| 66 | const isStudent = () => auth.user()?.role === "student"; | 67 | const isStudent = () => auth.user()?.role === "student"; |
| @@ -72,13 +73,16 @@ function CoursesContent() { | |||
| 72 | }; | 73 | }; |
| 73 | const filteredCourses = createMemo(() => { | 74 | const filteredCourses = createMemo(() => { |
| 74 | const needle = query().trim().toLocaleLowerCase(); | 75 | const needle = query().trim().toLocaleLowerCase(); |
| 75 | - if (!needle) return courseList(); | 76 | + const selectedTerm = termFilter(); |
| 76 | - return courseList().filter((course) => | 77 | + return courseList().filter((course) => { |
| 77 | - [course.title, course.description, course.creator, creatorName(course.creator), termName(course.term_id)] | 78 | + if (selectedTerm === "unassigned" && course.term_id) return false; |
| 79 | + if (selectedTerm !== "all" && selectedTerm !== "unassigned" && course.term_id !== selectedTerm) return false; | ||
| 80 | + if (!needle) return true; | ||
| 81 | + return [course.title, course.description, course.creator, creatorName(course.creator), termName(course.term_id)] | ||
| 78 | .join(" ") | 82 | .join(" ") |
| 79 | .toLocaleLowerCase() | 83 | .toLocaleLowerCase() |
| 80 | - .includes(needle), | 84 | + .includes(needle); |
| 81 | - ); | 85 | + }); |
| 82 | }); | 86 | }); |
| 83 | const totalPages = createMemo(() => Math.max(1, Math.ceil(filteredCourses().length / COURSE_PAGE_SIZE))); | 87 | const totalPages = createMemo(() => Math.max(1, Math.ceil(filteredCourses().length / COURSE_PAGE_SIZE))); |
| 84 | const safePage = createMemo(() => Math.min(page(), totalPages() - 1)); | 88 | const safePage = createMemo(() => Math.min(page(), totalPages() - 1)); |
| @@ -183,9 +187,24 @@ function CoursesContent() { | |||
| 183 | setPage(0); | 187 | setPage(0); |
| 184 | }} | 188 | }} |
| 185 | filters={ | 189 | filters={ |
| 186 | - <Badge variant="outline" class="mono h-9 rounded-sm px-3 uppercase tracking-[0.08em]"> | 190 | + <div class="flex flex-wrap items-center gap-2"> |
| 187 | - {isStudent() ? t("courses.enrolled") : t("common.all")} | 191 | + <Badge variant="outline" class="mono h-9 rounded-sm px-3 uppercase tracking-[0.08em]"> |
| 188 | - </Badge> | 192 | + {isStudent() ? t("courses.enrolled") : t("common.all")} |
| 193 | + </Badge> | ||
| 194 | + <Select | ||
| 195 | + class="h-9 w-full rounded-sm sm:w-44" | ||
| 196 | + value={termFilter()} | ||
| 197 | + aria-label={t("terms.term")} | ||
| 198 | + onChange={(event) => { | ||
| 199 | + setTermFilter(event.currentTarget.value); | ||
| 200 | + setPage(0); | ||
| 201 | + }} | ||
| 202 | + > | ||
| 203 | + <option value="all">{t("common.all")}</option> | ||
| 204 | + <option value="unassigned">{t("terms.unassigned")}</option> | ||
| 205 | + <For each={terms() ?? []}>{(term) => <option value={term.id}>{term.name}</option>}</For> | ||
| 206 | + </Select> | ||
| 207 | + </div> | ||
| 189 | } | 208 | } |
| 190 | /> | 209 | /> |
| 191 | 210 | ||
src/pages/events-page.tsxmodified+60 -16
| @@ -8,12 +8,15 @@ import { EventCard } from "@/components/events/event-card"; | |||
| 8 | import { EventForm } from "@/components/events/event-form"; | 8 | import { EventForm } from "@/components/events/event-form"; |
| 9 | import { RouteGuard } from "@/components/layout/route-guard"; | 9 | import { RouteGuard } from "@/components/layout/route-guard"; |
| 10 | import { PageHeader } from "@/components/layout/page-header"; | 10 | import { PageHeader } from "@/components/layout/page-header"; |
| 11 | +import { DataToolbar } from "@/components/ui/data-toolbar"; | ||
| 11 | import { IconPlus } from "@/components/ui/icons"; | 12 | import { IconPlus } from "@/components/ui/icons"; |
| 12 | import { PageSpinner } from "@/components/ui/page-spinner"; | 13 | import { PageSpinner } from "@/components/ui/page-spinner"; |
| 13 | import { PaginationControls } from "@/components/ui/pagination-controls"; | 14 | import { PaginationControls } from "@/components/ui/pagination-controls"; |
| 15 | +import { Select } from "@/components/ui/select"; | ||
| 14 | import { SidePanel } from "@/components/ui/side-panel"; | 16 | import { SidePanel } from "@/components/ui/side-panel"; |
| 15 | import { useAuth } from "@/stores/auth-context"; | 17 | import { useAuth } from "@/stores/auth-context"; |
| 16 | -import { useT } from "@/stores/preferences-context"; | 18 | +import { usePreferences, useT } from "@/stores/preferences-context"; |
| 19 | +import { formatDateTime } from "@/lib/format"; | ||
| 17 | import { hasMinRole } from "@/lib/roles"; | 20 | import { hasMinRole } from "@/lib/roles"; |
| 18 | 21 | ||
| 19 | const EVENT_PAGE_SIZE = 9; | 22 | const EVENT_PAGE_SIZE = 9; |
| @@ -28,18 +31,35 @@ export default function EventsPage() { | |||
| 28 | 31 | ||
| 29 | function EventsContent() { | 32 | function EventsContent() { |
| 30 | const auth = useAuth(); | 33 | const auth = useAuth(); |
| 34 | + const { locale } = usePreferences(); | ||
| 31 | const t = useT(); | 35 | const t = useT(); |
| 32 | const [events, { refetch }] = createResource(() => getEvents()); | 36 | const [events, { refetch }] = createResource(() => getEvents()); |
| 33 | const [error, setError] = createSignal(""); | 37 | const [error, setError] = createSignal(""); |
| 34 | const [showForm, setShowForm] = createSignal(false); | 38 | const [showForm, setShowForm] = createSignal(false); |
| 39 | + const [query, setQuery] = createSignal(""); | ||
| 40 | + const [timeFilter, setTimeFilter] = createSignal("all"); | ||
| 35 | const [page, setPage] = createSignal(0); | 41 | const [page, setPage] = createSignal(0); |
| 36 | const canCreate = () => hasMinRole(auth.user()?.role, "teacher"); | 42 | const canCreate = () => hasMinRole(auth.user()?.role, "teacher"); |
| 37 | const eventList = createMemo(() => events() ?? []); | 43 | const eventList = createMemo(() => events() ?? []); |
| 38 | - const totalPages = createMemo(() => Math.max(1, Math.ceil(eventList().length / EVENT_PAGE_SIZE))); | 44 | + const filteredEvents = createMemo(() => { |
| 45 | + const needle = query().trim().toLocaleLowerCase(); | ||
| 46 | + const scope = timeFilter(); | ||
| 47 | + const now = Date.now(); | ||
| 48 | + return eventList().filter((event) => { | ||
| 49 | + if (scope === "upcoming" && event.ends_at != null && event.ends_at < now) return false; | ||
| 50 | + if (scope === "past" && (event.ends_at == null || event.ends_at >= now)) return false; | ||
| 51 | + if (!needle) return true; | ||
| 52 | + return [event.title, event.description, formatDateTime(event.starts_at, locale()), formatDateTime(event.ends_at, locale())] | ||
| 53 | + .join(" ") | ||
| 54 | + .toLocaleLowerCase() | ||
| 55 | + .includes(needle); | ||
| 56 | + }); | ||
| 57 | + }); | ||
| 58 | + const totalPages = createMemo(() => Math.max(1, Math.ceil(filteredEvents().length / EVENT_PAGE_SIZE))); | ||
| 39 | const safePage = createMemo(() => Math.min(page(), totalPages() - 1)); | 59 | const safePage = createMemo(() => Math.min(page(), totalPages() - 1)); |
| 40 | const pageItems = createMemo(() => { | 60 | const pageItems = createMemo(() => { |
| 41 | const start = safePage() * EVENT_PAGE_SIZE; | 61 | const start = safePage() * EVENT_PAGE_SIZE; |
| 42 | - return eventList().slice(start, start + EVENT_PAGE_SIZE); | 62 | + return filteredEvents().slice(start, start + EVENT_PAGE_SIZE); |
| 43 | }); | 63 | }); |
| 44 | 64 | ||
| 45 | return ( | 65 | return ( |
| @@ -95,25 +115,49 @@ function EventsContent() { | |||
| 95 | 115 | ||
| 96 | {error() && <p class="text-sm text-destructive">{error()}</p>} | 116 | {error() && <p class="text-sm text-destructive">{error()}</p>} |
| 97 | 117 | ||
| 98 | - <Suspense fallback={<PageSpinner />}> | 118 | + <section class="data-shell space-y-4 p-4"> |
| 99 | - <Show when={events.error}> | 119 | + <DataToolbar |
| 100 | - <Alert variant="destructive">{formatApiError(events.error)}</Alert> | 120 | + searchValue={query()} |
| 101 | - </Show> | 121 | + searchPlaceholder={t("common.searchPlaceholder")} |
| 102 | - <Show when={events()}> | 122 | + onSearchInput={(value) => { |
| 103 | - {(list) => ( | 123 | + setQuery(value); |
| 124 | + setPage(0); | ||
| 125 | + }} | ||
| 126 | + filters={ | ||
| 127 | + <Select | ||
| 128 | + class="h-9 w-full rounded-sm sm:w-44" | ||
| 129 | + value={timeFilter()} | ||
| 130 | + aria-label={t("events.title")} | ||
| 131 | + onChange={(event) => { | ||
| 132 | + setTimeFilter(event.currentTarget.value); | ||
| 133 | + setPage(0); | ||
| 134 | + }} | ||
| 135 | + > | ||
| 136 | + <option value="all">{t("common.all")}</option> | ||
| 137 | + <option value="upcoming">{t("events.upcoming")}</option> | ||
| 138 | + <option value="past">{t("events.past")}</option> | ||
| 139 | + </Select> | ||
| 140 | + } | ||
| 141 | + /> | ||
| 142 | + | ||
| 143 | + <Suspense fallback={<PageSpinner />}> | ||
| 144 | + <Show when={events.error}> | ||
| 145 | + <Alert variant="destructive">{formatApiError(events.error)}</Alert> | ||
| 146 | + </Show> | ||
| 147 | + <Show when={events() !== undefined}> | ||
| 104 | <Show | 148 | <Show |
| 105 | - when={list().length > 0} | 149 | + when={filteredEvents().length > 0} |
| 106 | fallback={ | 150 | fallback={ |
| 107 | <div class="rounded-sm border border-dashed border-border bg-muted/20 px-6 py-16 text-center text-sm text-muted-foreground"> | 151 | <div class="rounded-sm border border-dashed border-border bg-muted/20 px-6 py-16 text-center text-sm text-muted-foreground"> |
| 108 | {t("events.empty")} | 152 | {t("events.empty")} |
| 109 | </div> | 153 | </div> |
| 110 | } | 154 | } |
| 111 | > | 155 | > |
| 112 | - <div class="space-y-4"> | 156 | + <div class="space-y-4"> |
| 113 | <div class="flex flex-wrap items-center justify-between gap-3"> | 157 | <div class="flex flex-wrap items-center justify-between gap-3"> |
| 114 | <div> | 158 | <div> |
| 115 | <h2 class="font-display text-lg font-semibold">{t("events.title")}</h2> | 159 | <h2 class="font-display text-lg font-semibold">{t("events.title")}</h2> |
| 116 | - <p class="mt-1 text-sm text-muted-foreground">{eventList().length} {t("nav.events")}</p> | 160 | + <p class="mt-1 text-sm text-muted-foreground">{filteredEvents().length} / {eventList().length} {t("nav.events")}</p> |
| 117 | </div> | 161 | </div> |
| 118 | </div> | 162 | </div> |
| 119 | <ul class="grid gap-3 sm:grid-cols-2 xl:grid-cols-3"> | 163 | <ul class="grid gap-3 sm:grid-cols-2 xl:grid-cols-3"> |
| @@ -125,14 +169,14 @@ function EventsContent() { | |||
| 125 | )} | 169 | )} |
| 126 | </For> | 170 | </For> |
| 127 | </ul> | 171 | </ul> |
| 128 | - <Show when={eventList().length > EVENT_PAGE_SIZE}> | 172 | + <Show when={filteredEvents().length > EVENT_PAGE_SIZE}> |
| 129 | <PaginationControls page={safePage()} totalPages={totalPages()} onPageChange={setPage} /> | 173 | <PaginationControls page={safePage()} totalPages={totalPages()} onPageChange={setPage} /> |
| 130 | </Show> | 174 | </Show> |
| 131 | </div> | 175 | </div> |
| 132 | </Show> | 176 | </Show> |
| 133 | - )} | 177 | + </Show> |
| 134 | - </Show> | 178 | + </Suspense> |
| 135 | - </Suspense> | 179 | + </section> |
| 136 | </div> | 180 | </div> |
| 137 | ); | 181 | ); |
| 138 | } | 182 | } |