diff --git a/src/components/events/event-card.tsx b/src/components/events/event-card.tsx index cde639a..1f90093 100644 --- a/src/components/events/event-card.tsx +++ b/src/components/events/event-card.tsx @@ -1,7 +1,11 @@ +import { Show } from "solid-js"; import { Link } from "@tanstack/solid-router"; 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 { formatDateTime } from "@/lib/format"; +import { scheduleStatusClass, scheduleStatusDotClass, type ScheduleStatus } from "@/lib/schedule-status"; import { usePreferences, useT } from "@/stores/preferences-context"; function audienceLabel(audience: EventAudience, t: ReturnType): string { @@ -11,17 +15,39 @@ function audienceLabel(audience: EventAudience, t: ReturnType): str return t("events.audience.school"); } +function eventStatus(event: Event, now: number): ScheduleStatus { + if (event.starts_at == null) return "unscheduled"; + if (event.ends_at != null && event.ends_at < now) return "finished"; + if (event.starts_at > now) return "upcoming"; + return "active"; +} + export function EventCard(props: { event: Event }) { const t = useT(); const { locale } = usePreferences(); + const status = () => eventStatus(props.event, Date.now()); + const statusLabel = () => { + const s = status(); + if (s === "unscheduled") return t("exams.unscheduled"); + if (s === "finished") return t("events.past"); + if (s === "upcoming") return t("events.upcoming"); + return t("dashboard.activeNow"); + }; + return (
-

- {props.event.title} -

-

+

+

+ {props.event.title} +

+ + + {statusLabel()} + +
+

{props.event.description || "—"}

{audienceLabel(props.event.audience, t)}

@@ -32,10 +58,12 @@ export function EventCard(props: { event: Event }) {
{t("events.starts")}
{formatDateTime(props.event.starts_at, locale())}
-
-
{t("events.ends")}
-
{formatDateTime(props.event.ends_at, locale())}
-
+ +
+
{t("events.ends")}
+
{formatDateTime(props.event.ends_at, locale())}
+
+
diff --git a/src/components/exams/exam-card.tsx b/src/components/exams/exam-card.tsx index 71357f0..ffd94b2 100644 --- a/src/components/exams/exam-card.tsx +++ b/src/components/exams/exam-card.tsx @@ -7,6 +7,7 @@ import { cn } from "@/lib/cn"; import { examKindLabel } from "@/lib/exam-labels"; import { examWeight } from "@/lib/exam-weight"; import { examDurationMs, formatDateTime, formatDurationMinutes } from "@/lib/format"; +import { scheduleStatusClass, scheduleStatusDotClass } from "@/lib/schedule-status"; import { usePreferences, useT } from "@/stores/preferences-context"; export function ExamCard(props: { exam: Exam; courseTitle?: string; now?: number }) { @@ -37,22 +38,6 @@ export function ExamCard(props: { exam: Exam; courseTitle?: string; now?: number return t("exams.active"); }; - const statusClass = () => { - const s = status(); - if (s === "unscheduled") return "bg-muted text-muted-foreground border-muted"; - if (s === "finished") return "bg-muted text-muted-foreground border-muted"; - if (s === "upcoming") return "bg-amber-500/15 text-amber-600 border-amber-500/30"; - return "bg-emerald-500/15 text-emerald-600 border-emerald-500/30"; - }; - - const statusDot = () => { - const s = status(); - if (s === "unscheduled") return "bg-muted-foreground"; - if (s === "finished") return "bg-muted-foreground"; - if (s === "upcoming") return "bg-amber-600"; - return "bg-emerald-600"; - }; - return (
@@ -66,8 +51,8 @@ export function ExamCard(props: { exam: Exam; courseTitle?: string; now?: number {props.exam.title} - - + + {statusLabel()} diff --git a/src/lib/schedule-status.ts b/src/lib/schedule-status.ts new file mode 100644 index 0000000..3b70764 --- /dev/null +++ b/src/lib/schedule-status.ts @@ -0,0 +1,25 @@ +/** Shared semantic colors for exam/event schedule chips (dashboard, lists, cards). */ +export type ScheduleStatus = + | "active" + | "upcoming" + | "today" + | "soon" + | "finished" + | "past" + | "unscheduled"; + +export function scheduleStatusClass(status: ScheduleStatus | string): string { + if (status === "active") { + return "border-emerald-500/30 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300"; + } + if (status === "today" || status === "upcoming" || status === "soon") { + return "border-amber-500/30 bg-amber-500/10 text-amber-700 dark:text-amber-300"; + } + return "border-muted bg-muted/50 text-muted-foreground"; +} + +export function scheduleStatusDotClass(status: ScheduleStatus | string): string { + if (status === "active") return "bg-emerald-600"; + if (status === "today" || status === "upcoming" || status === "soon") return "bg-amber-600"; + return "bg-muted-foreground"; +} diff --git a/src/pages/dashboard-page.tsx b/src/pages/dashboard-page.tsx index 97e89a5..ea5f243 100644 --- a/src/pages/dashboard-page.tsx +++ b/src/pages/dashboard-page.tsx @@ -28,6 +28,7 @@ import { cn } from "@/lib/cn"; import { examKindLabel } from "@/lib/exam-labels"; import { formatDateTime } from "@/lib/format"; import { hasMinRole } from "@/lib/roles"; +import { scheduleStatusClass, scheduleStatusDotClass } from "@/lib/schedule-status"; import { useAuth } from "@/stores/auth-context"; import { usePreferences, useT } from "@/stores/preferences-context"; @@ -478,12 +479,7 @@ function PortalCard(props: { card: PortalCardDef }) { function StatusDot(props: { status: AttentionKind }) { return (