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.
This commit is contained in:
blake committed 2026-11-02 11:36:22 -06:00
1 parent e7fc1e03ae
commit 019f61bc4a
6 files changed
+221 -11

No files matched your search

+4 -1
View File
@@ -1792,7 +1792,10 @@ function EventForm(props: {
)}
<label class="check">
<input type="checkbox" name="published" value="yes" checked={props.values.published ? true : undefined} />
Show this event on the public list
<span class="check-copy">
Show this event on the public list
<span class="hint">The sign-up page lists every checked event. When only one event is checked, its shifts open directly.</span>
</span>
</label>
<button type="submit">{props.submitLabel}</button>
</form>
+15 -7
View File
@@ -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', <EmptySchedulePage />);
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`,
<EventPage config={config} event={only} now={at} month={c.req.query('month')} view={c.req.query('view')} path="/" />,
);
}
return page(
c,
config,
db,
at,
`${event.title} · Hope Volunteer`,
<EventPage config={config} event={event} now={at} month={c.req.query('month')} view={c.req.query('view')} path="/" />,
'Volunteer shifts · Hope Volunteer',
events.length === 0 ? <EmptySchedulePage /> : <EventListPage config={config} events={events} />,
);
});
+35 -2
View File
@@ -219,12 +219,45 @@ export function Layout(props: {
export function EmptySchedulePage() {
return (
<>
<h1>Weekly pantry</h1>
<p class="empty">No upcoming shifts are posted.</p>
<h1>Volunteer shifts</h1>
<p class="empty">No events are posted.</p>
</>
);
}
export function EventListPage(props: { config: AppConfig; events: PublicEvent[] }) {
return (
<>
<h1>Volunteer shifts</h1>
<ul class="public-events" aria-label="Published events">
{props.events.map((event) => {
const description = event.description.trim();
return (
<li key={event.id}>
<a class="public-event" href={appPath(props.config, `/e/${encodeURIComponent(event.slug)}`)}>
<span class="public-event-title">{event.title}</span>
{event.location ? <span class="public-event-location">{event.location}</span> : null}
{description ? <span class="public-event-description">{description}</span> : null}
<span class="public-event-meta">{postedShiftLabel(event.shifts.length)}</span>
<span class="public-event-go">
View shifts
<img src={asset(props.config, '/img/icons/right-arrow.svg')} alt="" />
</span>
</a>
</li>
);
})}
</ul>
</>
);
}
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;
+13
View File
@@ -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(