🧹 remove unused domain components
Browse files at this commitc41c4bcfd44bf387eb5c647a323460d58981e317Parent: 15cde33- chore
- 🧹 remove unused domain components
6 changed files +0 -762
- src/components/events/event-card.tsx +0 -74
- src/components/exams/exam-card.tsx +0 -94
- src/components/exams/student-exam-room.tsx +0 -361
- src/components/messages/message-item-card.tsx +0 -127
- src/components/messages/quick-reply-bar.tsx +0 -80
- src/components/users/user-role-select.tsx +0 -26
src/components/events/event-card.tsxdeleted+0 -74
| @@ -1,74 +0,0 @@ | |||
| 1 | -import { Show } from "solid-js"; | ||
| 2 | -import { Link } from "@tanstack/solid-router"; | ||
| 3 | -import type { Event, EventAudience } from "@/api/client"; | ||
| 4 | -import type { MessageKey } from "@/i18n/messages"; | ||
| 5 | -import { Badge } from "@/components/ui/badge"; | ||
| 6 | -import { cn } from "@/lib/cn"; | ||
| 7 | -import { createNow } from "@/lib/create-now"; | ||
| 8 | -import { formatDateTime } from "@/lib/format"; | ||
| 9 | -import { scheduleStatusClass, scheduleStatusDotClass, type ScheduleStatus } from "@/lib/schedule-status"; | ||
| 10 | -import { usePreferences, useT } from "@/stores/preferences-context"; | ||
| 11 | - | ||
| 12 | -function audienceLabel(audience: EventAudience, t: ReturnType<typeof useT>): string { | ||
| 13 | - if (audience.kind === "role") return `${t("events.audience.role")}: ${t(`role.${audience.role}` as MessageKey)}`; | ||
| 14 | - if (audience.kind === "course") return t("events.audience.course"); | ||
| 15 | - if (audience.kind === "registration") return t("events.audience.registration"); | ||
| 16 | - return t("events.audience.school"); | ||
| 17 | -} | ||
| 18 | - | ||
| 19 | -function eventStatus(event: Event, now: number): ScheduleStatus { | ||
| 20 | - if (event.starts_at == null) return "unscheduled"; | ||
| 21 | - if (event.ends_at != null && event.ends_at < now) return "finished"; | ||
| 22 | - if (event.starts_at > now) return "upcoming"; | ||
| 23 | - return "active"; | ||
| 24 | -} | ||
| 25 | - | ||
| 26 | -export function EventCard(props: { event: Event }) { | ||
| 27 | - const t = useT(); | ||
| 28 | - const { locale } = usePreferences(); | ||
| 29 | - const now = createNow(); | ||
| 30 | - const status = () => eventStatus(props.event, now()); | ||
| 31 | - const statusLabel = () => { | ||
| 32 | - const s = status(); | ||
| 33 | - if (s === "unscheduled") return t("exams.unscheduled"); | ||
| 34 | - if (s === "finished") return t("events.past"); | ||
| 35 | - if (s === "upcoming") return t("events.upcoming"); | ||
| 36 | - return t("dashboard.activeNow"); | ||
| 37 | - }; | ||
| 38 | - | ||
| 39 | - return ( | ||
| 40 | - <Link to="/events/$id" params={{ id: props.event.id }} class="group block h-full"> | ||
| 41 | - <article class="data-shell flex h-full min-h-40 flex-col overflow-hidden card-lift group-hover:border-primary/35"> | ||
| 42 | - <div class="flex flex-1 flex-col p-3"> | ||
| 43 | - <div class="mb-2 flex items-start justify-between gap-2"> | ||
| 44 | - <h3 class="line-clamp-2 min-w-0 flex-1 font-display text-base font-semibold leading-snug group-hover:text-primary"> | ||
| 45 | - {props.event.title} | ||
| 46 | - </h3> | ||
| 47 | - <Badge variant="outline" class={cn("shrink-0 rounded-sm capitalize", scheduleStatusClass(status()))}> | ||
| 48 | - <span class={cn("mr-1.5 inline-block h-1.5 w-1.5 rounded-full", scheduleStatusDotClass(status()))} /> | ||
| 49 | - {statusLabel()} | ||
| 50 | - </Badge> | ||
| 51 | - </div> | ||
| 52 | - <p class="line-clamp-3 flex-1 text-[13px] leading-relaxed text-muted-foreground"> | ||
| 53 | - {props.event.description || "—"} | ||
| 54 | - </p> | ||
| 55 | - <p class="mt-3 text-xs font-medium text-muted-foreground">{audienceLabel(props.event.audience, t)}</p> | ||
| 56 | - </div> | ||
| 57 | - <div class="border-t border-border bg-muted/25 px-3 py-3"> | ||
| 58 | - <dl class="grid gap-2 text-xs text-muted-foreground"> | ||
| 59 | - <div> | ||
| 60 | - <dt class="font-medium uppercase tracking-[0.08em] text-muted-foreground">{t("events.starts")}</dt> | ||
| 61 | - <dd class="mono mt-1 text-foreground">{formatDateTime(props.event.starts_at, locale())}</dd> | ||
| 62 | - </div> | ||
| 63 | - <Show when={props.event.ends_at != null}> | ||
| 64 | - <div> | ||
| 65 | - <dt class="font-medium uppercase tracking-[0.08em] text-muted-foreground">{t("events.ends")}</dt> | ||
| 66 | - <dd class="mono mt-1 text-foreground">{formatDateTime(props.event.ends_at, locale())}</dd> | ||
| 67 | - </div> | ||
| 68 | - </Show> | ||
| 69 | - </dl> | ||
| 70 | - </div> | ||
| 71 | - </article> | ||
| 72 | - </Link> | ||
| 73 | - ); | ||
| 74 | -} | ||
src/components/exams/exam-card.tsxdeleted+0 -94
| @@ -1,94 +0,0 @@ | |||
| 1 | -import { Show, createResource } from "solid-js"; | ||
| 2 | -import { getSettings } from "@/api/settings"; | ||
| 3 | -import type { Exam } from "@/api/client"; | ||
| 4 | -import { Badge } from "@/components/ui/badge"; | ||
| 5 | -import { ExamLink } from "@/components/exams/exam-link"; | ||
| 6 | -import { cn } from "@/lib/cn"; | ||
| 7 | -import { examKindLabel } from "@/lib/exam-labels"; | ||
| 8 | -import { examDisplayStatus, examStatusMessageKey, examStatusTone } from "@/lib/exam-status"; | ||
| 9 | -import { examWeight } from "@/lib/exam-weight"; | ||
| 10 | -import { examDurationMs, formatDateTime, formatDurationMinutes } from "@/lib/format"; | ||
| 11 | -import { scheduleStatusClass, scheduleStatusDotClass } from "@/lib/schedule-status"; | ||
| 12 | -import { usePreferences, useT } from "@/stores/preferences-context"; | ||
| 13 | - | ||
| 14 | -export function ExamCard(props: { exam: Exam; courseTitle?: string; now?: number }) { | ||
| 15 | - const t = useT(); | ||
| 16 | - const { locale } = usePreferences(); | ||
| 17 | - const [settings] = createResource(() => getSettings()); | ||
| 18 | - const modeLabel = () => { | ||
| 19 | - if (props.exam.mode === "sync") return t("exams.mode.sync"); | ||
| 20 | - if (props.exam.mode === "async") return t("exams.mode.async"); | ||
| 21 | - if (props.exam.mode === "open") return t("exams.mode.open"); | ||
| 22 | - return t("exams.unscheduled"); | ||
| 23 | - }; | ||
| 24 | - | ||
| 25 | - const status = () => { | ||
| 26 | - return examDisplayStatus(props.exam, props.now ?? Date.now()); | ||
| 27 | - }; | ||
| 28 | - | ||
| 29 | - const statusLabel = () => { | ||
| 30 | - return t(examStatusMessageKey(status())); | ||
| 31 | - }; | ||
| 32 | - | ||
| 33 | - return ( | ||
| 34 | - <ExamLink examId={props.exam.id} class="group block h-full"> | ||
| 35 | - <article class="data-shell flex h-full min-h-48 flex-col overflow-hidden transition-colors group-hover:border-primary/35"> | ||
| 36 | - <div class="flex flex-1 flex-col p-3"> | ||
| 37 | - <div class="mb-3 flex items-start justify-between gap-3"> | ||
| 38 | - <div class="min-w-0 flex-1 space-y-1"> | ||
| 39 | - <Show when={props.courseTitle}> | ||
| 40 | - <p class="truncate text-xs font-medium text-muted-foreground">{props.courseTitle}</p> | ||
| 41 | - </Show> | ||
| 42 | - <h3 class="line-clamp-2 font-display text-base font-semibold leading-snug group-hover:text-primary"> | ||
| 43 | - {props.exam.title} | ||
| 44 | - </h3> | ||
| 45 | - </div> | ||
| 46 | - <Badge variant="outline" class={cn("shrink-0 rounded-sm capitalize", scheduleStatusClass(examStatusTone(status())))}> | ||
| 47 | - <span class={cn("mr-1.5 inline-block h-1.5 w-1.5 rounded-full", scheduleStatusDotClass(examStatusTone(status())))} /> | ||
| 48 | - {statusLabel()} | ||
| 49 | - </Badge> | ||
| 50 | - </div> | ||
| 51 | - | ||
| 52 | - <p class="line-clamp-2 min-h-10 text-[13px] leading-relaxed text-muted-foreground"> | ||
| 53 | - {props.exam.description || "—"} | ||
| 54 | - </p> | ||
| 55 | - | ||
| 56 | - <div class="mt-4 flex flex-wrap gap-2"> | ||
| 57 | - <Badge variant="outline" class="rounded-sm capitalize"> | ||
| 58 | - {examKindLabel(String(props.exam.kind), t)} | ||
| 59 | - <Show when={examWeight(props.exam, settings()?.exam_kinds) != null}> | ||
| 60 | - {(weight) => <span class="ml-1 text-muted-foreground">({t("courses.weight")}: {weight()})</span>} | ||
| 61 | - </Show> | ||
| 62 | - </Badge> | ||
| 63 | - <Badge variant="outline" class="rounded-sm"> | ||
| 64 | - {modeLabel()} | ||
| 65 | - </Badge> | ||
| 66 | - </div> | ||
| 67 | - </div> | ||
| 68 | - | ||
| 69 | - <div class="border-t border-border bg-muted/25 px-3 py-3"> | ||
| 70 | - <dl class="grid gap-2 text-xs text-muted-foreground"> | ||
| 71 | - <Show when={props.exam.starts_at != null && props.exam.ends_at != null}> | ||
| 72 | - <div class="grid gap-1 sm:grid-cols-2"> | ||
| 73 | - <div> | ||
| 74 | - <dt class="font-medium uppercase tracking-[0.08em] text-muted-foreground">{t("events.starts")}</dt> | ||
| 75 | - <dd class="mono mt-1 text-foreground">{formatDateTime(props.exam.starts_at, locale())}</dd> | ||
| 76 | - </div> | ||
| 77 | - <div> | ||
| 78 | - <dt class="font-medium uppercase tracking-[0.08em] text-muted-foreground">{t("events.ends")}</dt> | ||
| 79 | - <dd class="mono mt-1 text-foreground">{formatDateTime(props.exam.ends_at, locale())}</dd> | ||
| 80 | - </div> | ||
| 81 | - </div> | ||
| 82 | - </Show> | ||
| 83 | - <div class="flex items-center justify-between gap-3"> | ||
| 84 | - <dt>{t("exams.durationMinutes")}</dt> | ||
| 85 | - <dd class="mono font-medium text-foreground"> | ||
| 86 | - {formatDurationMinutes(examDurationMs(props.exam.duration_ms, props.exam.starts_at, props.exam.ends_at), locale())} | ||
| 87 | - </dd> | ||
| 88 | - </div> | ||
| 89 | - </dl> | ||
| 90 | - </div> | ||
| 91 | - </article> | ||
| 92 | - </ExamLink> | ||
| 93 | - ); | ||
| 94 | -} | ||
src/components/exams/student-exam-room.tsxdeleted+0 -361
| @@ -1,361 +0,0 @@ | |||
| 1 | -import { For, Show, Suspense, createEffect, createMemo, createResource, createSignal, onCleanup } from "solid-js"; | ||
| 2 | -import { getExamAttempt } from "@/api/exams"; | ||
| 3 | -import { getExamAttemptQuestions } from "@/api/exams"; | ||
| 4 | -import { postExamAttempt } from "@/api/exams"; | ||
| 5 | -import { postExamAttemptAnswer } from "@/api/exams"; | ||
| 6 | -import { postExamAttemptFinish } from "@/api/exams"; | ||
| 7 | -import { ApiError, formatApiError } from "@/api/client"; | ||
| 8 | -import type { AttemptQuestion, Exam, ExamAttempt } from "@/api/client"; | ||
| 9 | -import { Badge } from "@/components/ui/badge"; | ||
| 10 | -import { Button } from "@/components/ui/button"; | ||
| 11 | -import { ConfirmDialog } from "@/components/ui/confirm-dialog"; | ||
| 12 | -import { PageSpinner } from "@/components/ui/page-spinner"; | ||
| 13 | -import { Textarea } from "@/components/ui/textarea"; | ||
| 14 | -import { formatDateTime } from "@/lib/format"; | ||
| 15 | -import { usePreferences, useT } from "@/stores/preferences-context"; | ||
| 16 | - | ||
| 17 | -function formatRemaining(ms: number | null): string { | ||
| 18 | - if (ms == null) return "—"; | ||
| 19 | - const safe = Math.max(0, ms); | ||
| 20 | - const totalSeconds = Math.floor(safe / 1000); | ||
| 21 | - const hours = Math.floor(totalSeconds / 3600); | ||
| 22 | - const minutes = Math.floor((totalSeconds % 3600) / 60); | ||
| 23 | - const seconds = totalSeconds % 60; | ||
| 24 | - return `${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`; | ||
| 25 | -} | ||
| 26 | - | ||
| 27 | -export function StudentExamRoom(props: { exam: Exam; compact?: boolean }) { | ||
| 28 | - const t = useT(); | ||
| 29 | - const [attempt, { refetch: refetchAttempt, mutate: setAttempt }] = createResource( | ||
| 30 | - () => props.exam.id, | ||
| 31 | - async (examId) => { | ||
| 32 | - try { | ||
| 33 | - return await getExamAttempt(examId); | ||
| 34 | - } catch (err) { | ||
| 35 | - if (err instanceof ApiError && (err.status === 404 || err.status === 409)) return null; | ||
| 36 | - throw err; | ||
| 37 | - } | ||
| 38 | - }, | ||
| 39 | - ); | ||
| 40 | - const [questions, { refetch: refetchQuestions }] = createResource( | ||
| 41 | - () => (attempt() ? props.exam.id : null), | ||
| 42 | - async (examId) => { | ||
| 43 | - if (!examId) return []; | ||
| 44 | - return getExamAttemptQuestions(examId); | ||
| 45 | - }, | ||
| 46 | - ); | ||
| 47 | - const [error, setError] = createSignal(""); | ||
| 48 | - const [pending, setPending] = createSignal(false); | ||
| 49 | - const [finishOpen, setFinishOpen] = createSignal(false); | ||
| 50 | - const [remainingMs, setRemainingMs] = createSignal<number | null>(0); | ||
| 51 | - const [roomOpen, setRoomOpen] = createSignal(false); | ||
| 52 | - const scheduled = createMemo(() => props.exam.mode === "sync" || props.exam.mode === "async" || props.exam.mode === "open"); | ||
| 53 | - const canWrite = createMemo(() => attempt()?.status === "in_progress" && (remainingMs() == null || remainingMs()! > 0)); | ||
| 54 | - | ||
| 55 | - createEffect(() => { | ||
| 56 | - const current = attempt(); | ||
| 57 | - const remaining = current?.remaining_ms ?? null; | ||
| 58 | - setRemainingMs(remaining); | ||
| 59 | - if (!current || current.status !== "in_progress" || remaining == null || remaining <= 0) return; | ||
| 60 | - const startedAt = Date.now(); | ||
| 61 | - const initial = remaining; | ||
| 62 | - const timer = window.setInterval(() => { | ||
| 63 | - setRemainingMs(Math.max(0, initial - (Date.now() - startedAt))); | ||
| 64 | - }, 1000); | ||
| 65 | - onCleanup(() => window.clearInterval(timer)); | ||
| 66 | - }); | ||
| 67 | - | ||
| 68 | - const start = async () => { | ||
| 69 | - setError(""); | ||
| 70 | - setPending(true); | ||
| 71 | - try { | ||
| 72 | - const next = await postExamAttempt(props.exam.id); | ||
| 73 | - setAttempt(next); | ||
| 74 | - setRoomOpen(true); | ||
| 75 | - await refetchQuestions(); | ||
| 76 | - } catch (err) { | ||
| 77 | - setError(formatApiError(err)); | ||
| 78 | - } finally { | ||
| 79 | - setPending(false); | ||
| 80 | - } | ||
| 81 | - }; | ||
| 82 | - | ||
| 83 | - const saveAnswer = async (question: AttemptQuestion, value: string) => { | ||
| 84 | - setError(""); | ||
| 85 | - setPending(true); | ||
| 86 | - try { | ||
| 87 | - if (question.kind === "choice") { | ||
| 88 | - await postExamAttemptAnswer(props.exam.id, { question_id: question.id, selected: Number(value) }); | ||
| 89 | - } else { | ||
| 90 | - await postExamAttemptAnswer(props.exam.id, { question_id: question.id, text: value }); | ||
| 91 | - } | ||
| 92 | - await refetchAttempt(); | ||
| 93 | - await refetchQuestions(); | ||
| 94 | - } catch (err) { | ||
| 95 | - setError(formatApiError(err)); | ||
| 96 | - } finally { | ||
| 97 | - setPending(false); | ||
| 98 | - } | ||
| 99 | - }; | ||
| 100 | - | ||
| 101 | - const finish = async () => { | ||
| 102 | - setError(""); | ||
| 103 | - setPending(true); | ||
| 104 | - try { | ||
| 105 | - const next = await postExamAttemptFinish(props.exam.id); | ||
| 106 | - setAttempt(next); | ||
| 107 | - await refetchQuestions(); | ||
| 108 | - } catch (err) { | ||
| 109 | - setError(formatApiError(err)); | ||
| 110 | - } finally { | ||
| 111 | - setPending(false); | ||
| 112 | - } | ||
| 113 | - }; | ||
| 114 | - | ||
| 115 | - return ( | ||
| 116 | - <section class={props.compact ? "space-y-5" : "surface-card space-y-4 p-5"}> | ||
| 117 | - <Show when={!roomOpen()}> | ||
| 118 | - <div class="surface-card flex flex-wrap items-center justify-between gap-3 p-5"> | ||
| 119 | - <div> | ||
| 120 | - <h2 class="font-display text-lg font-semibold">{t("attempt.title")}</h2> | ||
| 121 | - <p class="mt-1 text-sm text-muted-foreground"> | ||
| 122 | - {props.exam.mode === "sync" ? t("exams.mode.sync") : props.exam.mode === "async" ? t("exams.mode.async") : props.exam.mode === "open" ? t("exams.mode.open") : t("attempt.unscheduled")} | ||
| 123 | - </p> | ||
| 124 | - </div> | ||
| 125 | - <Show when={scheduled()} fallback={<Badge variant="outline">{t("attempt.unscheduled")}</Badge>}> | ||
| 126 | - <Show | ||
| 127 | - when={attempt()} | ||
| 128 | - fallback={ | ||
| 129 | - <Button type="button" disabled={pending()} onClick={() => void start()}> | ||
| 130 | - {t("attempt.start")} | ||
| 131 | - </Button> | ||
| 132 | - } | ||
| 133 | - > | ||
| 134 | - <Button type="button" variant="outline" disabled={pending()} onClick={() => setRoomOpen(true)}> | ||
| 135 | - {t("attempt.resume")} | ||
| 136 | - </Button> | ||
| 137 | - </Show> | ||
| 138 | - </Show> | ||
| 139 | - </div> | ||
| 140 | - </Show> | ||
| 141 | - | ||
| 142 | - {error() && <p class="rounded-sm bg-destructive/10 px-3 py-2 text-sm text-destructive">{error()}</p>} | ||
| 143 | - | ||
| 144 | - <Suspense fallback={<PageSpinner />}> | ||
| 145 | - <Show when={scheduled()}> | ||
| 146 | - <Show when={attempt()} fallback={<p class="rounded-sm bg-muted/40 px-3 py-4 text-sm text-muted-foreground">{t("attempt.notStarted")}</p>}> | ||
| 147 | - {(a) => <AttemptSummary attempt={a()} remainingMs={remainingMs()} />} | ||
| 148 | - </Show> | ||
| 149 | - </Show> | ||
| 150 | - | ||
| 151 | - <Show when={attempt() && roomOpen()}> | ||
| 152 | - <Show when={!canWrite()}> | ||
| 153 | - <p class="rounded-sm bg-muted/40 px-3 py-3 text-sm text-muted-foreground">{t("attempt.closed")}</p> | ||
| 154 | - </Show> | ||
| 155 | - <div class="grid items-start gap-4 lg:grid-cols-[minmax(0,1fr)_12rem] xl:grid-cols-[minmax(0,1fr)_13rem] 2xl:grid-cols-[minmax(0,1fr)_14rem]"> | ||
| 156 | - <div class="grid auto-rows-fr items-stretch gap-4 2xl:grid-cols-2"> | ||
| 157 | - <For each={questions() ?? []}> | ||
| 158 | - {(question, index) => ( | ||
| 159 | - <QuestionAnswerCard | ||
| 160 | - index={index() + 1} | ||
| 161 | - nextQuestionId={(questions() ?? [])[index() + 1]?.id} | ||
| 162 | - question={question} | ||
| 163 | - disabled={!canWrite() || pending()} | ||
| 164 | - onSave={(value) => saveAnswer(question, value)} | ||
| 165 | - /> | ||
| 166 | - )} | ||
| 167 | - </For> | ||
| 168 | - </div> | ||
| 169 | - <aside class="surface-card sticky top-4 space-y-3 p-4"> | ||
| 170 | - <h3 class="font-display text-sm font-semibold">{t("questions.title")}</h3> | ||
| 171 | - <div class="grid grid-cols-4 gap-2"> | ||
| 172 | - <For each={questions() ?? []}> | ||
| 173 | - {(question, index) => ( | ||
| 174 | - <a | ||
| 175 | - href={`#question-${question.id}`} | ||
| 176 | - class="inline-flex h-9 items-center justify-center rounded-sm border bg-background text-sm font-medium hover:bg-accent" | ||
| 177 | - > | ||
| 178 | - {index() + 1} | ||
| 179 | - </a> | ||
| 180 | - )} | ||
| 181 | - </For> | ||
| 182 | - </div> | ||
| 183 | - <Show when={canWrite()}> | ||
| 184 | - <Button type="button" variant="destructive" class="w-full" disabled={pending()} onClick={() => setFinishOpen(true)}> | ||
| 185 | - {t("attempt.finish")} | ||
| 186 | - </Button> | ||
| 187 | - </Show> | ||
| 188 | - </aside> | ||
| 189 | - </div> | ||
| 190 | - </Show> | ||
| 191 | - </Suspense> | ||
| 192 | - | ||
| 193 | - <ConfirmDialog | ||
| 194 | - open={finishOpen()} | ||
| 195 | - onOpenChange={setFinishOpen} | ||
| 196 | - title={t("attempt.finish")} | ||
| 197 | - summary={props.exam.title} | ||
| 198 | - onConfirm={finish} | ||
| 199 | - /> | ||
| 200 | - </section> | ||
| 201 | - ); | ||
| 202 | -} | ||
| 203 | - | ||
| 204 | -function AttemptSummary(props: { attempt: ExamAttempt; remainingMs: number | null }) { | ||
| 205 | - const t = useT(); | ||
| 206 | - const { locale } = usePreferences(); | ||
| 207 | - const statusLabel = () => { | ||
| 208 | - if (props.attempt.status === "in_progress") return t("attempt.inProgress"); | ||
| 209 | - if (props.attempt.status === "submitted") return t("attempt.submitted"); | ||
| 210 | - if (props.attempt.status === "expired") return t("attempt.expired"); | ||
| 211 | - return props.attempt.status; | ||
| 212 | - }; | ||
| 213 | - return ( | ||
| 214 | - <div class="grid auto-rows-fr gap-3 text-sm sm:grid-cols-2 xl:grid-cols-5"> | ||
| 215 | - <div class="h-full rounded-md border bg-background/60 p-3"> | ||
| 216 | - <p class="text-xs text-muted-foreground">{t("attempt.status")}</p> | ||
| 217 | - <p class="mt-1 font-medium">{statusLabel()}</p> | ||
| 218 | - </div> | ||
| 219 | - <div class="h-full rounded-md border bg-background/60 p-3"> | ||
| 220 | - <p class="text-xs text-muted-foreground">{t("attempt.remaining")}</p> | ||
| 221 | - <p class="mt-1 font-mono font-medium">{formatRemaining(props.remainingMs)}</p> | ||
| 222 | - </div> | ||
| 223 | - <div class="h-full rounded-md border bg-background/60 p-3"> | ||
| 224 | - <p class="text-xs text-muted-foreground">{t("attempt.progress")}</p> | ||
| 225 | - <p class="mt-1 font-medium">{props.attempt.answered} / {props.attempt.question_count}</p> | ||
| 226 | - </div> | ||
| 227 | - <div class="h-full rounded-md border bg-background/60 p-3"> | ||
| 228 | - <p class="text-xs text-muted-foreground">{t("attempt.deadline")}</p> | ||
| 229 | - <p class="mt-1 font-medium">{formatDateTime(props.attempt.deadline, locale())}</p> | ||
| 230 | - </div> | ||
| 231 | - <div class="h-full rounded-md border bg-background/60 p-3"> | ||
| 232 | - <p class="text-xs text-muted-foreground">{t("attempt.serverNow")}</p> | ||
| 233 | - <p class="mt-1 font-medium">{formatDateTime(props.attempt.now, locale())}</p> | ||
| 234 | - </div> | ||
| 235 | - <Show when={props.attempt.mark != null}> | ||
| 236 | - <div class="h-full rounded-md border bg-background/60 p-3"> | ||
| 237 | - <p class="text-xs text-muted-foreground">{t("attempt.mark")}</p> | ||
| 238 | - <p class="mt-1 font-medium">{props.attempt.mark}</p> | ||
| 239 | - </div> | ||
| 240 | - </Show> | ||
| 241 | - </div> | ||
| 242 | - ); | ||
| 243 | -} | ||
| 244 | - | ||
| 245 | -function QuestionAnswerCard(props: { | ||
| 246 | - index: number; | ||
| 247 | - nextQuestionId?: string; | ||
| 248 | - question: AttemptQuestion; | ||
| 249 | - disabled: boolean; | ||
| 250 | - onSave: (value: string) => Promise<void>; | ||
| 251 | -}) { | ||
| 252 | - const t = useT(); | ||
| 253 | - const { locale } = usePreferences(); | ||
| 254 | - const [value, setValue] = createSignal( | ||
| 255 | - props.question.kind === "choice" | ||
| 256 | - ? props.question.answer?.selected != null | ||
| 257 | - ? String(props.question.answer.selected) | ||
| 258 | - : "" | ||
| 259 | - : props.question.answer?.text ?? "", | ||
| 260 | - ); | ||
| 261 | - const [saved, setSaved] = createSignal(false); | ||
| 262 | - let questionId = props.question.id; | ||
| 263 | - | ||
| 264 | - createEffect(() => { | ||
| 265 | - if (props.question.id === questionId) return; | ||
| 266 | - questionId = props.question.id; | ||
| 267 | - setValue( | ||
| 268 | - props.question.kind === "choice" | ||
| 269 | - ? props.question.answer?.selected != null | ||
| 270 | - ? String(props.question.answer.selected) | ||
| 271 | - : "" | ||
| 272 | - : props.question.answer?.text ?? "", | ||
| 273 | - ); | ||
| 274 | - setSaved(false); | ||
| 275 | - }); | ||
| 276 | - | ||
| 277 | - const save = async () => { | ||
| 278 | - await props.onSave(value()); | ||
| 279 | - setSaved(true); | ||
| 280 | - if (props.nextQuestionId) { | ||
| 281 | - document.getElementById(`question-${props.nextQuestionId}`)?.scrollIntoView({ behavior: "smooth", block: "start" }); | ||
| 282 | - } | ||
| 283 | - }; | ||
| 284 | - | ||
| 285 | - return ( | ||
| 286 | - <article id={`question-${props.question.id}`} class="surface-card min-h-[18rem] scroll-mt-24 p-5"> | ||
| 287 | - <div class="mb-3 flex flex-wrap items-center gap-2"> | ||
| 288 | - <span class="text-xs font-semibold text-muted-foreground">#{props.index}</span> | ||
| 289 | - <Badge variant="outline">{props.question.points} {t("questions.points")}</Badge> | ||
| 290 | - <Show when={saved()}> | ||
| 291 | - <Badge variant="outline">{t("attempt.saved")}</Badge> | ||
| 292 | - </Show> | ||
| 293 | - <Show when={props.question.answer?.updated_at}> | ||
| 294 | - {(updatedAt) => <Badge variant="outline">{t("attempt.savedAt")}: {formatDateTime(updatedAt(), locale())}</Badge>} | ||
| 295 | - </Show> | ||
| 296 | - </div> | ||
| 297 | - <Show when={props.question.image}> | ||
| 298 | - <img | ||
| 299 | - src={`/api/exams/${props.question.exam}/questions/${props.question.id}/image`} | ||
| 300 | - alt={t("questions.image")} | ||
| 301 | - class="mb-4 h-64 w-full max-w-2xl rounded-md border bg-muted/20 object-contain" | ||
| 302 | - /> | ||
| 303 | - </Show> | ||
| 304 | - <p class="mb-4 whitespace-pre-wrap text-sm font-medium">{props.question.text}</p> | ||
| 305 | - <Show | ||
| 306 | - when={props.question.kind === "choice"} | ||
| 307 | - fallback={ | ||
| 308 | - <Textarea | ||
| 309 | - value={value()} | ||
| 310 | - rows={4} | ||
| 311 | - disabled={props.disabled} | ||
| 312 | - maxlength={10000} | ||
| 313 | - onInput={(e) => { | ||
| 314 | - setSaved(false); | ||
| 315 | - setValue(e.currentTarget.value); | ||
| 316 | - }} | ||
| 317 | - /> | ||
| 318 | - } | ||
| 319 | - > | ||
| 320 | - <div class="space-y-2"> | ||
| 321 | - <For each={props.question.choices ?? []}> | ||
| 322 | - {(choice, choiceIndex) => ( | ||
| 323 | - <button | ||
| 324 | - type="button" | ||
| 325 | - class="flex w-full items-center gap-3 rounded-sm border px-3 py-2 text-left text-sm transition-colors hover:bg-accent disabled:cursor-not-allowed disabled:opacity-60" | ||
| 326 | - disabled={props.disabled} | ||
| 327 | - onClick={() => { | ||
| 328 | - setSaved(false); | ||
| 329 | - setValue(String(choiceIndex())); | ||
| 330 | - }} | ||
| 331 | - > | ||
| 332 | - <span class={value() === String(choiceIndex()) ? "flex h-7 w-7 shrink-0 items-center justify-center rounded-md border border-primary bg-primary text-xs font-semibold text-primary-foreground" : "flex h-7 w-7 shrink-0 items-center justify-center rounded-md border border-input bg-background text-xs font-semibold text-foreground"}> | ||
| 333 | - {String.fromCharCode(65 + choiceIndex())} | ||
| 334 | - </span> | ||
| 335 | - <span class="min-w-0 space-y-2"> | ||
| 336 | - <span class="block whitespace-pre-wrap">{choice}</span> | ||
| 337 | - <Show when={props.question.choice_images?.[choiceIndex()]}> | ||
| 338 | - <img | ||
| 339 | - src={`/api/exams/${props.question.exam}/questions/${props.question.id}/choices/${choiceIndex()}/image`} | ||
| 340 | - alt={t("questions.choiceImage")} | ||
| 341 | - class="h-36 w-full max-w-md rounded-md border bg-muted/20 object-contain" | ||
| 342 | - /> | ||
| 343 | - </Show> | ||
| 344 | - </span> | ||
| 345 | - </button> | ||
| 346 | - )} | ||
| 347 | - </For> | ||
| 348 | - </div> | ||
| 349 | - </Show> | ||
| 350 | - <Button | ||
| 351 | - type="button" | ||
| 352 | - size="sm" | ||
| 353 | - class="mt-3" | ||
| 354 | - disabled={props.disabled || (props.question.kind === "choice" && value() === "")} | ||
| 355 | - onClick={() => void save()} | ||
| 356 | - > | ||
| 357 | - {t("attempt.saveAnswer")} | ||
| 358 | - </Button> | ||
| 359 | - </article> | ||
| 360 | - ); | ||
| 361 | -} | ||
src/components/messages/message-item-card.tsxdeleted+0 -127
| @@ -1,127 +0,0 @@ | |||
| 1 | -import { Show } from "solid-js"; | ||
| 2 | -import type { Message } from "@/api/client"; | ||
| 3 | -import { Badge } from "@/components/ui/badge"; | ||
| 4 | -import { cn } from "@/lib/cn"; | ||
| 5 | -import { personLabel } from "@/lib/person"; | ||
| 6 | -import { useT } from "@/stores/preferences-context"; | ||
| 7 | - | ||
| 8 | -interface MessageItemCardProps { | ||
| 9 | - message: Message; | ||
| 10 | - currentUserId?: string; | ||
| 11 | - folder: string; | ||
| 12 | - isSelected: boolean; | ||
| 13 | - onSelect: () => void; | ||
| 14 | -} | ||
| 15 | - | ||
| 16 | -export function MessageItemCard(props: MessageItemCardProps) { | ||
| 17 | - const t = useT(); | ||
| 18 | - | ||
| 19 | - const isSent = () => props.folder === "sent" || props.message.sender.id === props.currentUserId; | ||
| 20 | - const peer = () => (isSent() ? props.message.recipient : props.message.sender); | ||
| 21 | - const peerName = () => personLabel(peer()); | ||
| 22 | - const role = () => (isSent() ? props.message.recipient_role : props.message.sender_role); | ||
| 23 | - const unread = () => !isSent() && !props.message.read; | ||
| 24 | - | ||
| 25 | - const initial = () => { | ||
| 26 | - const name = peerName().trim(); | ||
| 27 | - return name.charAt(0).toUpperCase() || "?"; | ||
| 28 | - }; | ||
| 29 | - | ||
| 30 | - const formattedTime = (ts: number) => { | ||
| 31 | - const date = new Date(ts); | ||
| 32 | - const now = new Date(); | ||
| 33 | - const isToday = | ||
| 34 | - date.getDate() === now.getDate() && | ||
| 35 | - date.getMonth() === now.getMonth() && | ||
| 36 | - date.getFullYear() === now.getFullYear(); | ||
| 37 | - | ||
| 38 | - if (isToday) { | ||
| 39 | - return date.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }); | ||
| 40 | - } | ||
| 41 | - return date.toLocaleDateString([], { month: "short", day: "numeric" }); | ||
| 42 | - }; | ||
| 43 | - | ||
| 44 | - return ( | ||
| 45 | - <button | ||
| 46 | - type="button" | ||
| 47 | - class={cn( | ||
| 48 | - "group relative flex w-full items-start gap-3 rounded-xl border p-3 text-left transition-colors duration-150", | ||
| 49 | - props.isSelected | ||
| 50 | - ? "border-primary/50 bg-accent/60 shadow-xs ring-1 ring-primary/20" | ||
| 51 | - : unread() | ||
| 52 | - ? "border-primary/30 bg-primary/[0.03] hover:border-primary/40 hover:bg-accent/40" | ||
| 53 | - : "border-border/60 bg-card hover:border-border hover:bg-muted/40" | ||
| 54 | - )} | ||
| 55 | - onClick={props.onSelect} | ||
| 56 | - > | ||
| 57 | - {/* Avatar */} | ||
| 58 | - <div class="relative shrink-0"> | ||
| 59 | - <div | ||
| 60 | - class={cn( | ||
| 61 | - "flex h-10 w-10 items-center justify-center rounded-full font-bold text-xs shadow-xs", | ||
| 62 | - unread() | ||
| 63 | - ? "bg-primary text-primary-foreground font-extrabold" | ||
| 64 | - : "bg-muted text-muted-foreground border border-border" | ||
| 65 | - )} | ||
| 66 | - > | ||
| 67 | - {initial()} | ||
| 68 | - </div> | ||
| 69 | - <Show when={unread()}> | ||
| 70 | - <span class="absolute -top-0.5 -right-0.5 h-3 w-3 rounded-full bg-primary ring-2 ring-background" /> | ||
| 71 | - </Show> | ||
| 72 | - </div> | ||
| 73 | - | ||
| 74 | - {/* Message Info */} | ||
| 75 | - <div class="min-w-0 flex-1 space-y-1"> | ||
| 76 | - <div class="flex items-center justify-between gap-2"> | ||
| 77 | - <div class="flex items-center gap-1.5 min-w-0"> | ||
| 78 | - <span | ||
| 79 | - class={cn( | ||
| 80 | - "truncate text-xs font-semibold tracking-tight", | ||
| 81 | - unread() ? "text-foreground font-bold" : "text-foreground/90" | ||
| 82 | - )} | ||
| 83 | - > | ||
| 84 | - {peerName()} | ||
| 85 | - </span> | ||
| 86 | - <Show when={role()}> | ||
| 87 | - <span class="shrink-0 text-[9px] uppercase font-mono px-1 py-0.2 rounded bg-muted text-muted-foreground border border-border/50"> | ||
| 88 | - {t(`role.${role()}` as any)} | ||
| 89 | - </span> | ||
| 90 | - </Show> | ||
| 91 | - </div> | ||
| 92 | - <span class="shrink-0 font-mono text-[10px] text-muted-foreground"> | ||
| 93 | - {formattedTime(props.message.sent_at)} | ||
| 94 | - </span> | ||
| 95 | - </div> | ||
| 96 | - | ||
| 97 | - <div class="flex items-center gap-1.5"> | ||
| 98 | - <Show when={isSent()}> | ||
| 99 | - <span class="text-[10px] font-medium text-muted-foreground shrink-0"> | ||
| 100 | - {t("messages.to")}: | ||
| 101 | - </span> | ||
| 102 | - </Show> | ||
| 103 | - <p | ||
| 104 | - class={cn( | ||
| 105 | - "truncate text-xs tracking-tight", | ||
| 106 | - unread() ? "font-bold text-foreground" : "font-medium text-foreground/80" | ||
| 107 | - )} | ||
| 108 | - > | ||
| 109 | - {props.message.subject} | ||
| 110 | - </p> | ||
| 111 | - </div> | ||
| 112 | - | ||
| 113 | - <p class="line-clamp-2 text-[11px] leading-relaxed text-muted-foreground/90"> | ||
| 114 | - {props.message.body} | ||
| 115 | - </p> | ||
| 116 | - | ||
| 117 | - <Show when={props.message.label}> | ||
| 118 | - <div class="pt-0.5"> | ||
| 119 | - <Badge variant="outline" class="text-[9px] h-4 px-1.5 py-0 font-medium"> | ||
| 120 | - {props.message.label} | ||
| 121 | - </Badge> | ||
| 122 | - </div> | ||
| 123 | - </Show> | ||
| 124 | - </div> | ||
| 125 | - </button> | ||
| 126 | - ); | ||
| 127 | -} | ||
src/components/messages/quick-reply-bar.tsxdeleted+0 -80
| @@ -1,80 +0,0 @@ | |||
| 1 | -import { createSignal, Show } from "solid-js"; | ||
| 2 | -import { Button } from "@/components/ui/button"; | ||
| 3 | -import { Textarea } from "@/components/ui/textarea"; | ||
| 4 | -import { IconSend } from "@/components/ui/icons"; | ||
| 5 | -import { useT } from "@/stores/preferences-context"; | ||
| 6 | - | ||
| 7 | -interface QuickReplyBarProps { | ||
| 8 | - recipientName: string; | ||
| 9 | - defaultSubject: string; | ||
| 10 | - onSend: (body: string, subject: string) => Promise<void>; | ||
| 11 | - disabled?: boolean; | ||
| 12 | -} | ||
| 13 | - | ||
| 14 | -export function QuickReplyBar(props: QuickReplyBarProps) { | ||
| 15 | - const t = useT(); | ||
| 16 | - const [body, setBody] = createSignal(""); | ||
| 17 | - const [sending, setSending] = createSignal(false); | ||
| 18 | - const [error, setError] = createSignal(""); | ||
| 19 | - | ||
| 20 | - const handleSend = async (e?: Event) => { | ||
| 21 | - if (e) e.preventDefault(); | ||
| 22 | - const content = body().trim(); | ||
| 23 | - if (!content || sending() || props.disabled) return; | ||
| 24 | - | ||
| 25 | - setError(""); | ||
| 26 | - setSending(true); | ||
| 27 | - | ||
| 28 | - try { | ||
| 29 | - const replySubject = props.defaultSubject.startsWith("Re:") | ||
| 30 | - ? props.defaultSubject | ||
| 31 | - : `Re: ${props.defaultSubject}`; | ||
| 32 | - | ||
| 33 | - await props.onSend(content, replySubject); | ||
| 34 | - setBody(""); | ||
| 35 | - } catch (err: any) { | ||
| 36 | - setError(err?.message || "Mesaj gönderilemedi"); | ||
| 37 | - } finally { | ||
| 38 | - setSending(false); | ||
| 39 | - } | ||
| 40 | - }; | ||
| 41 | - | ||
| 42 | - const handleKeyDown = (e: KeyboardEvent) => { | ||
| 43 | - if (e.key === "Enter" && !e.shiftKey) { | ||
| 44 | - e.preventDefault(); | ||
| 45 | - handleSend(); | ||
| 46 | - } | ||
| 47 | - }; | ||
| 48 | - | ||
| 49 | - return ( | ||
| 50 | - <div class="border-t bg-card/80 p-3 backdrop-blur-xs"> | ||
| 51 | - <form onSubmit={handleSend} class="space-y-2"> | ||
| 52 | - <Show when={error()}> | ||
| 53 | - <p class="text-xs font-medium text-destructive px-1">{error()}</p> | ||
| 54 | - </Show> | ||
| 55 | - <div class="flex items-end gap-2"> | ||
| 56 | - <div class="relative flex-1"> | ||
| 57 | - <Textarea | ||
| 58 | - value={body()} | ||
| 59 | - onInput={(e) => setBody(e.currentTarget.value)} | ||
| 60 | - onKeyDown={handleKeyDown} | ||
| 61 | - placeholder={`${props.recipientName} kişisine mesaj yanıtla... (Göndermek için Enter, yeni satır için Shift+Enter)`} | ||
| 62 | - rows={2} | ||
| 63 | - class="min-h-[2.5rem] max-h-32 resize-none rounded-xl bg-background text-sm py-2 px-3 focus-visible:ring-1" | ||
| 64 | - disabled={sending() || props.disabled} | ||
| 65 | - /> | ||
| 66 | - </div> | ||
| 67 | - <Button | ||
| 68 | - type="submit" | ||
| 69 | - size="sm" | ||
| 70 | - class="h-10 w-10 shrink-0 rounded-xl p-0" | ||
| 71 | - disabled={!body().trim() || sending() || props.disabled} | ||
| 72 | - title={t("messages.send")} | ||
| 73 | - > | ||
| 74 | - <IconSend class="h-4 w-4" /> | ||
| 75 | - </Button> | ||
| 76 | - </div> | ||
| 77 | - </form> | ||
| 78 | - </div> | ||
| 79 | - ); | ||
| 80 | -} | ||
src/components/users/user-role-select.tsxdeleted+0 -26
| @@ -1,26 +0,0 @@ | |||
| 1 | -import type { Role } from "@/api/client"; | ||
| 2 | -import type { MessageKey } from "@/i18n/messages"; | ||
| 3 | -import { Select } from "@/components/ui/select"; | ||
| 4 | -import { ROLES } from "@/lib/roles"; | ||
| 5 | -import { useT } from "@/stores/preferences-context"; | ||
| 6 | - | ||
| 7 | -export function UserRoleSelect(props: { | ||
| 8 | - value: Role; | ||
| 9 | - disabled?: boolean; | ||
| 10 | - onChange: (role: Role) => void; | ||
| 11 | -}) { | ||
| 12 | - const t = useT(); | ||
| 13 | - return ( | ||
| 14 | - <Select | ||
| 15 | - class="rounded-sm" | ||
| 16 | - value={props.value} | ||
| 17 | - disabled={props.disabled} | ||
| 18 | - onChange={(e) => props.onChange(e.currentTarget.value as Role)} | ||
| 19 | - aria-label={t("admin.role")} | ||
| 20 | - > | ||
| 21 | - {ROLES.map((r) => ( | ||
| 22 | - <option value={r}>{t(`role.${r}` as MessageKey)}</option> | ||
| 23 | - ))} | ||
| 24 | - </Select> | ||
| 25 | - ); | ||
| 26 | -} | ||