Skip to content

Commit acfb57c

Browse files
Merge pull request #225 from CodeForPhilly/feat/events-picker-active-projects
feat: the project picker opens on the active projects
2 parents b03f900 + a60aa8c commit acfb57c

10 files changed

Lines changed: 57 additions & 32 deletions

File tree

‎apps/api/src/services/event.ts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,23 @@ export class EventService {
8989
const ids = this.#state.rsvpsByPerson.get(caller.id) ?? new Set<string>();
9090
const named = [...ids]
9191
.map((id) => this.#state.eventRsvps.get(id))
92-
.filter((r): r is EventRsvp => r !== undefined && r.eventId !== eventId && r.plan === 'project' && !!r.projectId)
92+
.filter((r): r is EventRsvp => r !== undefined && r.eventId !== eventId);
93+
return this.#distinctProjects(named, 8);
94+
}
95+
96+
/**
97+
* The last ten distinct projects anyone named on an RSVP to any event,
98+
* most recently answered first — the active projects, so a newcomer's
99+
* picker opens on the teams that actually meet (specs/api/events.md).
100+
*/
101+
recentProjects(): ProjectRef[] {
102+
return this.#distinctProjects([...this.#state.eventRsvps.values()], 10);
103+
}
104+
105+
/** Distinct live projects named on `rsvps`, newest answer first, up to `limit`. */
106+
#distinctProjects(rsvps: EventRsvp[], limit: number): ProjectRef[] {
107+
const named = rsvps
108+
.filter((r) => r.plan === 'project' && !!r.projectId)
93109
.sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));
94110
const out: ProjectRef[] = [];
95111
const seen = new Set<string>();
@@ -98,7 +114,7 @@ export class EventService {
98114
if (!p || p.deletedAt || seen.has(p.id)) continue;
99115
seen.add(p.id);
100116
out.push({ slug: p.slug, title: p.title });
101-
if (out.length === 8) break;
117+
if (out.length === limit) break;
102118
}
103119
return out;
104120
}
@@ -140,6 +156,7 @@ export class EventService {
140156
rsvpCount,
141157
viewerRsvp: this.viewerRsvp(event.id, caller),
142158
viewerRecentProjects: this.viewerRecentProjects(event.id, caller),
159+
recentProjects: this.recentProjects(),
143160
projectLookup: (id) => this.#state.projects.get(id),
144161
series: this.seriesRef(event),
145162
permissions: computeEventPermissions(caller, event, rsvpCount, now),

‎apps/api/src/services/serializers/event.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export interface EventSummaryResponse {
5555
export interface EventResponse extends EventSummaryResponse {
5656
/** Projects the caller named on RSVPs to other events, newest first (specs/api/events.md). */
5757
readonly viewerRecentProjects: ProjectRef[];
58+
/** The last ten distinct projects anyone named on any RSVP, newest first. */
59+
readonly recentProjects: ProjectRef[];
5860
readonly description: string | null;
5961
readonly descriptionHtml: string;
6062
readonly agenda: EventAgendaItemResponse[];
@@ -132,7 +134,11 @@ function serializeAgendaItem(item: EventAgendaItem): EventAgendaItemResponse {
132134

133135
export function serializeEvent(
134136
event: Event,
135-
opts: SerializeEventOptions & { readonly permissions: EventPermissions; readonly viewerRecentProjects: ProjectRef[] },
137+
opts: SerializeEventOptions & {
138+
readonly permissions: EventPermissions;
139+
readonly viewerRecentProjects: ProjectRef[];
140+
readonly recentProjects: ProjectRef[];
141+
},
136142
): EventResponse {
137143
return {
138144
...serializeEventSummary(event, opts),
@@ -142,6 +148,7 @@ export function serializeEvent(
142148
agenda: (event.agenda ?? []).map(serializeAgendaItem),
143149
cancellationNote: event.cancellationNote ?? null,
144150
viewerRecentProjects: opts.viewerRecentProjects,
151+
recentProjects: opts.recentProjects,
145152
permissions: opts.permissions,
146153
};
147154
}

‎apps/api/tests/events.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,10 @@ describe('RSVP', () => {
323323
expect(sameDetail.json().data.viewerRecentProjects).toEqual([]);
324324
const anonDetail = await app!.inject({ method: 'GET', url: `/api/events/${other.slug}` });
325325
expect(anonDetail.json().data.viewerRecentProjects).toEqual([]);
326+
// Every caller sees the active projects: the last ten distinct ones anyone
327+
// named on any RSVP, this event's included.
328+
expect(anonDetail.json().data.recentProjects).toEqual([{ slug: fixtures.projectSlug, title: expect.any(String) }]);
329+
expect(sameDetail.json().data.recentProjects).toEqual([{ slug: fixtures.projectSlug, title: expect.any(String) }]);
326330

327331
const noSlug = await app!.inject({
328332
method: 'PUT',

‎apps/web/src/lib/api.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ export interface EventSummary {
398398
export interface EventDetail extends EventSummary {
399399
/** Projects the viewer named on RSVPs to other events, newest first; `[]` when anonymous. */
400400
readonly viewerRecentProjects: ReadonlyArray<{ readonly slug: string; readonly title: string }>;
401+
/** The last ten distinct projects anyone named on any RSVP, newest first. */
402+
readonly recentProjects: ReadonlyArray<{ readonly slug: string; readonly title: string }>;
401403
readonly description: string | null;
402404
readonly descriptionHtml: string;
403405
readonly cancellationNote: string | null;

‎apps/web/src/screens/EventDetail.tsx‎

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import {
2424
api,
2525
ApiError,
2626
type EventDetail as EventDetailData,
27-
type EventRsvp,
2827
type EventRsvpInput,
2928
type EventRsvpPlan,
3029
type SuccessEnvelope,
@@ -58,28 +57,20 @@ interface FollowUpProps {
5857

5958
/**
6059
* The picker's opened-but-empty suggestions (screens/event-detail.md): the
61-
* viewer's own recent projects from other events first, then the projects
62-
* other attendees of this event named, newest answer first; a project
63-
* appears once, in the first group it belongs to.
60+
* viewer's own recent projects from other events first, then the active
61+
* projects — the last ten distinct ones anyone named on any RSVP; a
62+
* project appears once, in the first group it belongs to.
6463
*/
6564
export function suggestionGroups(
66-
recent: readonly ProjectChoice[],
67-
rsvps: readonly EventRsvp[],
68-
viewerSlug: string | null | undefined,
65+
mine: readonly ProjectChoice[],
66+
active: readonly ProjectChoice[],
6967
): ProjectSuggestionGroup[] {
7068
const seen = new Set<string>();
7169
const take = (list: readonly ProjectChoice[]): ProjectChoice[] =>
7270
list.filter((p) => (seen.has(p.slug) ? false : (seen.add(p.slug), true)));
73-
const mine = take(recent);
74-
const teams = take(
75-
[...rsvps]
76-
.filter((r) => r.project && r.person?.slug !== viewerSlug)
77-
.sort((a, b) => b.updatedAt.localeCompare(a.updatedAt))
78-
.map((r) => ({ slug: r.project!.slug, title: r.project!.title })),
79-
);
8071
return [
81-
{ label: 'Your recent projects', items: mine },
82-
{ label: 'Teams already coming', items: teams },
72+
{ label: 'Your recent projects', items: take(mine) },
73+
{ label: 'Other active projects', items: take(active) },
8374
].filter((g) => g.items.length > 0);
8475
}
8576

@@ -482,7 +473,7 @@ export function EventDetail() {
482473
<FollowUp
483474
plan={event.viewerRsvp?.plan ?? null}
484475
project={event.viewerRsvp?.project ?? null}
485-
groups={suggestionGroups(event.viewerRecentProjects, rsvps, person?.slug)}
476+
groups={suggestionGroups(event.viewerRecentProjects, event.recentProjects)}
486477
busy={rsvpBusy}
487478
onSave={saveFollowUp}
488479
/>

‎apps/web/tests/EventDetail.test.tsx‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ describe('EventDetail', () => {
149149
const box = screen.getByRole('combobox', { name: 'Pick a project' });
150150
expect(box).toHaveAttribute('placeholder', 'Type a project name');
151151
expect(screen.queryByRole('option')).not.toBeInTheDocument();
152-
expect(screen.queryByText('Teams already coming')).not.toBeInTheDocument();
152+
expect(screen.queryByText('Other active projects')).not.toBeInTheDocument();
153153
expect(calls.some((c) => c.url.startsWith('/api/projects'))).toBe(false);
154154

155155
await user.type(box, 'squad');
@@ -167,28 +167,24 @@ describe('EventDetail', () => {
167167
expect(await screen.findByText('I’m coming to work on SquadQuest')).toBeInTheDocument();
168168
});
169169

170-
it('project picker: opened empty offers the viewer’s recent projects, then teams other attendees named, without listing the catalog', async () => {
170+
it('project picker: opened empty offers the viewer’s recent projects, then the other active projects, without listing the catalog', async () => {
171171
const user = userEvent.setup();
172172
const calls = mockFetch({
173173
me: USER_ME,
174174
event: makeEvent({
175175
viewerRsvp: { plan: null, project: null, createdAt: '2026-10-02T00:00:00Z' },
176-
// Named on a previous event; also named by Ada here, so it shows once, under "Your recent projects".
176+
// Alpha is in both lists; it shows once, under "Your recent projects".
177177
viewerRecentProjects: [{ slug: 'squadquest', title: 'SquadQuest' }, { slug: 'alpha', title: 'Alpha' }],
178+
recentProjects: [{ slug: 'zeta', title: 'Zeta' }, { slug: 'alpha', title: 'Alpha' }, { slug: 'omega', title: 'Omega' }],
178179
}),
179-
rsvps: [
180-
makeRsvp('Ada Lovelace', { plan: 'project', project: { slug: 'alpha', title: 'Alpha' }, updatedAt: '2026-10-01T00:00:00Z' }),
181-
makeRsvp('Grace Hopper', { plan: 'project', project: { slug: 'zeta', title: 'Zeta' }, updatedAt: '2026-10-03T00:00:00Z' }),
182-
makeRsvp('Linus T', { plan: 'project', project: { slug: 'alpha', title: 'Alpha' }, updatedAt: '2026-10-02T00:00:00Z' }),
183-
],
184180
});
185181
render();
186182
await screen.findByRole('heading', { name: /Going/ });
187183
await user.click(await screen.findByRole('button', { name: 'I’m coming to work on [Pick a project ▾]' }));
188184

189185
expect(screen.getByText('Your recent projects')).toBeInTheDocument();
190-
expect(screen.getByText('Teams already coming')).toBeInTheDocument();
191-
expect(screen.getAllByRole('option').map((o) => o.textContent)).toEqual(['SquadQuest', 'Alpha', 'Zeta']);
186+
expect(screen.getByText('Other active projects')).toBeInTheDocument();
187+
expect(screen.getAllByRole('option').map((o) => o.textContent)).toEqual(['SquadQuest', 'Alpha', 'Zeta', 'Omega']);
192188
expect(calls.some((c) => c.url.startsWith('/api/projects'))).toBe(false);
193189

194190
await user.click(screen.getByRole('option', { name: 'Alpha' }));

‎apps/web/tests/event-fixtures.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export function makeEvent(overrides: Partial<EventDetail> = {}): EventDetail {
4141
return {
4242
...makeSummary(),
4343
viewerRecentProjects: [],
44+
recentProjects: [],
4445
description: 'Bring a laptop.',
4546
descriptionHtml: '<p>Bring a laptop.</p>',
4647
cancellationNote: null,

‎plans/events-rsvp-project-picker.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ projects, a different and short list).
9292
should come up first. The event detail now carries
9393
`viewerRecentProjects` (the caller's named projects on other events,
9494
newest first) and the picker shows it as the first group.
95+
- Second review: "teams already coming" is empty exactly when a newcomer
96+
needs the list most (a fresh event). The second group is now
97+
`recentProjects` — the last ten distinct projects anyone named on any
98+
RSVP — under "Other active projects", so the picker opens on the teams
99+
that actually meet. Follow-on PR after #223.
95100
- Kept the hand-rolled combobox (same shape as `SeriesPicker`) rather than
96101
adopting shadcn's Popover + Command; decided with Chris for launch.
97102

‎specs/api/events.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ Hard delete. Permitted only when `status = draft` or the event has no RSVPs. Rem
281281
"rsvpCount": 14,
282282
"viewerRsvp": { "plan": "project" | "newcomer" | "no_project" | null, "project": { "slug": "squadquest", "title": "SquadQuest" } | null, "createdAt": "..." } | null,
283283
"viewerRecentProjects": [ { "slug": "squadquest", "title": "SquadQuest" } ],
284+
"recentProjects": [ { "slug": "philly-bike-action", "title": "Philly Bike Action" }, "…" ],
284285
"icsUrl": "/api/events/2026-11-03-hack-night/ics",
285286
"permissions": {
286287
"canRsvp": true,
@@ -298,6 +299,7 @@ Hard delete. Permitted only when `status = draft` or the event has no RSVPs. Rem
298299
- `rsvpCount` counts going RSVPs.
299300
- `viewerRsvp` is `null` for anonymous callers and for members who haven't RSVP'd.
300301
- `viewerRecentProjects` is the projects the caller named on their RSVPs to *other* events, most recently answered first, de-duplicated, at most eight — what the follow-up's project picker offers before anything is typed ([screens/event-detail.md](../screens/event-detail.md)). `[]` for anonymous callers. Detail only; the list shape omits it.
302+
- `recentProjects` is the last ten distinct projects anyone named on an RSVP to any event, most recently answered first — the active projects, so a newcomer's picker opens on the teams that actually meet rather than a search box. Same for every caller. Detail only.
301303
- `permissions.canRsvp` is `true` exactly when a `PUT …/rsvp` from this caller would succeed (signed in, event `scheduled`, `endsAt > now`). Anonymous callers get `false`; the client renders "Sign in to RSVP" from the auth context.
302304
- `icsSequence`, `reminders`, and `createdById` are internal and not serialized.
303305

‎specs/screens/event-detail.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Legacy laddr URLs of the same shape resolve directly because the backfilled hist
1010

1111
- `GET /api/events/:slug` — full Event with `viewerRsvp` and `permissions`
1212
- `GET /api/events/:slug/rsvps?perPage=100` — attendee list (lazy after first paint)
13-
- `GET /api/projects?q=<typed>&perPage=8` — only while the viewer is going and typing in the follow-up's project picker (lazy, debounced); the picker's opened-but-empty suggestions come from the event's `viewerRecentProjects` and the attendee list, both already loaded
13+
- `GET /api/projects?q=<typed>&perPage=8` — only while the viewer is going and typing in the follow-up's project picker (lazy, debounced); the picker's opened-but-empty suggestions come from the event's `viewerRecentProjects` and `recentProjects`, already loaded
1414
- `GET /api/auth/me`
1515

1616
Unknown slug, or a draft and the caller isn't staff: 404 page.
@@ -44,7 +44,7 @@ Across the top of the content area, before the title:
4444
| ------------ | -------- |
4545
| Anonymous, RSVPs open | Button "Sign in to RSVP" → `/login?return=/events/<slug>`; helper "Your name will appear on the attendee list." |
4646
| Signed in, not going, RSVPs open | Primary button "I'm going"; same helper text |
47-
| Signed in, going, RSVPs open | Success state "You're going ✓" with a quiet "Can't make it?" link that withdraws (confirm); below it the **follow-up** per [behaviors/events.md](../behaviors/events.md#the-follow-up-what-are-you-coming-to-do): the prompt "What are you coming to do? (optional)" with three choices — "I'm new to Code for Philly", "I don't have a project yet", "I'm coming to work on [Pick a project ▾]". The picker is a find-as-you-type combobox that never lists the whole catalog: opened with nothing typed, it offers two groups — "Your recent projects", the projects the member named on their own RSVPs to other events (`viewerRecentProjects`, newest first), then "Teams already coming", the projects other attendees of this event have named, most recent answer first — each at most eight, a project appearing once in the first group it belongs to, empty groups omitted; when both are empty, nothing but the input's own hint "Type a project name"; once the member types, it searches projects by title and text (`GET /api/projects?q=`), showing at most eight in relevance order, or "No projects match". Arrow keys, Enter and Escape work as in any combobox. Selecting a choice saves immediately; the chosen one shows as selected with a "Change" affordance. Unanswered shows the three choices; never a blank. |
47+
| Signed in, going, RSVPs open | Success state "You're going ✓" with a quiet "Can't make it?" link that withdraws (confirm); below it the **follow-up** per [behaviors/events.md](../behaviors/events.md#the-follow-up-what-are-you-coming-to-do): the prompt "What are you coming to do? (optional)" with three choices — "I'm new to Code for Philly", "I don't have a project yet", "I'm coming to work on [Pick a project ▾]". The picker is a find-as-you-type combobox that never lists the whole catalog: opened with nothing typed, it offers two groups — "Your recent projects", the projects the member named on their own RSVPs to other events (`viewerRecentProjects`, newest first), then "Other active projects", the last ten distinct projects anyone named on any RSVP (`recentProjects`, newest first) — a project appearing once in the first group it belongs to, empty groups omitted, so a newcomer sees the teams that actually meet without searching; only when both are empty, nothing but the input's own hint "Type a project name"; once the member types, it searches projects by title and text (`GET /api/projects?q=`), showing at most eight in relevance order, or "No projects match". Arrow keys, Enter and Escape work as in any combobox. Selecting a choice saves immediately; the chosen one shows as selected with a "Change" affordance. Unanswered shows the three choices; never a blank. |
4848
| RSVPs closed (cancelled, past) | No control; the count line still renders |
4949

5050
Under the control: "14 going" linked to the attendee list anchor. When `meetupUrl` is set, a small muted "Also listed on Meetup ↗" link sits *below* everything in this block, never beside the button.

0 commit comments

Comments
 (0)