🐛 flash and schedule status regressions
Browse files at this commit1c125f7a394220acbef8abacb2f378c9ff185d34Parent: 86d63de- fix
- 🐛 flash and schedule status regressions
4 changed files +22 -14
- src/components/events/event-card.tsx +3 -1
- src/lib/flash.ts +8 -3
- src/pages/dashboard-page.tsx +3 -2
- src/pages/event-detail-page.tsx +8 -8
src/components/events/event-card.tsxmodified+3 -1
| @@ -4,6 +4,7 @@ import type { Event, EventAudience } from "@/api/types"; | |||
| 4 | import type { MessageKey } from "@/i18n/messages"; | 4 | import type { MessageKey } from "@/i18n/messages"; |
| 5 | import { Badge } from "@/components/ui/badge"; | 5 | import { Badge } from "@/components/ui/badge"; |
| 6 | import { cn } from "@/lib/cn"; | 6 | import { cn } from "@/lib/cn"; |
| 7 | +import { createNow } from "@/lib/create-now"; | ||
| 7 | import { formatDateTime } from "@/lib/format"; | 8 | import { formatDateTime } from "@/lib/format"; |
| 8 | import { scheduleStatusClass, scheduleStatusDotClass, type ScheduleStatus } from "@/lib/schedule-status"; | 9 | import { scheduleStatusClass, scheduleStatusDotClass, type ScheduleStatus } from "@/lib/schedule-status"; |
| 9 | import { usePreferences, useT } from "@/stores/preferences-context"; | 10 | import { usePreferences, useT } from "@/stores/preferences-context"; |
| @@ -25,7 +26,8 @@ function eventStatus(event: Event, now: number): ScheduleStatus { | |||
| 25 | export function EventCard(props: { event: Event }) { | 26 | export function EventCard(props: { event: Event }) { |
| 26 | const t = useT(); | 27 | const t = useT(); |
| 27 | const { locale } = usePreferences(); | 28 | const { locale } = usePreferences(); |
| 28 | - const status = () => eventStatus(props.event, Date.now()); | 29 | + const now = createNow(); |
| 30 | + const status = () => eventStatus(props.event, now()); | ||
| 29 | const statusLabel = () => { | 31 | const statusLabel = () => { |
| 30 | const s = status(); | 32 | const s = status(); |
| 31 | if (s === "unscheduled") return t("exams.unscheduled"); | 33 | if (s === "unscheduled") return t("exams.unscheduled"); |
src/lib/flash.tsmodified+8 -3
| @@ -1,13 +1,18 @@ | |||
| 1 | -import { createEffect, createSignal, onCleanup, type Accessor, type Setter } from "solid-js"; | 1 | +import { createEffect, createSignal, onCleanup, type Accessor } from "solid-js"; |
| 2 | 2 | ||
| 3 | /** Short-lived success banner; auto-clears after `ms` (default 3s). */ | 3 | /** Short-lived success banner; auto-clears after `ms` (default 3s). */ |
| 4 | -export function createFlash(ms = 3000): [Accessor<string>, Setter<string>] { | 4 | +export function createFlash(ms = 3000): [Accessor<string>, (text: string) => void] { |
| 5 | const [message, setMessage] = createSignal(""); | 5 | const [message, setMessage] = createSignal(""); |
| 6 | + const [tick, setTick] = createSignal(0); | ||
| 6 | createEffect(() => { | 7 | createEffect(() => { |
| 8 | + tick(); | ||
| 7 | const text = message(); | 9 | const text = message(); |
| 8 | if (!text) return; | 10 | if (!text) return; |
| 9 | const id = window.setTimeout(() => setMessage(""), ms); | 11 | const id = window.setTimeout(() => setMessage(""), ms); |
| 10 | onCleanup(() => window.clearTimeout(id)); | 12 | onCleanup(() => window.clearTimeout(id)); |
| 11 | }); | 13 | }); |
| 12 | - return [message, setMessage]; | 14 | + return [message, (text) => { |
| 15 | + setMessage(text); | ||
| 16 | + setTick((value) => value + 1); | ||
| 17 | + }]; | ||
| 13 | } | 18 | } |
src/pages/dashboard-page.tsxmodified+3 -2
| @@ -25,6 +25,7 @@ import { | |||
| 25 | import { PageSpinner } from "@/components/ui/page-spinner"; | 25 | import { PageSpinner } from "@/components/ui/page-spinner"; |
| 26 | import type { MessageKey } from "@/i18n/messages"; | 26 | import type { MessageKey } from "@/i18n/messages"; |
| 27 | import { cn } from "@/lib/cn"; | 27 | import { cn } from "@/lib/cn"; |
| 28 | +import { createNow } from "@/lib/create-now"; | ||
| 28 | import { examKindLabel } from "@/lib/exam-labels"; | 29 | import { examKindLabel } from "@/lib/exam-labels"; |
| 29 | import { formatDateTime } from "@/lib/format"; | 30 | import { formatDateTime } from "@/lib/format"; |
| 30 | import { hasMinRole } from "@/lib/roles"; | 31 | import { hasMinRole } from "@/lib/roles"; |
| @@ -104,7 +105,7 @@ function DashboardContent() { | |||
| 104 | const { locale } = usePreferences(); | 105 | const { locale } = usePreferences(); |
| 105 | const user = () => auth.user()!; | 106 | const user = () => auth.user()!; |
| 106 | const role = () => user().role; | 107 | const role = () => user().role; |
| 107 | - const now = () => Date.now(); | 108 | + const now = createNow(); |
| 108 | 109 | ||
| 109 | const [courses] = createResource( | 110 | const [courses] = createResource( |
| 110 | () => (role() !== "student" ? true : null), | 111 | () => (role() !== "student" ? true : null), |
| @@ -318,7 +319,7 @@ function DashboardContent() { | |||
| 318 | <span class="rounded-md border border-border bg-background px-2 py-1 font-medium text-foreground shadow-sm"> | 319 | <span class="rounded-md border border-border bg-background px-2 py-1 font-medium text-foreground shadow-sm"> |
| 319 | {t(ROLE_KEY[role()])} | 320 | {t(ROLE_KEY[role()])} |
| 320 | </span> | 321 | </span> |
| 321 | - <span class="mono tabular-nums">{formatDateTime(Date.now(), locale()).split(",")[0]}</span> | 322 | + <span class="mono tabular-nums">{formatDateTime(now(), locale()).split(",")[0]}</span> |
| 322 | </div> | 323 | </div> |
| 323 | </header> | 324 | </header> |
| 324 | 325 | ||
src/pages/event-detail-page.tsxmodified+8 -8
| @@ -226,21 +226,21 @@ function EventDetailContent() { | |||
| 226 | type="button" | 226 | type="button" |
| 227 | class="w-full rounded-sm sm:w-auto" | 227 | class="w-full rounded-sm sm:w-auto" |
| 228 | disabled={pending()} | 228 | disabled={pending()} |
| 229 | - onClick={() => | 229 | + onClick={() => { |
| 230 | + const uid = otherUserId().trim(); | ||
| 231 | + if (!uid) { | ||
| 232 | + setError(t("events.userIdRequired")); | ||
| 233 | + return; | ||
| 234 | + } | ||
| 230 | void wrap(async () => { | 235 | void wrap(async () => { |
| 231 | - const uid = otherUserId().trim(); | ||
| 232 | - if (!uid) { | ||
| 233 | - setError(t("events.userIdRequired")); | ||
| 234 | - return; | ||
| 235 | - } | ||
| 236 | await postEventAttendance(id(), { | 236 | await postEventAttendance(id(), { |
| 237 | status: status(), | 237 | status: status(), |
| 238 | user_id: uid, | 238 | user_id: uid, |
| 239 | }); | 239 | }); |
| 240 | setOtherUserId(""); | 240 | setOtherUserId(""); |
| 241 | if (attendanceOpen()) await refetchAttendance(); | 241 | if (attendanceOpen()) await refetchAttendance(); |
| 242 | - }, t("common.saved")) | 242 | + }, t("common.saved")); |
| 243 | - } | 243 | + }} |
| 244 | > | 244 | > |
| 245 | {t("events.saveStudentAttendance")} | 245 | {t("events.saveStudentAttendance")} |
| 246 | </Button> | 246 | </Button> |