forge
Explore
Log in

Don't you dare go Hollow

🐛 lazy-load event attendance behind disclosure

Browse files at this commit

6505c30c11bb0b8edf56cc16bbdbb8e8e7ae9a00Burak BoduroğluParent: b67b398
  • fix
    • 🐛 lazy-load event attendance behind disclosure
Show full message
fix: 🐛 lazy-load event attendance behind disclosure
- wrap teacher attendance in SectionDisclosure
- fetch only when disclosure opens
- signals before resources
- doc + remove completed optimization task
docs/frontend-next-steps.mdmodified+3 -7
@@ -68,6 +68,7 @@ Started fixes:
68 - Exams page create action appears only when the teacher/manager has at least one manageable course to receive the new exam.68 - Exams page create action appears only when the teacher/manager has at least one manageable course to receive the new exam.
69 - Exam create course picker lists only manageable courses, not every visible course.69 - Exam create course picker lists only manageable courses, not every visible course.
70 - Exam detail defers teacher-only heavy data: statistics load when opened, questions mount when opened, and results/roster load when the results or grade workflow needs them.70 - Exam detail defers teacher-only heavy data: statistics load when opened, questions mount when opened, and results/roster load when the results or grade workflow needs them.
71+- Event detail defers the teacher-only attendance roster until the attendance disclosure is opened.
71 72
72 ## Priority 2: Pagination And Request Audit73 ## Priority 2: Pagination And Request Audit
73 74
@@ -113,6 +114,7 @@ Current classification:
113 - `/courses/:id` exams: unpaginated `GET /courses/{id}/exams`; course-scoped and accepted short-term.114 - `/courses/:id` exams: unpaginated `GET /courses/{id}/exams`; course-scoped and accepted short-term.
114 - `/courses/:id` sessions: unpaginated `GET /courses/{id}/sessions`, deferred until sessions section or create panel is opened. Course-scoped and accepted short-term.115 - `/courses/:id` sessions: unpaginated `GET /courses/{id}/sessions`, deferred until sessions section or create panel is opened. Course-scoped and accepted short-term.
115 - `/courses/:id` roster: unpaginated `GET /courses/{id}/enrollments`, course-management only. Accepted for normal class sizes.116 - `/courses/:id` roster: unpaginated `GET /courses/{id}/enrollments`, course-management only. Accepted for normal class sizes.
117+- `/events/:id` attendance: unpaginated `GET /events/{id}/attendance`, teacher+ only and deferred until the attendance disclosure opens. Accepted for event-scale rosters.
116 - `/exams/:id` results: unpaginated `GET /exams/{id}/results`, deferred until results/grade/answer-sheet workflow needs it. Accepted for normal class sizes.118 - `/exams/:id` results: unpaginated `GET /exams/{id}/results`, deferred until results/grade/answer-sheet workflow needs it. Accepted for normal class sizes.
117 - `/exams/:id` questions: unpaginated `GET /exams/{id}/questions`, deferred until questions section is opened. Accepted for exam-scale data.119 - `/exams/:id` questions: unpaginated `GET /exams/{id}/questions`, deferred until questions section is opened. Accepted for exam-scale data.
118 - `/exams/:id/live`: client-paginated/sorted live roster over backend snapshot/SSE. Accepted because monitor snapshot is role-gated and exam-scoped.120 - `/exams/:id/live`: client-paginated/sorted live roster over backend snapshot/SSE. Accepted because monitor snapshot is role-gated and exam-scoped.
@@ -145,12 +147,6 @@ Known follow-ups:
145 - This is acceptable while the question form stays small.147 - This is acceptable while the question form stays small.
146 - Revisit as a `SidePanel` if question authoring grows or needs more vertical space.148 - Revisit as a `SidePanel` if question authoring grows or needs more vertical space.
147 149
148-### Event Detail Optimization
149-
150-- Event detail still fetches attendance on initial page load.
151-- Consider wrapping attendance in `SectionDisclosure` so the attendance list fetches only when opened.
152-- Keep self-attendance visible if it remains a primary action.
153-
154 ### Schedule Validation150 ### Schedule Validation
155 151
156 - Lesson session creation currently validates date shape and end-after-start in the client; backend still enforces not-in-the-past with server time.152 - Lesson session creation currently validates date shape and end-after-start in the client; backend still enforces not-in-the-past with server time.
@@ -174,7 +170,7 @@ Known follow-ups:
174 - `/courses`: max 2-4 initial API calls depending on role and lookup needs.170 - `/courses`: max 2-4 initial API calls depending on role and lookup needs.
175 - `/courses/:id`: course detail may keep opened section state mounted; avoid fetching large hidden data unless the section is opened or needed for header metadata.171 - `/courses/:id`: course detail may keep opened section state mounted; avoid fetching large hidden data unless the section is opened or needed for header metadata.
176 - `/exams/:id`: exam detail may keep disclosure content mounted to preserve local state; defer heavy section data where practical.172 - `/exams/:id`: exam detail may keep disclosure content mounted to preserve local state; defer heavy section data where practical.
177-- `/events/:id`: consider lazy-loading attendance if the route feels heavy.173+- `/events/:id`: teacher-only attendance is lazy-loaded behind the attendance disclosure; keep self-attendance visible as a primary action.
178 - Dashboard should avoid broad role-specific requests unless that role actually needs global scope.174 - Dashboard should avoid broad role-specific requests unless that role actually needs global scope.
179 - Settings-dependent controls should share the cached settings request.175 - Settings-dependent controls should share the cached settings request.
180 - Paginated tables should prefer server-side pagination when backend support exists.176 - Paginated tables should prefer server-side pagination when backend support exists.
src/pages/event-detail-page.tsxmodified+19 -16
@@ -18,6 +18,7 @@ import { Button } from "@/components/ui/button";
18 import { ConfirmDialog } from "@/components/ui/confirm-dialog";18 import { ConfirmDialog } from "@/components/ui/confirm-dialog";
19 import { IconChevronLeft, IconEdit, IconTrash } from "@/components/ui/icons";19 import { IconChevronLeft, IconEdit, IconTrash } from "@/components/ui/icons";
20 import { PageSpinner } from "@/components/ui/page-spinner";20 import { PageSpinner } from "@/components/ui/page-spinner";
21+import { SectionDisclosure } from "@/components/ui/section-disclosure";
21 import { SidePanel } from "@/components/ui/side-panel";22 import { SidePanel } from "@/components/ui/side-panel";
22 import { UserSearchSelect } from "@/components/users/user-search-select";23 import { UserSearchSelect } from "@/components/users/user-search-select";
23 import { formatDateTime } from "@/lib/format";24 import { formatDateTime } from "@/lib/format";
@@ -45,27 +46,28 @@ function EventDetailContent() {
45 return params().id;46 return params().id;
46 });47 });
47 48
48- const [event, { refetch: refetchEvent }] = createResource(id, (eventId) => getEventById(eventId));
49- const [attendance, { refetch: refetchAttendance }] = createResource(
50- () => (hasMinRole(auth.user()?.role, "teacher") ? id() : null),
51- async (eventId) => (eventId ? getEventAttendance(eventId) : []),
52- );
53-
54 const [status, setStatus] = createSignal<AttendanceStatus>("present");49 const [status, setStatus] = createSignal<AttendanceStatus>("present");
55 const [otherUserId, setOtherUserId] = createSignal("");50 const [otherUserId, setOtherUserId] = createSignal("");
56 const [editing, setEditing] = createSignal(false);51 const [editing, setEditing] = createSignal(false);
57 const [deleteOpen, setDeleteOpen] = createSignal(false);52 const [deleteOpen, setDeleteOpen] = createSignal(false);
53+ const [attendanceOpen, setAttendanceOpen] = createSignal(false);
58 const [error, setError] = createSignal("");54 const [error, setError] = createSignal("");
59 const [pending, setPending] = createSignal(false);55 const [pending, setPending] = createSignal(false);
60 56
57+ const isTeacherPlus = () => hasMinRole(auth.user()?.role, "teacher");
58+
59+ const [event, { refetch: refetchEvent }] = createResource(id, (eventId) => getEventById(eventId));
60+ const [attendance, { refetch: refetchAttendance }] = createResource(
61+ () => (isTeacherPlus() && attendanceOpen() ? id() : null),
62+ async (eventId) => (eventId ? getEventAttendance(eventId) : []),
63+ );
64+
61 const canManage = () => {65 const canManage = () => {
62 const e = event();66 const e = event();
63 const u = auth.user();67 const u = auth.user();
64 if (!e || !u) return false;68 if (!e || !u) return false;
65 return e.creator === u.id || hasMinRole(u.role, "manager");69 return e.creator === u.id || hasMinRole(u.role, "manager");
66 };70 };
67- const isTeacherPlus = () => hasMinRole(auth.user()?.role, "teacher");
68-
69 const wrap = async (fn: () => Promise<void>) => {71 const wrap = async (fn: () => Promise<void>) => {
70 setError("");72 setError("");
71 setPending(true);73 setPending(true);
@@ -198,7 +200,7 @@ function EventDetailContent() {
198 onClick={() =>200 onClick={() =>
199 void wrap(async () => {201 void wrap(async () => {
200 await postEventAttendance(id(), { status: status() });202 await postEventAttendance(id(), { status: status() });
201- if (isTeacherPlus()) await refetchAttendance();203+ if (attendanceOpen()) await refetchAttendance();
202 })204 })
203 }205 }
204 >206 >
@@ -243,7 +245,7 @@ function EventDetailContent() {
243 user_id: uid,245 user_id: uid,
244 });246 });
245 setOtherUserId("");247 setOtherUserId("");
246- await refetchAttendance();248+ if (attendanceOpen()) await refetchAttendance();
247 })249 })
248 }250 }
249 >251 >
@@ -259,11 +261,12 @@ function EventDetailContent() {
259 )}261 )}
260 262
261 <Show when={isTeacherPlus()}>263 <Show when={isTeacherPlus()}>
262- <section class="data-shell space-y-4 p-4">264+ <SectionDisclosure
263- <div>265+ open={attendanceOpen()}
264- <h2 class="font-display text-lg font-semibold">{t("events.attendance")}</h2>266+ onToggle={() => setAttendanceOpen((open) => !open)}
265- <p class="mt-1 text-sm text-muted-foreground">{t("events.markedBy")}</p>267+ title={t("events.attendance")}
266- </div>268+ description={t("events.markedBy")}
269+ >
267 <Suspense fallback={<PageSpinner />}>270 <Suspense fallback={<PageSpinner />}>
268 <Show when={attendance()}>271 <Show when={attendance()}>
269 {(rows) => (272 {(rows) => (
@@ -281,7 +284,7 @@ function EventDetailContent() {
281 )}284 )}
282 </Show>285 </Show>
283 </Suspense>286 </Suspense>
284- </section>287+ </SectionDisclosure>
285 </Show>288 </Show>
286 </div>289 </div>
287 )}290 )}