From 208f08753e731e640e9d4475c24fb573847af85e Mon Sep 17 00:00:00 2001 From: blake Date: Wed, 28 Oct 2026 16:07:37 -0500 Subject: [PATCH] feat: update shift display logic and styles for ended shifts Enhanced the user interface to visually indicate when shifts have ended, including graying out past shifts and adding labels for clarity. Updated styles for both the public and admin views to reflect these changes, ensuring a consistent experience. Adjusted the logic to keep ended shifts visible until midnight in their respective time zones, improving user understanding of shift availability. --- README.md | 2 +- public/css/app.css | 55 ++++++++++++++++++++++++++++++++++++-- src/admin-pages.tsx | 2 +- src/pages.tsx | 15 ++++++++--- src/schedule.ts | 8 +++--- tests/public-pages.test.ts | 41 +++++++++++++++++++++++++--- 6 files changed, 108 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index a830651..263c8be 100644 --- a/README.md +++ b/README.md @@ -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. 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 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. 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. diff --git a/public/css/app.css b/public/css/app.css index cc7b333..a35c767 100644 --- a/public/css/app.css +++ b/public/css/app.css @@ -37,6 +37,8 @@ --hope-open-edge: #c5d7b4; --hope-full: #f6e2de; --hope-full-edge: #e4c4be; + --hope-blue-quiet: #d7ebf8; + --hope-blue-quiet-ink: #2d5f86; --hope-scrollbar-size: 14px; --hope-scrollbar-thumb: var(--hope-gold); --hope-scrollbar-thumb-hover: color-mix(in srgb, var(--hope-gold) 72%, var(--hope-ink)); @@ -849,13 +851,42 @@ main a:hover { background: var(--hope-blue-50); } +.shift-pane.is-ended::after { + content: ""; + position: absolute; + inset: 0; + z-index: 1; + background: rgb(255 255 255 / 0.5); + pointer-events: none; +} + +.shift-pane.is-ended { + position: relative; +} + +/* Full is two lines and Sign up uses the large type. One height keeps that band even. */ +.shift-pane > .btn-card { + min-height: calc(1.7rem + 2.125rem); +} + .shift-pane-body { display: grid; + align-content: start; gap: 0.15rem; flex: 1; padding: 1rem 1.2rem 0.85rem; } +/* A shift with no status line still holds that row when a neighbor has one, so the pills line up. */ +.shift-pane-body > .status:empty { + display: none; +} + +.day-card-shifts:has(.status:not(:empty)) .shift-pane-body > .status:empty { + display: block; + min-height: 1.7em; +} + .shift-pane-body h3 { margin-bottom: 0.15rem; } @@ -1140,6 +1171,25 @@ main a:hover { background: rgb(255 255 255 / 0.45); } +.cal-shift.is-ended { + position: relative; +} + +.cal-shift.is-ended .cal-line { + position: relative; +} + +.cal-shift.is-ended .cal-line::after, +.cal-shift.is-ended .cal-detail::after { + content: ""; + position: absolute; + inset: 0; + z-index: 1; + border-radius: inherit; + background: rgb(255 255 255 / 0.5); + pointer-events: none; +} + .cal-hold { position: absolute; z-index: 2; @@ -2647,8 +2697,8 @@ button.btn-quiet::before { } .need-pill.is-public { - background: #d7ebf8; - color: #2d5f86; + background: var(--hope-blue-quiet); + color: var(--hope-blue-quiet-ink); font-weight: 600; } @@ -3724,6 +3774,7 @@ button.btn-quiet::before { .cal-detail .spots.is-full { margin-top: 0.25rem; } + } /* Wider hamburger layout: one even week row, shifts open underneath it. */ diff --git a/src/admin-pages.tsx b/src/admin-pages.tsx index 288145f..971f4b1 100644 --- a/src/admin-pages.tsx +++ b/src/admin-pages.tsx @@ -1251,7 +1251,7 @@ function ShiftList(props: { config: AppConfig; event: AdminEvent; csrf: string;
?

- Shifts show on the public list when this event is public, the shift is not cancelled, and it has not ended. Repeating shifts add dates for the next three months. Add weekly shifts fills those dates. Shifts already on the schedule stay as they are, including cancelled ones. + Shifts show on the public list when this event is public and the shift is not cancelled. A shift that has already ended stays on today's card, grayed out, until midnight. Then that day leaves the list. Repeating shifts add dates for the next three months. Add weekly shifts fills those dates. Shifts already on the schedule stay as they are, including cancelled ones.

diff --git a/src/pages.tsx b/src/pages.tsx index 97ad4d8..cb3d041 100644 --- a/src/pages.tsx +++ b/src/pages.tsx @@ -673,16 +673,20 @@ function ShiftPane(props: { config: AppConfig; shift: PublicShift }) { const closed = shift.full || shift.cancelled || shift.ended; const action = closed ? 'View shift' : 'Sign up'; return ( -
+

{shift.role}

- {shift.inProgress ?

In progress

: null} +

{shift.inProgress ? 'In progress' : ''}

Volunteers

- {shift.full ? ( + {shift.ended ? ( +

+ Ended +

+ ) : shift.full ? (

Full Not accepting more signups @@ -860,14 +864,16 @@ function CalendarShift(props: { config: AppConfig; shift: PublicShift }) { const closed = shift.full || shift.cancelled || shift.ended; const action = closed ? 'View shift' : 'Sign up'; return ( - + {shift.when.startLabel} {shift.role} + {shift.ended ? ' · Ended' : ''} {'. '} {action} for {shift.role} on {shift.when.dateLabel}, {shift.when.startLabel} to {shift.when.endLabel}{' '} {shift.when.abbreviation}. {spotsSentence(shift)} + {shift.ended ? ' Ended.' : ''} {shift.inProgress ? ' In progress.' : ''} {shift.volunteers.length > 0 ? ` Volunteers: ${shift.volunteers.join(', ')}.` : ' No one signed up yet.'} @@ -880,6 +886,7 @@ function CalendarShift(props: { config: AppConfig; shift: PublicShift }) { {shift.when.sameDay ? null : } {shift.when.abbreviation} + {shift.ended ? Ended : null} {shift.inProgress ? In progress : null} {shift.volunteers.length > 0 ? shift.volunteers.join(', ') : 'No one signed up yet.'} diff --git a/src/schedule.ts b/src/schedule.ts index ef4da9d..5948e70 100644 --- a/src/schedule.ts +++ b/src/schedule.ts @@ -1,7 +1,7 @@ import { Temporal } from '@js-temporal/polyfill'; import type Database from 'better-sqlite3'; import { isWithinSignupWindow } from './signup-window.js'; -import { formatInstantInZone, todayInZone } from './time.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; @@ -110,15 +110,17 @@ export function getPublishedEvent(db: Database.Database, slug: string, now: stri } | undefined; if (!event || event.published !== 1) return null; + // A shift that already ended stays through the rest of its local day, then leaves at midnight. + const todayStart = localToUtc(todayInZone(event.tz, Temporal.Instant.from(now)), '00:00', event.tz); const rows = db .prepare( `SELECT ${SHIFT_COLUMNS} ${SHIFT_FROM} - WHERE e.id = ? AND s.cancelled = 0 AND s.ends_at_utc > ? + WHERE e.id = ? AND s.cancelled = 0 AND (s.ends_at_utc > ? OR s.starts_at_utc >= ?) GROUP BY s.id ORDER BY s.starts_at_utc, s.role, s.id`, ) - .all(event.id, now) as ShiftRow[]; + .all(event.id, now, todayStart) as ShiftRow[]; const names = volunteerNamesByShift(db, rows.map((row) => row.id)); return { id: event.id, diff --git a/tests/public-pages.test.ts b/tests/public-pages.test.ts index b3900a9..59c9531 100644 --- a/tests/public-pages.test.ts +++ b/tests/public-pages.test.ts @@ -48,7 +48,8 @@ describe('public pages', () => { expect(html).toContain('class="day-card"'); expect(html).toContain('class="shift-pane"'); expect(html.match(/class="day-card"/g)).toHaveLength(2); - expect(html.match(/class="shift-pane"/g)).toHaveLength(3); + expect(html.match(/

{ expect(footer).not.toContain('Privacy'); expect(footer).not.toContain('Coordinator'); expect(html).not.toContain('Cancelled Distribution'); - expect(html).not.toContain('Past Setup'); + 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).not.toContain('secret.person@example.invalid'); @@ -126,6 +128,10 @@ describe('public pages', () => { expect(calendar).toContain('1/3 spots filled'); expect(calendar).toContain('1/1 spots filled'); expect(calendar).toContain('class="cal-line"'); + expect(calendar).toContain('Past Setup'); + expect(calendar).toContain('class="cal-shift is-ended"'); + expect(calendar).toContain('· Ended'); + expect(calendar).toContain(`href="/s/${ids.past}"`); expect(calendar).toContain('class="cal-hold"'); expect(calendar).toContain('class="cal-detail"'); expect(calendar).toContain('>Sun'); @@ -460,6 +466,33 @@ describe('public pages', () => { expect(openPane).toContain('data-signup=""'); }); + it('keeps a finished shift on today and drops that day at midnight', 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, 'Yesterday Setup', '2026-10-13', '09:00', '12:00', 2, 0); + const html = await (await app.request('/')).text(); + expect(html).not.toContain('Yesterday Setup'); + const start = html.indexOf('Past Setup'); + const pane = html.slice(html.lastIndexOf('
', start)); + expect(pane).toContain('>Ended'); + expect(pane).toContain('9:00 AM'); + expect(pane).not.toContain('href='); + expect(pane).not.toContain('data-signup'); + expect(pane).not.toContain('Sign up'); + const todayCard = html.slice(html.indexOf('aria-current="date"'), html.indexOf('October 21')); + expect(todayCard).toContain('Past Setup'); + expect(todayCard).toContain('Live Greeting'); + expect(todayCard).toContain('is-ended'); + + const { app: nextDay } = await buildApp({ now: '2026-10-15T05:00:00.000Z' }); + const later = await (await nextDay.request('/')).text(); + expect(later).not.toContain('Past Setup'); + expect(later).not.toContain('Live Greeting'); + expect(later).not.toContain('October 14'); + expect(later).not.toContain('is-ended'); + expect(later).toContain('Wednesday Sorting'); + }); + it('shows an empty list when nothing is upcoming', async () => { const { app } = await buildApp({ empty: true }); const html = await (await app.request('/')).text(); @@ -467,7 +500,7 @@ describe('public pages', () => { }); }); -async function buildApp(options?: { basePath?: string; empty?: boolean }) { +async function buildApp(options?: { basePath?: string; empty?: boolean; now?: string }) { const dataDir = path.join(mkdtempSync(path.join(tmpdir(), 'hope-volunteer-')), 'data'); dirs.push(path.dirname(dataDir)); const config = loadConfig( @@ -479,7 +512,7 @@ async function buildApp(options?: { basePath?: string; empty?: boolean }) { const db = await openAppDatabase(config); databases.push(db); const ids = options?.empty ? emptyIds() : seedCatalog(db); - const app = createApp(config, db, { now: NOW, publicDir: publicDirectory() }); + const app = createApp(config, db, { now: options?.now ?? NOW, publicDir: publicDirectory() }); return { app, ids, db, close: () => db.close() }; }