From 1c125f7a394220acbef8abacb2f378c9ff185d34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Fri, 17 Jul 2026 20:35:26 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20flash=20and=20schedule=20?= =?UTF-8?q?status=20regressions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - prevent empty event attendance save from showing success - refresh repeated flash timers for same message text - make event cards and dashboard schedule status time-reactive --- src/components/events/event-card.tsx | 4 +++- src/lib/flash.ts | 11 ++++++++--- src/pages/dashboard-page.tsx | 5 +++-- src/pages/event-detail-page.tsx | 16 ++++++++-------- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/components/events/event-card.tsx b/src/components/events/event-card.tsx index 1f90093..fe405fe 100644 --- a/src/components/events/event-card.tsx +++ b/src/components/events/event-card.tsx @@ -4,6 +4,7 @@ import type { Event, EventAudience } from "@/api/types"; import type { MessageKey } from "@/i18n/messages"; import { Badge } from "@/components/ui/badge"; import { cn } from "@/lib/cn"; +import { createNow } from "@/lib/create-now"; import { formatDateTime } from "@/lib/format"; import { scheduleStatusClass, scheduleStatusDotClass, type ScheduleStatus } from "@/lib/schedule-status"; import { usePreferences, useT } from "@/stores/preferences-context"; @@ -25,7 +26,8 @@ function eventStatus(event: Event, now: number): ScheduleStatus { export function EventCard(props: { event: Event }) { const t = useT(); const { locale } = usePreferences(); - const status = () => eventStatus(props.event, Date.now()); + const now = createNow(); + const status = () => eventStatus(props.event, now()); const statusLabel = () => { const s = status(); if (s === "unscheduled") return t("exams.unscheduled"); diff --git a/src/lib/flash.ts b/src/lib/flash.ts index a979749..5e84486 100644 --- a/src/lib/flash.ts +++ b/src/lib/flash.ts @@ -1,13 +1,18 @@ -import { createEffect, createSignal, onCleanup, type Accessor, type Setter } from "solid-js"; +import { createEffect, createSignal, onCleanup, type Accessor } from "solid-js"; /** Short-lived success banner; auto-clears after `ms` (default 3s). */ -export function createFlash(ms = 3000): [Accessor, Setter] { +export function createFlash(ms = 3000): [Accessor, (text: string) => void] { const [message, setMessage] = createSignal(""); + const [tick, setTick] = createSignal(0); createEffect(() => { + tick(); const text = message(); if (!text) return; const id = window.setTimeout(() => setMessage(""), ms); onCleanup(() => window.clearTimeout(id)); }); - return [message, setMessage]; + return [message, (text) => { + setMessage(text); + setTick((value) => value + 1); + }]; } diff --git a/src/pages/dashboard-page.tsx b/src/pages/dashboard-page.tsx index ea5f243..cacbc6c 100644 --- a/src/pages/dashboard-page.tsx +++ b/src/pages/dashboard-page.tsx @@ -25,6 +25,7 @@ import { import { PageSpinner } from "@/components/ui/page-spinner"; import type { MessageKey } from "@/i18n/messages"; import { cn } from "@/lib/cn"; +import { createNow } from "@/lib/create-now"; import { examKindLabel } from "@/lib/exam-labels"; import { formatDateTime } from "@/lib/format"; import { hasMinRole } from "@/lib/roles"; @@ -104,7 +105,7 @@ function DashboardContent() { const { locale } = usePreferences(); const user = () => auth.user()!; const role = () => user().role; - const now = () => Date.now(); + const now = createNow(); const [courses] = createResource( () => (role() !== "student" ? true : null), @@ -318,7 +319,7 @@ function DashboardContent() { {t(ROLE_KEY[role()])} - {formatDateTime(Date.now(), locale()).split(",")[0]} + {formatDateTime(now(), locale()).split(",")[0]} diff --git a/src/pages/event-detail-page.tsx b/src/pages/event-detail-page.tsx index d1fa064..5c336f4 100644 --- a/src/pages/event-detail-page.tsx +++ b/src/pages/event-detail-page.tsx @@ -226,21 +226,21 @@ function EventDetailContent() { type="button" class="w-full rounded-sm sm:w-auto" disabled={pending()} - onClick={() => + onClick={() => { + const uid = otherUserId().trim(); + if (!uid) { + setError(t("events.userIdRequired")); + return; + } void wrap(async () => { - const uid = otherUserId().trim(); - if (!uid) { - setError(t("events.userIdRequired")); - return; - } await postEventAttendance(id(), { status: status(), user_id: uid, }); setOtherUserId(""); if (attendanceOpen()) await refetchAttendance(); - }, t("common.saved")) - } + }, t("common.saved")); + }} > {t("events.saveStudentAttendance")}