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:
1 parent
e7fc1e03ae
commit
019f61bc4a
6 files changed
+220
-10
No files matched your search
@@ -1708,6 +1708,63 @@ article.shift-card {
|
|||||||
box-shadow: var(--hope-shadow);
|
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 */
|
/* Forms */
|
||||||
|
|
||||||
.signup-form,
|
.signup-form,
|
||||||
@@ -1899,6 +1956,24 @@ article.shift-card {
|
|||||||
box-shadow: none;
|
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 {
|
.hint {
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
color: var(--hope-ink-2);
|
color: var(--hope-ink-2);
|
||||||
@@ -4842,6 +4917,11 @@ main > .crumb,
|
|||||||
min-height: 2.75rem;
|
min-height: 2.75rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.event-fields > .check:has(.check-copy) {
|
||||||
|
align-items: flex-start;
|
||||||
|
align-self: start;
|
||||||
|
}
|
||||||
|
|
||||||
.event-fields > button {
|
.event-fields > button {
|
||||||
justify-self: end;
|
justify-self: end;
|
||||||
align-self: center;
|
align-self: center;
|
||||||
|
|||||||
@@ -1792,7 +1792,10 @@ function EventForm(props: {
|
|||||||
)}
|
)}
|
||||||
<label class="check">
|
<label class="check">
|
||||||
<input type="checkbox" name="published" value="yes" checked={props.values.published ? true : undefined} />
|
<input type="checkbox" name="published" value="yes" checked={props.values.published ? true : undefined} />
|
||||||
|
<span class="check-copy">
|
||||||
Show this event on the public list
|
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>
|
</label>
|
||||||
<button type="submit">{props.submitLabel}</button>
|
<button type="submit">{props.submitLabel}</button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
+15
-7
@@ -5,8 +5,8 @@ import type { Child } from 'hono/jsx';
|
|||||||
import { registerAdmin } from './admin-http.js';
|
import { registerAdmin } from './admin-http.js';
|
||||||
import { readSession } from './auth/session.js';
|
import { readSession } from './auth/session.js';
|
||||||
import type { AppConfig } from './config.js';
|
import type { AppConfig } from './config.js';
|
||||||
import { EmptySchedulePage, EventPage, Layout, NotFoundPage, ProblemPage } from './pages.js';
|
import { EmptySchedulePage, EventListPage, EventPage, Layout, NotFoundPage, ProblemPage } from './pages.js';
|
||||||
import { getPublishedEvent } from './schedule.js';
|
import { getPublishedEvent, listPublishedEvents } from './schedule.js';
|
||||||
import { registerReminderOff } from './reminder-http.js';
|
import { registerReminderOff } from './reminder-http.js';
|
||||||
import { registerPublicSignup } from './signup-http.js';
|
import { registerPublicSignup } from './signup-http.js';
|
||||||
import { securityHeaders } from './security.js';
|
import { securityHeaders } from './security.js';
|
||||||
@@ -61,17 +61,25 @@ export function createApp(
|
|||||||
|
|
||||||
app.get(appPath(config, '/'), (c) => {
|
app.get(appPath(config, '/'), (c) => {
|
||||||
const at = now();
|
const at = now();
|
||||||
const event = getPublishedEvent(db, 'weekly-pantry', at);
|
const events = listPublishedEvents(db, at);
|
||||||
if (!event) {
|
const only = events.length === 1 ? events[0] : undefined;
|
||||||
return page(c, config, db, at, 'Weekly pantry · Hope Volunteer', <EmptySchedulePage />);
|
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(
|
return page(
|
||||||
c,
|
c,
|
||||||
config,
|
config,
|
||||||
db,
|
db,
|
||||||
at,
|
at,
|
||||||
`${event.title} · Hope Volunteer`,
|
'Volunteer shifts · Hope Volunteer',
|
||||||
<EventPage config={config} event={event} now={at} month={c.req.query('month')} view={c.req.query('view')} path="/" />,
|
events.length === 0 ? <EmptySchedulePage /> : <EventListPage config={config} events={events} />,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+35
-2
@@ -219,12 +219,45 @@ export function Layout(props: {
|
|||||||
export function EmptySchedulePage() {
|
export function EmptySchedulePage() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h1>Weekly pantry</h1>
|
<h1>Volunteer shifts</h1>
|
||||||
<p class="empty">No upcoming shifts are posted.</p>
|
<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: {
|
export function EventPage(props: {
|
||||||
config: AppConfig;
|
config: AppConfig;
|
||||||
event: PublicEvent;
|
event: PublicEvent;
|
||||||
|
|||||||
@@ -90,6 +90,19 @@ const SHIFT_FROM = `
|
|||||||
LEFT JOIN signups su ON su.shift_id = s.id
|
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 {
|
export function getPublishedEvent(db: Database.Database, slug: string, now: string): PublicEvent | null {
|
||||||
const event = db
|
const event = db
|
||||||
.prepare(
|
.prepare(
|
||||||
|
|||||||
@@ -500,10 +500,83 @@ describe('public pages', () => {
|
|||||||
expect(later).toContain('Wednesday Sorting');
|
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 { app } = await buildApp({ empty: true });
|
||||||
const html = await (await app.request('/')).text();
|
const html = await (await app.request('/')).text();
|
||||||
|
expect(html).toContain('<title>Volunteer shifts · Hope Volunteer</title>');
|
||||||
|
expect(html).toContain('<h1>Volunteer shifts</h1>');
|
||||||
|
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('<title>Volunteer Shifts · Hope Volunteer</title>');
|
||||||
|
expect(html).toContain('<h1>Volunteer Shifts</h1>');
|
||||||
|
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('<h1>Volunteer shifts</h1>');
|
||||||
|
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).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.');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user