✅ roll call in a few taps
Browse files at this commit9bea6a1ac7acaef10ad9d4d25b92eb216d2b53abParent: afb3667- feat
- ✅ roll call in a few taps
4 changed files +323 -121
- src/components/sessions/course-sessions-panel.tsx +1 -0
- src/components/sessions/session-roll-call.test.tsx +76 -21
- src/components/sessions/session-roll-call.tsx +222 -100
- src/i18n/messages.ts +24 -0
src/components/sessions/course-sessions-panel.tsxmodified+1 -0
| @@ -376,6 +376,7 @@ export function CourseSessionsPanel(props: { | |||
| 376 | if (!open) setSelectedSession(null); | 376 | if (!open) setSelectedSession(null); |
| 377 | }} | 377 | }} |
| 378 | title={t("sessions.rollCall")} | 378 | title={t("sessions.rollCall")} |
| 379 | + size="wide" | ||
| 379 | description={selectedSession() ? `${selectedSession()!.topic || t("sessions.untitled")} · ${formatDateTime(selectedSession()!.starts_at, locale())}` : undefined} | 380 | description={selectedSession() ? `${selectedSession()!.topic || t("sessions.untitled")} · ${formatDateTime(selectedSession()!.starts_at, locale())}` : undefined} |
| 380 | > | 381 | > |
| 381 | <Show when={selectedSession()}> | 382 | <Show when={selectedSession()}> |
src/components/sessions/session-roll-call.test.tsxmodified+76 -21
| @@ -1,4 +1,4 @@ | |||
| 1 | -import { fireEvent, render, screen, waitFor } from "@solidjs/testing-library"; | 1 | +import { fireEvent, render, screen, waitFor, within } from "@solidjs/testing-library"; |
| 2 | import { SessionRollCall } from "@/components/sessions/session-roll-call"; | 2 | import { SessionRollCall } from "@/components/sessions/session-roll-call"; |
| 3 | import { PreferencesProvider } from "@/stores/preferences-context"; | 3 | import { PreferencesProvider } from "@/stores/preferences-context"; |
| 4 | 4 | ||
| @@ -24,13 +24,14 @@ vi.mock("@/api/settings", () => ({ | |||
| 24 | getSettings: async () => ({ attendance_statuses: ["present", "absent", "late", "excused"] }), | 24 | getSettings: async () => ({ attendance_statuses: ["present", "absent", "late", "excused"] }), |
| 25 | })); | 25 | })); |
| 26 | 26 | ||
| 27 | -const roster = [{ | 27 | +const enrollment = (id: string, name: string) => ({ |
| 28 | - id: "enrollment-1", | 28 | + id: `enrollment-${id}`, |
| 29 | class_course: "instance-1", | 29 | class_course: "instance-1", |
| 30 | - user: { id: "student-1", username: "ada", display_name: "Ada Öğrenci" }, | 30 | + user: { id, username: id, display_name: name }, |
| 31 | enrolled_by: { id: "manager-1", username: "manager", display_name: null }, | 31 | enrolled_by: { id: "manager-1", username: "manager", display_name: null }, |
| 32 | source: null, | 32 | source: null, |
| 33 | -}]; | 33 | +}); |
| 34 | +const roster = [enrollment("student-1", "Ada Öğrenci")]; | ||
| 34 | 35 | ||
| 35 | const teacher = { id: "teacher-1", username: "teacher", display_name: "Deniz Öğretmen" }; | 36 | const teacher = { id: "teacher-1", username: "teacher", display_name: "Deniz Öğretmen" }; |
| 36 | 37 | ||
| @@ -38,35 +39,89 @@ afterEach(() => { | |||
| 38 | vi.clearAllMocks(); | 39 | vi.clearAllMocks(); |
| 39 | }); | 40 | }); |
| 40 | 41 | ||
| 41 | -test("lets manager-level users mark the session teacher alongside enrolled students", async () => { | 42 | +const mount = (props: { roster?: ReturnType<typeof enrollment>[]; canMarkTeacher?: boolean } = {}) => |
| 42 | render(() => ( | 43 | render(() => ( |
| 43 | <PreferencesProvider> | 44 | <PreferencesProvider> |
| 44 | - <SessionRollCall sessionId="session-1" roster={roster} teacher={teacher} canMarkTeacher /> | 45 | + <SessionRollCall |
| 46 | + sessionId="session-1" | ||
| 47 | + roster={props.roster ?? roster} | ||
| 48 | + teacher={teacher} | ||
| 49 | + canMarkTeacher={props.canMarkTeacher ?? false} | ||
| 50 | + /> | ||
| 45 | </PreferencesProvider> | 51 | </PreferencesProvider> |
| 46 | )); | 52 | )); |
| 53 | +const statusButtons = (name: string) => within(screen.getByRole("radiogroup", { name })); | ||
| 54 | +/** The status buttons unlock once the saved marks have loaded. */ | ||
| 55 | +const ready = () => screen.findByText(/\d+ of \d+ marked|kişiden \d+ işaretlendi/); | ||
| 47 | 56 | ||
| 48 | - expect(await screen.findByText("Ada Öğrenci")).toBeTruthy(); | 57 | +test("lets manager-level users mark the session teacher alongside enrolled students", async () => { |
| 49 | - expect(screen.getByText("Deniz Öğretmen")).toBeTruthy(); | 58 | + mount({ canMarkTeacher: true }); |
| 50 | 59 | ||
| 51 | - const saveButtons = screen.getAllByRole("button", { name: "Save" }); | 60 | + expect(await screen.findByText("Ada Öğrenci")).toBeTruthy(); |
| 52 | - fireEvent.click(saveButtons[1]!); | 61 | + await ready(); |
| 62 | + fireEvent.click(statusButtons("Deniz Öğretmen").getByRole("radio", { name: /Present|Var|Mevcut/ })); | ||
| 53 | 63 | ||
| 54 | await waitFor(() => { | 64 | await waitFor(() => { |
| 55 | - expect(postSessionAttendance).toHaveBeenCalledWith("session-1", { | 65 | + expect(postSessionAttendance).toHaveBeenCalledWith("session-1", { user_id: "teacher-1", status: "present" }); |
| 56 | - user_id: "teacher-1", | ||
| 57 | - status: "present", | ||
| 58 | - }); | ||
| 59 | }); | 66 | }); |
| 60 | }); | 67 | }); |
| 61 | 68 | ||
| 62 | test("keeps the teacher out of roll call for users without staff-attendance rights", async () => { | 69 | test("keeps the teacher out of roll call for users without staff-attendance rights", async () => { |
| 63 | - render(() => ( | 70 | + mount(); |
| 64 | - <PreferencesProvider> | ||
| 65 | - <SessionRollCall sessionId="session-1" roster={roster} teacher={teacher} canMarkTeacher={false} /> | ||
| 66 | - </PreferencesProvider> | ||
| 67 | - )); | ||
| 68 | 71 | ||
| 69 | expect(await screen.findByText("Ada Öğrenci")).toBeTruthy(); | 72 | expect(await screen.findByText("Ada Öğrenci")).toBeTruthy(); |
| 70 | expect(screen.queryByText("Deniz Öğretmen")).toBeNull(); | 73 | expect(screen.queryByText("Deniz Öğretmen")).toBeNull(); |
| 71 | - expect(screen.getAllByRole("button", { name: "Save" })).toHaveLength(1); | 74 | + expect(screen.getAllByRole("radiogroup")).toHaveLength(1); |
| 75 | +}); | ||
| 76 | + | ||
| 77 | +test("one tap saves that row, with no roster refetch", async () => { | ||
| 78 | + mount(); | ||
| 79 | + await ready(); | ||
| 80 | + const absent = statusButtons("Ada Öğrenci").getByRole("radio", { name: /Absent|Yok|Devamsız/ }); | ||
| 81 | + | ||
| 82 | + fireEvent.click(absent); | ||
| 83 | + | ||
| 84 | + await waitFor(() => expect(postSessionAttendance).toHaveBeenCalledWith("session-1", { user_id: "student-1", status: "absent" })); | ||
| 85 | + expect(absent.getAttribute("aria-checked")).toBe("true"); | ||
| 86 | + expect(getSessionAttendance).toHaveBeenCalledTimes(1); | ||
| 87 | +}); | ||
| 88 | + | ||
| 89 | +test("mark the rest present fills only the unmarked students", async () => { | ||
| 90 | + getSessionAttendance.mockResolvedValueOnce({ | ||
| 91 | + items: [{ | ||
| 92 | + id: "a-2", | ||
| 93 | + session: "session-1", | ||
| 94 | + class_course: "instance-1", | ||
| 95 | + user: { id: "student-2", username: "student-2", display_name: "Bora" }, | ||
| 96 | + status: "absent", | ||
| 97 | + marked_by: { id: "teacher-1", username: "teacher", display_name: null }, | ||
| 98 | + }], | ||
| 99 | + total: 1, | ||
| 100 | + limit: null, | ||
| 101 | + offset: 0, | ||
| 102 | + } as never); | ||
| 103 | + mount({ | ||
| 104 | + roster: [enrollment("student-1", "Ada"), enrollment("student-2", "Bora"), enrollment("student-3", "Cem")], | ||
| 105 | + canMarkTeacher: true, | ||
| 106 | + }); | ||
| 107 | + expect(await screen.findByText(/1 of 4 marked|4 kişiden 1/)).toBeTruthy(); | ||
| 108 | + | ||
| 109 | + fireEvent.click(screen.getByRole("button", { name: /Mark the rest present|Kalanları Var/ })); | ||
| 110 | + | ||
| 111 | + await waitFor(() => expect(postSessionAttendance).toHaveBeenCalledTimes(2)); | ||
| 112 | + const marked = postSessionAttendance.mock.calls.map(([, body]) => body.user_id).sort(); | ||
| 113 | + expect(marked).toEqual(["student-1", "student-3"]); | ||
| 114 | + expect(await screen.findByText(/3 of 4 marked|4 kişiden 3/)).toBeTruthy(); | ||
| 115 | +}); | ||
| 116 | + | ||
| 117 | +test("a failed save puts the row back as it was", async () => { | ||
| 118 | + postSessionAttendance.mockRejectedValueOnce(new Error("offline")); | ||
| 119 | + mount(); | ||
| 120 | + await ready(); | ||
| 121 | + const late = statusButtons("Ada Öğrenci").getByRole("radio", { name: /Late|Geç/ }); | ||
| 122 | + | ||
| 123 | + fireEvent.click(late); | ||
| 124 | + | ||
| 125 | + await waitFor(() => expect(screen.getByRole("alert")).toBeTruthy()); | ||
| 126 | + expect(late.getAttribute("aria-checked")).toBe("false"); | ||
| 72 | }); | 127 | }); |
src/components/sessions/session-roll-call.tsxmodified+222 -100
| @@ -1,26 +1,33 @@ | |||
| 1 | import { For, Show, createEffect, createMemo, createSignal } from "solid-js"; | 1 | import { For, Show, createEffect, createMemo, createSignal } from "solid-js"; |
| 2 | import { createResource } from "@/lib/create-resource"; | 2 | import { createResource } from "@/lib/create-resource"; |
| 3 | import { deleteSessionAttendanceByUserId, getSessionAttendance, postSessionAttendance } from "@/api/sessions"; | 3 | import { deleteSessionAttendanceByUserId, getSessionAttendance, postSessionAttendance } from "@/api/sessions"; |
| 4 | +import { getSettings } from "@/api/settings"; | ||
| 4 | import { formatApiError } from "@/api/client"; | 5 | import { formatApiError } from "@/api/client"; |
| 5 | -import type { AttendanceStatus, Enrollment, PersonRef, SessionAttendance } from "@/api/client"; | 6 | +import type { AttendanceStatus, Enrollment, PersonRef } from "@/api/client"; |
| 6 | -import { AttendanceStatusPicker } from "@/components/events/attendance-status-picker"; | ||
| 7 | import { Alert } from "@/components/ui/alert"; | 7 | import { Alert } from "@/components/ui/alert"; |
| 8 | import { Badge } from "@/components/ui/badge"; | 8 | import { Badge } from "@/components/ui/badge"; |
| 9 | import { Button } from "@/components/ui/button"; | 9 | import { Button } from "@/components/ui/button"; |
| 10 | import { EmptyState } from "@/components/ui/empty-state"; | 10 | import { EmptyState } from "@/components/ui/empty-state"; |
| 11 | -import { IconTrash } from "@/components/ui/icons"; | 11 | +import { IconCheck, IconX } from "@/components/ui/icons"; |
| 12 | -import { PaginationControls } from "@/components/ui/pagination-controls"; | 12 | +import { ATTENDANCE_STATUSES, getAttendanceStatusMeta } from "@/lib/attendance-status"; |
| 13 | -import { createFlash } from "@/lib/flash"; | 13 | +import { cn } from "@/lib/cn"; |
| 14 | import { personLabel } from "@/lib/person"; | 14 | import { personLabel } from "@/lib/person"; |
| 15 | import { useT } from "@/stores/preferences-context"; | 15 | import { useT } from "@/stores/preferences-context"; |
| 16 | 16 | ||
| 17 | -const PAGE_SIZE = 8; | 17 | +/** Parallel requests while marking the rest present; the API takes one row per call. */ |
| 18 | +const BULK_CONCURRENCY = 4; | ||
| 18 | 19 | ||
| 19 | type RollCallTarget = { | 20 | type RollCallTarget = { |
| 20 | user: PersonRef; | 21 | user: PersonRef; |
| 21 | isTeacher: boolean; | 22 | isTeacher: boolean; |
| 22 | }; | 23 | }; |
| 23 | 24 | ||
| 25 | +/** | ||
| 26 | + * Lesson roll call built for speed: one list, a tap on a status saves that | ||
| 27 | + * row at once, and "mark the rest present" fills every unmarked row — the | ||
| 28 | + * teacher then only touches the exceptions. Nothing is shown as present | ||
| 29 | + * until it is actually saved: an unmarked row stays visibly unmarked. | ||
| 30 | + */ | ||
| 24 | export function SessionRollCall(props: { | 31 | export function SessionRollCall(props: { |
| 25 | sessionId: string; | 32 | sessionId: string; |
| 26 | roster: Enrollment[]; | 33 | roster: Enrollment[]; |
| @@ -28,74 +35,130 @@ export function SessionRollCall(props: { | |||
| 28 | canMarkTeacher: boolean; | 35 | canMarkTeacher: boolean; |
| 29 | }) { | 36 | }) { |
| 30 | const t = useT(); | 37 | const t = useT(); |
| 31 | - const [attendance, { refetch }] = createResource( | 38 | + const [settings] = createResource(() => getSettings()); |
| 39 | + const statuses = createMemo<AttendanceStatus[]>( | ||
| 40 | + () => settings.latest?.attendance_statuses ?? ATTENDANCE_STATUSES.map((item) => item.value), | ||
| 41 | + ); | ||
| 42 | + const [attendance] = createResource( | ||
| 32 | () => props.sessionId, | 43 | () => props.sessionId, |
| 33 | async (sessionId) => (await getSessionAttendance(sessionId)).items, | 44 | async (sessionId) => (await getSessionAttendance(sessionId)).items, |
| 34 | ); | 45 | ); |
| 35 | - const rows = createMemo(() => new Map((attendance() ?? []).map((row) => [row.user.id, row]))); | 46 | + // Saved marks live in a local signal seeded from the server list: a tap |
| 47 | + // updates it optimistically instead of refetching the whole roster. | ||
| 48 | + const [marks, setMarks] = createSignal<Record<string, AttendanceStatus>>({}); | ||
| 49 | + createEffect(() => { | ||
| 50 | + const rows = attendance.latest; | ||
| 51 | + if (rows) setMarks(Object.fromEntries(rows.map((row) => [row.user.id, row.status]))); | ||
| 52 | + }); | ||
| 53 | + | ||
| 54 | + // The roster renders from props at once, but the saved marks arrive with | ||
| 55 | + // the attendance read; a tap before then would be overwritten by it, so | ||
| 56 | + // the status buttons wait for it. | ||
| 57 | + const ready = () => attendance.latest !== undefined; | ||
| 36 | const targets = createMemo<RollCallTarget[]>(() => [ | 58 | const targets = createMemo<RollCallTarget[]>(() => [ |
| 37 | ...props.roster.map((row) => ({ user: row.user, isTeacher: false })), | 59 | ...props.roster.map((row) => ({ user: row.user, isTeacher: false })), |
| 38 | ...(props.canMarkTeacher && !props.roster.some((row) => row.user.id === props.teacher.id) | 60 | ...(props.canMarkTeacher && !props.roster.some((row) => row.user.id === props.teacher.id) |
| 39 | ? [{ user: props.teacher, isTeacher: true }] | 61 | ? [{ user: props.teacher, isTeacher: true }] |
| 40 | : []), | 62 | : []), |
| 41 | ]); | 63 | ]); |
| 42 | - const [local, setLocal] = createSignal<Record<string, AttendanceStatus>>({}); | 64 | + const [saving, setSaving] = createSignal<ReadonlySet<string>>(new Set()); |
| 43 | - const [pendingUserId, setPendingUserId] = createSignal<string | null>(null); | ||
| 44 | const [error, setError] = createSignal(""); | 65 | const [error, setError] = createSignal(""); |
| 45 | - const [flash, setFlash] = createFlash(); | 66 | + const [onlyUnmarked, setOnlyUnmarked] = createSignal(false); |
| 46 | - const [page, setPage] = createSignal(0); | 67 | + const [bulk, setBulk] = createSignal<{ done: number; total: number } | null>(null); |
| 47 | - const totalPages = createMemo(() => Math.max(1, Math.ceil(targets().length / PAGE_SIZE))); | ||
| 48 | - const safePage = createMemo(() => Math.min(page(), totalPages() - 1)); | ||
| 49 | - const visibleTargets = createMemo(() => { | ||
| 50 | - const start = safePage() * PAGE_SIZE; | ||
| 51 | - return targets().slice(start, start + PAGE_SIZE); | ||
| 52 | - }); | ||
| 53 | 68 | ||
| 54 | - createEffect(() => { | 69 | + const markedCount = createMemo(() => targets().filter((target) => marks()[target.user.id] != null).length); |
| 55 | - if (page() >= totalPages()) setPage(totalPages() - 1); | 70 | + const unmarked = createMemo(() => targets().filter((target) => marks()[target.user.id] == null)); |
| 71 | + const counts = createMemo(() => { | ||
| 72 | + const tally: Record<string, number> = {}; | ||
| 73 | + for (const target of targets()) { | ||
| 74 | + const status = marks()[target.user.id]; | ||
| 75 | + if (status) tally[status] = (tally[status] ?? 0) + 1; | ||
| 76 | + } | ||
| 77 | + return tally; | ||
| 56 | }); | 78 | }); |
| 79 | + const visibleTargets = createMemo(() => (onlyUnmarked() ? unmarked() : targets())); | ||
| 57 | 80 | ||
| 58 | - const statusFor = (userId: string) => local()[userId] ?? rows().get(userId)?.status ?? "present"; | 81 | + const setBusy = (userId: string, busy: boolean) => |
| 59 | - const save = async (userId: string) => { | 82 | + setSaving((current) => { |
| 60 | - if (pendingUserId()) return; | 83 | + const next = new Set(current); |
| 84 | + if (busy) next.add(userId); | ||
| 85 | + else next.delete(userId); | ||
| 86 | + return next; | ||
| 87 | + }); | ||
| 88 | + const setMark = (userId: string, status: AttendanceStatus | undefined) => | ||
| 89 | + setMarks((current) => { | ||
| 90 | + const next = { ...current }; | ||
| 91 | + if (status) next[userId] = status; | ||
| 92 | + else delete next[userId]; | ||
| 93 | + return next; | ||
| 94 | + }); | ||
| 95 | + | ||
| 96 | + const mark = async (userId: string, status: AttendanceStatus) => { | ||
| 97 | + const previous = marks()[userId]; | ||
| 98 | + if (previous === status || saving().has(userId)) return; | ||
| 61 | setError(""); | 99 | setError(""); |
| 62 | - setPendingUserId(userId); | 100 | + setMark(userId, status); |
| 101 | + setBusy(userId, true); | ||
| 63 | try { | 102 | try { |
| 64 | - await postSessionAttendance(props.sessionId, { user_id: userId, status: statusFor(userId) }); | 103 | + await postSessionAttendance(props.sessionId, { user_id: userId, status }); |
| 65 | - await refetch(); | ||
| 66 | - setFlash(t("common.saved")); | ||
| 67 | } catch (err) { | 104 | } catch (err) { |
| 105 | + setMark(userId, previous); | ||
| 68 | setError(formatApiError(err)); | 106 | setError(formatApiError(err)); |
| 69 | } finally { | 107 | } finally { |
| 70 | - setPendingUserId(null); | 108 | + setBusy(userId, false); |
| 71 | } | 109 | } |
| 72 | }; | 110 | }; |
| 73 | 111 | ||
| 74 | const clear = async (userId: string) => { | 112 | const clear = async (userId: string) => { |
| 75 | - if (pendingUserId()) return; | 113 | + const previous = marks()[userId]; |
| 114 | + if (!previous || saving().has(userId)) return; | ||
| 76 | setError(""); | 115 | setError(""); |
| 77 | - setPendingUserId(userId); | 116 | + setMark(userId, undefined); |
| 117 | + setBusy(userId, true); | ||
| 78 | try { | 118 | try { |
| 79 | await deleteSessionAttendanceByUserId(props.sessionId, userId); | 119 | await deleteSessionAttendanceByUserId(props.sessionId, userId); |
| 80 | - setLocal((current) => { | ||
| 81 | - const next = { ...current }; | ||
| 82 | - delete next[userId]; | ||
| 83 | - return next; | ||
| 84 | - }); | ||
| 85 | - await refetch(); | ||
| 86 | - setFlash(t("common.deleted")); | ||
| 87 | } catch (err) { | 120 | } catch (err) { |
| 121 | + setMark(userId, previous); | ||
| 88 | setError(formatApiError(err)); | 122 | setError(formatApiError(err)); |
| 89 | } finally { | 123 | } finally { |
| 90 | - setPendingUserId(null); | 124 | + setBusy(userId, false); |
| 91 | } | 125 | } |
| 92 | }; | 126 | }; |
| 93 | 127 | ||
| 128 | + const markRestPresent = async () => { | ||
| 129 | + // Students only: the teacher's own presence row is a separate, deliberate call. | ||
| 130 | + const queue = unmarked().filter((target) => !target.isTeacher).map((target) => target.user.id); | ||
| 131 | + if (queue.length === 0 || bulk()) return; | ||
| 132 | + setError(""); | ||
| 133 | + setBulk({ done: 0, total: queue.length }); | ||
| 134 | + const failures: unknown[] = []; | ||
| 135 | + const worker = async () => { | ||
| 136 | + for (let userId = queue.shift(); userId; userId = queue.shift()) { | ||
| 137 | + setMark(userId, "present"); | ||
| 138 | + setBusy(userId, true); | ||
| 139 | + try { | ||
| 140 | + await postSessionAttendance(props.sessionId, { user_id: userId, status: "present" }); | ||
| 141 | + } catch (err) { | ||
| 142 | + setMark(userId, undefined); | ||
| 143 | + failures.push(err); | ||
| 144 | + } finally { | ||
| 145 | + setBusy(userId, false); | ||
| 146 | + setBulk((current) => (current ? { ...current, done: current.done + 1 } : current)); | ||
| 147 | + } | ||
| 148 | + } | ||
| 149 | + }; | ||
| 150 | + await Promise.all(Array.from({ length: BULK_CONCURRENCY }, worker)); | ||
| 151 | + setBulk(null); | ||
| 152 | + if (failures.length > 0) setError(t("rollCall.bulkFailed", { count: failures.length, reason: formatApiError(failures[0]) })); | ||
| 153 | + }; | ||
| 154 | + | ||
| 155 | + const statusLabel = (status: AttendanceStatus) => { | ||
| 156 | + const meta = getAttendanceStatusMeta(status); | ||
| 157 | + return meta ? t(meta.key) : status; | ||
| 158 | + }; | ||
| 159 | + | ||
| 94 | return ( | 160 | return ( |
| 95 | <div class="space-y-3"> | 161 | <div class="space-y-3"> |
| 96 | - <Show when={flash()}> | ||
| 97 | - <Alert variant="success">{flash()}</Alert> | ||
| 98 | - </Show> | ||
| 99 | <Show when={error()}> | 162 | <Show when={error()}> |
| 100 | <Alert variant="destructive">{error()}</Alert> | 163 | <Alert variant="destructive">{error()}</Alert> |
| 101 | </Show> | 164 | </Show> |
| @@ -103,66 +166,125 @@ export function SessionRollCall(props: { | |||
| 103 | when={targets().length > 0} | 166 | when={targets().length > 0} |
| 104 | fallback={<EmptyState kind="people" title={t("sessions.emptyRoster")} />} | 167 | fallback={<EmptyState kind="people" title={t("sessions.emptyRoster")} />} |
| 105 | > | 168 | > |
| 106 | - <For each={visibleTargets()}> | 169 | + <div class="sticky top-0 z-10 -mx-5 space-y-2.5 border-b border-border-hairline bg-surface-base px-5 pb-3"> |
| 107 | - {(target) => { | 170 | + <div class="flex items-center justify-between gap-3"> |
| 108 | - const saved = () => rows().get(target.user.id) as SessionAttendance | undefined; | 171 | + <p class="text-sm font-semibold text-text-strong" role="status"> |
| 109 | - const pending = () => pendingUserId() === target.user.id; | 172 | + {ready() ? t("rollCall.progress", { marked: markedCount(), total: targets().length }) : t("common.loading")} |
| 110 | - return ( | 173 | + </p> |
| 111 | - <div class="space-y-2 rounded-lg border border-border/50 bg-card px-4 py-3"> | 174 | + <div class="flex flex-wrap justify-end gap-1.5"> |
| 112 | - <div class="flex min-w-0 items-center gap-2"> | 175 | + <For each={statuses()}> |
| 113 | - <div class="min-w-0 flex-1"> | 176 | + {(status) => ( |
| 114 | - <p class="truncate font-medium">{personLabel(target.user)}</p> | 177 | + <Show when={counts()[status]}> |
| 115 | - <Show when={target.user.display_name}> | 178 | + <span class={cn("rounded-full border px-2 py-0.5 text-xs font-medium", getAttendanceStatusMeta(status)?.class)}> |
| 116 | - <p class="truncate text-xs text-muted-foreground">{target.user.username}</p> | 179 | + {statusLabel(status)} {counts()[status]} |
| 117 | - </Show> | 180 | + </span> |
| 118 | - </div> | ||
| 119 | - <Show when={target.isTeacher}> | ||
| 120 | - <Badge variant="secondary" class="shrink-0 rounded-full">{t("sessions.teacher")}</Badge> | ||
| 121 | </Show> | 181 | </Show> |
| 122 | - </div> | 182 | + )} |
| 123 | - <div class="flex items-center gap-2"> | 183 | + </For> |
| 124 | - <div class="min-w-0 flex-1"> | 184 | + </div> |
| 125 | - <AttendanceStatusPicker | 185 | + </div> |
| 126 | - hideLabel | 186 | + <div class="h-1.5 overflow-hidden rounded-full bg-surface-tint" aria-hidden="true"> |
| 127 | - hideDetail | 187 | + <div |
| 128 | - id={`session-${props.sessionId}-${target.user.id}`} | 188 | + class="h-full rounded-full bg-success transition-[width] duration-200" |
| 129 | - value={statusFor(target.user.id)} | 189 | + style={{ width: `${targets().length ? (markedCount() / targets().length) * 100 : 0}%` }} |
| 130 | - onChange={(status) => setLocal((current) => ({ ...current, [target.user.id]: status }))} | 190 | + /> |
| 131 | - /> | 191 | + </div> |
| 132 | - </div> | 192 | + <div class="flex flex-wrap items-center gap-2"> |
| 133 | - <Button | 193 | + <Button |
| 134 | - type="button" | 194 | + type="button" |
| 135 | - class="h-10 w-24 shrink-0 rounded-lg" | 195 | + size="sm" |
| 136 | - variant={saved() ? "outline" : "default"} | 196 | + class="h-9 rounded-lg" |
| 137 | - disabled={pendingUserId() != null} | 197 | + disabled={!ready() || bulk() != null || unmarked().filter((target) => !target.isTeacher).length === 0} |
| 138 | - onClick={() => void save(target.user.id)} | 198 | + onClick={() => void markRestPresent()} |
| 139 | - > | 199 | + > |
| 140 | - {saved() ? t("common.update") : t("common.save")} | 200 | + <IconCheck class="h-4 w-4" /> |
| 141 | - </Button> | 201 | + {bulk() |
| 142 | - <Show when={saved()}> | 202 | + ? t("rollCall.marking", { done: bulk()!.done, total: bulk()!.total }) |
| 143 | - <Button | 203 | + : t("rollCall.markRestPresent")} |
| 144 | - type="button" | 204 | + </Button> |
| 145 | - variant="ghost" | 205 | + <Button |
| 146 | - size="icon" | 206 | + type="button" |
| 147 | - class="h-10 w-10 shrink-0 text-destructive-text hover:bg-destructive/10" | 207 | + size="sm" |
| 148 | - aria-label={t("common.remove")} | 208 | + variant="outline" |
| 149 | - disabled={pendingUserId() != null} | 209 | + class="h-9 rounded-lg" |
| 150 | - onClick={() => void clear(target.user.id)} | 210 | + aria-pressed={onlyUnmarked()} |
| 151 | - > | 211 | + onClick={() => setOnlyUnmarked((value) => !value)} |
| 152 | - <IconTrash class="h-4 w-4" /> | 212 | + > |
| 153 | - </Button> | 213 | + {t("rollCall.onlyUnmarked")} |
| 154 | - </Show> | 214 | + </Button> |
| 155 | - <Show when={pending()}> | 215 | + </div> |
| 156 | - <span class="sr-only" aria-live="polite">{t("common.loading")}</span> | 216 | + </div> |
| 157 | - </Show> | 217 | + |
| 158 | - </div> | 218 | + <Show |
| 159 | - </div> | 219 | + when={visibleTargets().length > 0} |
| 160 | - ); | 220 | + fallback={<p class="py-6 text-center text-sm text-muted-foreground">{t("rollCall.allMarked")}</p>} |
| 161 | - }} | 221 | + > |
| 162 | - </For> | 222 | + <ul class="divide-y divide-border-hairline"> |
| 163 | - </Show> | 223 | + <For each={visibleTargets()}> |
| 164 | - <Show when={totalPages() > 1}> | 224 | + {(target) => { |
| 165 | - <PaginationControls page={safePage()} totalPages={totalPages()} onPageChange={setPage} /> | 225 | + const current = () => marks()[target.user.id]; |
| 226 | + const busy = () => saving().has(target.user.id); | ||
| 227 | + const groupLabel = () => personLabel(target.user); | ||
| 228 | + return ( | ||
| 229 | + <li class="flex flex-col gap-2 py-2.5 sm:flex-row sm:items-center"> | ||
| 230 | + <div class="flex min-w-0 flex-1 items-center gap-2"> | ||
| 231 | + <span | ||
| 232 | + class={cn("h-2 w-2 shrink-0 rounded-full", current() ? "bg-success" : "bg-border-line")} | ||
| 233 | + aria-hidden="true" | ||
| 234 | + /> | ||
| 235 | + <div class="min-w-0"> | ||
| 236 | + <p class="truncate text-sm font-medium">{groupLabel()}</p> | ||
| 237 | + <p class="truncate text-xs text-muted-foreground"> | ||
| 238 | + {current() ? statusLabel(current()!) : t("rollCall.unmarked")} | ||
| 239 | + </p> | ||
| 240 | + </div> | ||
| 241 | + <Show when={target.isTeacher}> | ||
| 242 | + <Badge variant="secondary" class="shrink-0 rounded-full">{t("sessions.teacher")}</Badge> | ||
| 243 | + </Show> | ||
| 244 | + </div> | ||
| 245 | + <div class="flex items-center gap-1.5"> | ||
| 246 | + <div role="radiogroup" aria-label={groupLabel()} class="grid flex-1 grid-cols-4 gap-1 sm:flex sm:flex-none"> | ||
| 247 | + <For each={statuses()}> | ||
| 248 | + {(status) => { | ||
| 249 | + const selected = () => current() === status; | ||
| 250 | + return ( | ||
| 251 | + <button | ||
| 252 | + type="button" | ||
| 253 | + role="radio" | ||
| 254 | + aria-checked={selected()} | ||
| 255 | + disabled={!ready() || busy() || bulk() != null} | ||
| 256 | + class={cn( | ||
| 257 | + "h-9 min-w-0 rounded-lg border px-2.5 text-xs font-semibold transition-colors outline-hidden focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-60", | ||
| 258 | + selected() | ||
| 259 | + ? getAttendanceStatusMeta(status)?.class ?? "border-primary bg-primary/10 text-primary-text" | ||
| 260 | + : "border-border-line bg-surface-base text-muted-foreground hover:bg-muted/60 hover:text-foreground", | ||
| 261 | + )} | ||
| 262 | + onClick={() => void mark(target.user.id, status)} | ||
| 263 | + > | ||
| 264 | + {statusLabel(status)} | ||
| 265 | + </button> | ||
| 266 | + ); | ||
| 267 | + }} | ||
| 268 | + </For> | ||
| 269 | + </div> | ||
| 270 | + <Button | ||
| 271 | + type="button" | ||
| 272 | + variant="ghost" | ||
| 273 | + size="icon" | ||
| 274 | + class={cn("h-9 w-9 shrink-0 text-muted-foreground", !current() && "invisible")} | ||
| 275 | + aria-label={t("rollCall.clear")} | ||
| 276 | + disabled={busy() || !current()} | ||
| 277 | + onClick={() => void clear(target.user.id)} | ||
| 278 | + > | ||
| 279 | + <IconX class="h-4 w-4" /> | ||
| 280 | + </Button> | ||
| 281 | + </div> | ||
| 282 | + </li> | ||
| 283 | + ); | ||
| 284 | + }} | ||
| 285 | + </For> | ||
| 286 | + </ul> | ||
| 287 | + </Show> | ||
| 166 | </Show> | 288 | </Show> |
| 167 | </div> | 289 | </div> |
| 168 | ); | 290 | ); |
src/i18n/messages.tsmodified+24 -0
| @@ -616,6 +616,14 @@ export type MessageKey = | |||
| 616 | | "common.deleted" | 616 | | "common.deleted" |
| 617 | | "common.saved" | 617 | | "common.saved" |
| 618 | | "common.loadAll" | 618 | | "common.loadAll" |
| 619 | + | "rollCall.progress" | ||
| 620 | + | "rollCall.markRestPresent" | ||
| 621 | + | "rollCall.marking" | ||
| 622 | + | "rollCall.onlyUnmarked" | ||
| 623 | + | "rollCall.allMarked" | ||
| 624 | + | "rollCall.unmarked" | ||
| 625 | + | "rollCall.clear" | ||
| 626 | + | "rollCall.bulkFailed" | ||
| 619 | | "common.skipToContent" | 627 | | "common.skipToContent" |
| 620 | | "form.fieldRequired" | 628 | | "form.fieldRequired" |
| 621 | | "common.close" | 629 | | "common.close" |
| @@ -2759,6 +2767,14 @@ const en: Dict = { | |||
| 2759 | "common.deleted": "Deleted.", | 2767 | "common.deleted": "Deleted.", |
| 2760 | "common.saved": "Saved successfully.", | 2768 | "common.saved": "Saved successfully.", |
| 2761 | "common.loadAll": "Load all", | 2769 | "common.loadAll": "Load all", |
| 2770 | + "rollCall.progress": "{marked} of {total} marked", | ||
| 2771 | + "rollCall.markRestPresent": "Mark the rest present", | ||
| 2772 | + "rollCall.marking": "Saving {done} of {total}…", | ||
| 2773 | + "rollCall.onlyUnmarked": "Only unmarked", | ||
| 2774 | + "rollCall.allMarked": "Everyone is marked.", | ||
| 2775 | + "rollCall.unmarked": "Not marked yet", | ||
| 2776 | + "rollCall.clear": "Clear mark", | ||
| 2777 | + "rollCall.bulkFailed": "{count} rows could not be saved: {reason}", | ||
| 2762 | "common.skipToContent": "Skip to content", | 2778 | "common.skipToContent": "Skip to content", |
| 2763 | "form.fieldRequired": "This field is required.", | 2779 | "form.fieldRequired": "This field is required.", |
| 2764 | "common.close": "Close", | 2780 | "common.close": "Close", |
| @@ -4904,6 +4920,14 @@ const tr: Dict = { | |||
| 4904 | "common.deleted": "Silindi.", | 4920 | "common.deleted": "Silindi.", |
| 4905 | "common.saved": "Başarıyla kaydedildi.", | 4921 | "common.saved": "Başarıyla kaydedildi.", |
| 4906 | "common.loadAll": "Tümünü yükle", | 4922 | "common.loadAll": "Tümünü yükle", |
| 4923 | + "rollCall.progress": "{total} kişiden {marked} işaretlendi", | ||
| 4924 | + "rollCall.markRestPresent": "Kalanları Var işaretle", | ||
| 4925 | + "rollCall.marking": "{total} kişiden {done} kaydedildi…", | ||
| 4926 | + "rollCall.onlyUnmarked": "Yalnızca işaretlenmemişler", | ||
| 4927 | + "rollCall.allMarked": "Herkes işaretlendi.", | ||
| 4928 | + "rollCall.unmarked": "Henüz işaretlenmedi", | ||
| 4929 | + "rollCall.clear": "İşareti kaldır", | ||
| 4930 | + "rollCall.bulkFailed": "{count} satır kaydedilemedi: {reason}", | ||
| 4907 | "common.skipToContent": "İçeriğe geç", | 4931 | "common.skipToContent": "İçeriğe geç", |
| 4908 | "form.fieldRequired": "Bu alan zorunlu.", | 4932 | "form.fieldRequired": "Bu alan zorunlu.", |
| 4909 | "common.close": "Kapat", | 4933 | "common.close": "Kapat", |