From 019f61bc4a96472d46cb66cd5f1045a6e924a561 Mon Sep 17 00:00:00 2001 From: blake Date: Mon, 2 Nov 2026 11:36:22 -0600 Subject: [PATCH] feat: implement event listing and styling for public events Added a new EventListPage component to display published events in a grid layout, enhancing the user interface for event visibility. Updated styles in app.css for public events, including hover effects and improved layout. Modified the main application logic to handle multiple published events and adjusted tests to verify the new functionality and display behavior. --- public/css/app.css | 80 ++++++++++++++++++++++++++++++++++++++ src/admin-pages.tsx | 5 ++- src/app.tsx | 22 +++++++---- src/pages.tsx | 37 +++++++++++++++++- src/schedule.ts | 13 +++++++ tests/public-pages.test.ts | 75 ++++++++++++++++++++++++++++++++++- 6 files changed, 221 insertions(+), 11 deletions(-) diff --git a/public/css/app.css b/public/css/app.css index 6aa5a0c..9c90199 100644 --- a/public/css/app.css +++ b/public/css/app.css @@ -1708,6 +1708,63 @@ article.shift-card { box-shadow: var(--hope-shadow); } +.public-events { + list-style: none; + display: grid; + gap: 1rem; + margin: 1.25rem 0 0; + padding: 0; +} + +.public-event { + display: grid; + gap: 0.2rem; + padding: 1.15rem 1.35rem 1.25rem; + background: #fff; + border-radius: 1.75rem; + box-shadow: var(--hope-shadow); + color: var(--hope-ink); + text-decoration: none; +} + +.public-event:hover, +.public-event:focus-visible { + background: var(--hope-blue-100); + color: var(--hope-ink); + text-decoration: none; +} + +.public-event-title { + font-size: 1.85rem; + font-weight: 500; + letter-spacing: -0.03em; + line-height: 1.2; +} + +.public-event-location, +.public-event-meta { + color: var(--hope-ink-2); +} + +.public-event-description { + white-space: pre-wrap; +} + +.public-event-go { + display: flex; + align-items: center; + justify-content: space-between; + margin-top: 0.55rem; + padding-top: 0.7rem; + border-top: 1px solid var(--hope-border); + font-weight: 650; +} + +.public-event-go img { + width: auto; + height: 1.15rem; +} + /* Forms */ .signup-form, @@ -1899,6 +1956,24 @@ article.shift-card { box-shadow: none; } +.check-copy { + display: grid; + gap: 0.15rem; +} + +.check:has(.check-copy) { + align-items: flex-start; +} + +.check:has(.check-copy) input { + margin-top: 0.2rem; +} + +.check-copy .hint { + font-size: 0.92rem; + line-height: 1.35; +} + .hint { font-weight: 400; color: var(--hope-ink-2); @@ -4842,6 +4917,11 @@ main > .crumb, min-height: 2.75rem; } +.event-fields > .check:has(.check-copy) { + align-items: flex-start; + align-self: start; +} + .event-fields > button { justify-self: end; align-self: center; diff --git a/src/admin-pages.tsx b/src/admin-pages.tsx index 9aa9ed2..03c2234 100644 --- a/src/admin-pages.tsx +++ b/src/admin-pages.tsx @@ -1792,7 +1792,10 @@ function EventForm(props: { )} diff --git a/src/app.tsx b/src/app.tsx index cb4dea1..6ea8ce6 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -5,8 +5,8 @@ import type { Child } from 'hono/jsx'; import { registerAdmin } from './admin-http.js'; import { readSession } from './auth/session.js'; import type { AppConfig } from './config.js'; -import { EmptySchedulePage, EventPage, Layout, NotFoundPage, ProblemPage } from './pages.js'; -import { getPublishedEvent } from './schedule.js'; +import { EmptySchedulePage, EventListPage, EventPage, Layout, NotFoundPage, ProblemPage } from './pages.js'; +import { getPublishedEvent, listPublishedEvents } from './schedule.js'; import { registerReminderOff } from './reminder-http.js'; import { registerPublicSignup } from './signup-http.js'; import { securityHeaders } from './security.js'; @@ -61,17 +61,25 @@ export function createApp( app.get(appPath(config, '/'), (c) => { const at = now(); - const event = getPublishedEvent(db, 'weekly-pantry', at); - if (!event) { - return page(c, config, db, at, 'Weekly pantry · Hope Volunteer', ); + const events = listPublishedEvents(db, at); + const only = events.length === 1 ? events[0] : undefined; + if (only) { + return page( + c, + config, + db, + at, + `${only.title} · Hope Volunteer`, + , + ); } return page( c, config, db, at, - `${event.title} · Hope Volunteer`, - , + 'Volunteer shifts · Hope Volunteer', + events.length === 0 ? : , ); }); diff --git a/src/pages.tsx b/src/pages.tsx index 8a9da2c..83778a7 100644 --- a/src/pages.tsx +++ b/src/pages.tsx @@ -219,12 +219,45 @@ export function Layout(props: { export function EmptySchedulePage() { return ( <> -

Weekly pantry

-

No upcoming shifts are posted.

+

Volunteer shifts

+

No events are posted.

); } +export function EventListPage(props: { config: AppConfig; events: PublicEvent[] }) { + return ( + <> +

Volunteer shifts

+ + + ); +} + +function postedShiftLabel(count: number): string { + if (count === 0) return 'No upcoming shifts are posted.'; + if (count === 1) return '1 upcoming shift'; + return `${count} upcoming shifts`; +} + export function EventPage(props: { config: AppConfig; event: PublicEvent; diff --git a/src/schedule.ts b/src/schedule.ts index 3f2790b..0d88d7d 100644 --- a/src/schedule.ts +++ b/src/schedule.ts @@ -90,6 +90,19 @@ const SHIFT_FROM = ` LEFT JOIN signups su ON su.shift_id = s.id `; +/** Published events in title order. Each entry uses the same upcoming-shift window as its own page. */ +export function listPublishedEvents(db: Database.Database, now: string): PublicEvent[] { + const rows = db + .prepare(`SELECT slug AS slug FROM events WHERE published = 1 ORDER BY title COLLATE NOCASE, id`) + .all() as { slug: string }[]; + const events: PublicEvent[] = []; + for (const row of rows) { + const event = getPublishedEvent(db, row.slug, now); + if (event) events.push(event); + } + return events; +} + export function getPublishedEvent(db: Database.Database, slug: string, now: string): PublicEvent | null { const event = db .prepare( diff --git a/tests/public-pages.test.ts b/tests/public-pages.test.ts index a8f136b..e3f734d 100644 --- a/tests/public-pages.test.ts +++ b/tests/public-pages.test.ts @@ -500,10 +500,83 @@ describe('public pages', () => { expect(later).toContain('Wednesday Sorting'); }); - it('shows an empty list when nothing is upcoming', async () => { + it('shows an empty sign-up page when no event is posted', async () => { const { app } = await buildApp({ empty: true }); const html = await (await app.request('/')).text(); + expect(html).toContain('Volunteer shifts · Hope Volunteer'); + expect(html).toContain('

Volunteer shifts

'); + expect(html).toContain('No events are posted.'); + expect(html).not.toContain('Weekly pantry'); + }); + + it('opens the only published event on the sign-up page', async () => { + const { app, db } = await buildApp({ empty: true }); + const eventId = insertEvent(db, { + slug: 'volunteer-shifts', + title: 'Volunteer Shifts', + description: 'Bring a box.', + published: 1, + }); + insertShift(db, eventId, 'Bagging', '2026-10-21', '09:00', '12:00', 4, 0); + insertEvent(db, { + slug: 'hidden-drive', + title: 'Hidden drive', + description: '', + published: 0, + }); + + const html = await (await app.request('/')).text(); + expect(html).toContain('Volunteer Shifts · Hope Volunteer'); + expect(html).toContain('

Volunteer Shifts

'); + expect(html).toContain('Bring a box.'); + expect(html).toContain('Bagging'); + expect(html).toContain('href="/?view=calendar"'); + expect(html).not.toContain('No events are posted.'); + expect(html).not.toContain('Hidden drive'); + expect(html).not.toContain('Weekly pantry'); + + const event = await app.request('/e/volunteer-shifts'); + expect(event.status).toBe(200); + expect(await event.text()).toContain('Bagging'); + expect((await app.request('/e/hidden-drive')).status).toBe(404); + }); + + it('lists every published event and links to its page', async () => { + const { app, db } = await buildApp(); + const drive = insertEvent(db, { + slug: 'volunteer-shifts', + title: 'Volunteer Shifts', + description: 'Bring a box.', + published: 1, + }); + insertShift(db, drive, 'Bagging', '2026-10-21', '09:00', '12:00', 4, 0); + insertEvent(db, { + slug: 'food-drive', + title: 'Food drive', + description: '', + published: 1, + }); + + const html = await (await app.request('/')).text(); + expect(html).toContain('

Volunteer shifts

'); + expect(html).toContain('aria-label="Published events"'); + expect(html).toContain('View shifts'); + expect(html).toContain('href="/e/food-drive"'); + expect(html).toContain('href="/e/volunteer-shifts"'); + expect(html).toContain('href="/e/weekly-pantry"'); + expect(html).toContain('Bring a box.'); + expect(html).toContain('1 upcoming shift'); + expect(html).toContain('6 upcoming shifts'); expect(html).toContain('No upcoming shifts are posted.'); + expect(html.indexOf('Food drive')).toBeLessThan(html.indexOf('Volunteer Shifts')); + expect(html.indexOf('Volunteer Shifts')).toBeLessThan(html.indexOf('Weekly pantry')); + expect(html).not.toContain('Hidden draft'); + expect(html).not.toContain('Bagging'); + expect(html).not.toContain('class="day-card"'); + + const event = await (await app.request('/e/volunteer-shifts')).text(); + expect(event).toContain('Bagging'); + expect(event).toContain('Bring a box.'); }); });