refactor: generalize shift display from Wednesday to any day

Updated the shift display logic to accommodate shifts on any day of the week instead of just Wednesday. Renamed components and functions for clarity, and adjusted the README to reflect these changes. Enhanced tests to ensure proper functionality across all days.
This commit is contained in:
blake committed 2026-10-29 10:28:52 -05:00
1 parent a0fa56202e
commit 096d1a2b9f
4 files changed
+24 -23

No files matched your search

+1 -1
View File
@@ -70,7 +70,7 @@ npm run seed
`npm run dev` serves the site on `127.0.0.1` at `BASE_URL` (from `.env`, `http://127.0.0.1:3000`). It is loopback only. Stop it with Ctrl+C.
Open `/` for the weekly pantry sign-up page. **View** starts on **List**: a card for each Wednesday in the next three months, split into that day's shifts. Each shift lists the names of the people who are signed up. A shift that has already ended stays on that day's card, grayed out, until midnight in the event's time zone. At midnight the day leaves the list. Emails, phone numbers, and notes stay off the page. **Calendar** is the other choice in that menu, at `/?view=calendar`, and it stops at that same three-month date. A shift later than that date is left off both views, and the signup form does not take a reservation for it. Shifts on other weekdays stay on the calendar. `/e/weekly-pantry` is the same seeded event. `/privacy` is the unapproved privacy notice. `/healthz` returns `{"ok":true,"database":"ok"}` and nothing else. A shift shows how many spots are filled, such as 3/5 spots filled. A shift with space left uses a soft green label. A full shift uses a soft red label.
Open `/` for the weekly pantry sign-up page. **View** starts on **List**: a card for each day with a shift in the next three months, split into that day's shifts. Each shift lists the names of the people who are signed up. A shift that has already ended stays on that day's card, grayed out, until midnight in the event's time zone. At midnight the day leaves the list. Emails, phone numbers, and notes stay off the page. **Calendar** is the other choice in that menu, at `/?view=calendar`, and it stops at that same three-month date. A shift later than that date is left off both views, and the signup form does not take a reservation for it. `/e/weekly-pantry` is the same seeded event. `/privacy` is the unapproved privacy notice. `/healthz` returns `{"ok":true,"database":"ok"}` and nothing else. A shift shows how many spots are filled, such as 3/5 spots filled. A shift with space left uses a soft green label. A full shift uses a soft red label.
An open shift has a signup form. It asks for one person. Another person can use the same email and takes another spot. The same person cannot take a second spot. The form needs JavaScript because of the Turnstile check. Wait a few seconds after the page loads before submitting. The confirmation page shows a private link and says a confirmation email is on the way. That page works without JavaScript. Cancel this signup there to open the spot again. A cancellation email is queued, and a confirmation that has not been sent yet is dropped. That person can sign up again once the cancellation is saved. Someone else can use the email while the first signup is still confirmed. A cancelled signup stays on that private page until the link expires. A private link controls only that signup. Use the separate link for each signup.
+11 -10
View File
@@ -1,7 +1,7 @@
import type { Child } from 'hono/jsx';
import type { AppConfig } from './config.js';
import { WEEKDAY_SHORT, calendarMonth, calendarToday, chooseCalendarMonth, monthStep, type CalendarDay } from './calendar.js';
import { WEDNESDAY, spotsSentence, type PublicEvent, type PublicShift } from './schedule.js';
import { spotsSentence, type PublicEvent, type PublicShift } from './schedule.js';
import { SIGNUP_TOO_EARLY, signupDeadlineLabel } from './signup-window.js';
import { partyChoiceLabel, partyChoices, type SignupErrors, type SignupValues } from './signup-form.js';
import type { MoveTarget } from './admin/store.js';
@@ -590,7 +590,7 @@ function PublicSchedule(props: {
{calendarView ? (
<ShiftCalendar config={props.config} event={props.event} now={props.now} month={props.month} path={props.path} />
) : (
<WednesdayBoard config={props.config} event={props.event} now={props.now} />
<DayBoard config={props.config} event={props.event} now={props.now} />
)}
<SignupDialog config={props.config} />
</div>
@@ -613,16 +613,16 @@ function SignupDialog(props: { config: AppConfig }) {
);
}
type WednesdayGroup = {
type DayGroup = {
date: string;
heading: string;
weekdayLabel: string;
shifts: PublicShift[];
};
function wednesdayGroups(shifts: PublicShift[]): WednesdayGroup[] {
const groups: WednesdayGroup[] = [];
function dayGroups(shifts: PublicShift[]): DayGroup[] {
const groups: DayGroup[] = [];
for (const shift of shifts) {
if (shift.when.weekday !== WEDNESDAY) continue;
const last = groups.at(-1);
if (last && last.date === shift.when.date) {
last.shifts.push(shift);
@@ -631,6 +631,7 @@ function wednesdayGroups(shifts: PublicShift[]): WednesdayGroup[] {
groups.push({
date: shift.when.date,
heading: comma === -1 ? shift.when.dateLabel : shift.when.dateLabel.slice(comma + 2),
weekdayLabel: shift.when.weekdayLabel,
shifts: [shift],
});
}
@@ -638,11 +639,11 @@ function wednesdayGroups(shifts: PublicShift[]): WednesdayGroup[] {
return groups;
}
function WednesdayBoard(props: { config: AppConfig; event: PublicEvent; now: string }) {
function DayBoard(props: { config: AppConfig; event: PublicEvent; now: string }) {
const today = calendarToday(props.event.timeZone, props.now);
const days = wednesdayGroups(props.event.shifts);
const days = dayGroups(props.event.shifts);
if (days.length === 0) {
return <p class="empty">No Wednesday shifts are posted. The calendar lists shifts on other days.</p>;
return <p class="empty">No upcoming shifts are posted.</p>;
}
return (
<ol class="day-board">
@@ -650,7 +651,7 @@ function WednesdayBoard(props: { config: AppConfig; event: PublicEvent; now: str
<li key={day.date}>
<article class="day-card" aria-current={day.date === today ? 'date' : undefined}>
<header class="day-card-head">
<p class="day-card-dow">Wednesday</p>
<p class="day-card-dow">{day.weekdayLabel}</p>
<h2>
<time dateTime={day.date}>{day.heading}</time>
</h2>
+1 -3
View File
@@ -3,9 +3,7 @@ import type Database from 'better-sqlite3';
import { isWithinSignupWindow } from './signup-window.js';
import { formatInstantInZone, localToUtc, todayInZone } from './time.js';
/** Weekday 0 is Sunday, matching the zoned clock. The public sign-up cards use Wednesday. */
export const WEDNESDAY = 3;
/** Weekday 0 is Sunday, matching the zoned clock. */
const WEEKDAY_LABELS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] as const;
export type PublicShift = {
+11 -9
View File
@@ -47,12 +47,14 @@ describe('public pages', () => {
expect(html).toContain('No one signed up yet.');
expect(html).toContain('class="day-card"');
expect(html).toContain('class="shift-pane"');
expect(html.match(/class="day-card"/g)).toHaveLength(2);
expect(html.match(/<section class="shift-pane/g)).toHaveLength(4);
expect(html.match(/class="day-card"/g)).toHaveLength(4);
expect(html.match(/<section class="shift-pane/g)).toHaveLength(6);
expect(html.match(/class="shift-pane is-ended"/g)).toHaveLength(1);
expect(html).not.toContain('shift-calendar');
expect(html).not.toContain('Open Sorting');
expect(html).not.toContain('Full Intake');
expect(html).toContain('class="day-card-dow">Thursday');
expect(html).toContain('class="day-card-dow">Friday');
expect(html).toContain('Open Sorting');
expect(html).toContain('Full Intake');
expect(html).toContain('Today');
expect(html).toContain('aria-current="date"');
expect(html).toContain('In progress');
@@ -84,7 +86,7 @@ describe('public pages', () => {
expect(html).toContain('Past Setup');
expect(html).not.toContain(`href="/s/${ids.past}"`);
expect(html).not.toContain('Hidden draft');
expect(html).not.toContain('Secret Person');
expect(html).toContain('Secret Person');
expect(html).not.toContain('secret.person@example.invalid');
expect(html).not.toContain('lane.wednesday@example.invalid');
expect(html).not.toContain('SECRET-PERSON-NOTE');
@@ -299,7 +301,7 @@ describe('public pages', () => {
expect(await health.json()).toEqual({ ok: true, database: 'ok' });
});
it('shows Wednesday cards by default and one calendar month at a time', async () => {
it('shows every shift in the list and one calendar month at a time', async () => {
const { app, db } = await buildApp();
const event = db.prepare(`SELECT id AS id FROM events WHERE slug = 'weekly-pantry'`).get() as { id: number };
insertShift(db, event.id, 'November Sorting', '2026-11-04', '09:00', '12:00', 4, 0);
@@ -310,8 +312,8 @@ describe('public pages', () => {
expect(html).toContain('Wednesday Sorting');
expect(html).toContain('November Sorting');
expect(html).toContain('December Sorting');
expect(html).not.toContain('Edge Sorting');
expect(html).not.toContain('Open Sorting');
expect(html).toContain('Edge Sorting');
expect(html).toContain('Open Sorting');
expect(html).not.toContain('shift-calendar');
expect(html).not.toContain('Next month');
expect(home).toContain('href="/?view=calendar"');
@@ -385,7 +387,7 @@ describe('public pages', () => {
expect(cards).toContain('Window Person');
expect(cards).not.toContain('window.person@example.invalid');
expect(cards).not.toContain('WINDOW-NOTE');
expect(cards).not.toContain('Deadline Sorting');
expect(cards).toContain('Deadline Sorting');
expect(cards).not.toContain('Later Sorting');
expect(cards).not.toContain('Spring Sorting');
expect(cards).toContain('Sign-up is open through January 14, 2027.');