Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/TheForum-clean
Submodule TheForum-clean added at 1211e9
43 changes: 36 additions & 7 deletions apps/web/src/actions/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export interface FeedEvent {
orgId: string | null;
orgName: string | null;
datetime: string;
datetimeIso?: string;
endDatetimeIso?: string;
location: string;
tags: string[];
flyerUrl: string | null;
Expand Down Expand Up @@ -754,6 +756,7 @@ export async function getMyEvents(): Promise<{
title: events.title,
description: events.description,
datetime: events.datetime,
endDatetime: events.endDatetime,
flyerUrl: events.flyerUrl,
locationName: campusLocations.name,
orgId: events.orgId,
Expand All @@ -772,6 +775,7 @@ export async function getMyEvents(): Promise<{
title: events.title,
description: events.description,
datetime: events.datetime,
endDatetime: events.endDatetime,
flyerUrl: events.flyerUrl,
locationName: campusLocations.name,
orgId: events.orgId,
Expand All @@ -791,6 +795,7 @@ export async function getMyEvents(): Promise<{
title: events.title,
description: events.description,
datetime: events.datetime,
endDatetime: events.endDatetime,
flyerUrl: events.flyerUrl,
locationName: campusLocations.name,
orgId: events.orgId,
Expand All @@ -803,26 +808,50 @@ export async function getMyEvents(): Promise<{
.where(eq(savedEvents.userId, userId))
.orderBy(events.datetime);

const mapEvent = (e: (typeof createdEvents)[0]): FeedEvent => ({
const allEvents = [...createdEvents, ...rsvpedEvents, ...savedEventsResult];
const eventIds = [...new Set(allEvents.map((event) => event.id))];

const attendeeCounts = new Map<string, number>();
if (eventIds.length > 0) {
const counts = await db
.select({
eventId: rsvps.eventId,
count: sql<number>`count(*)::int`,
})
.from(rsvps)
.where(inArray(rsvps.eventId, eventIds))
.groupBy(rsvps.eventId);

for (const row of counts) {
attendeeCounts.set(row.eventId, row.count);
}
}

const mapEvent = (
e: (typeof createdEvents)[0],
overrides: Partial<Pick<FeedEvent, "isRsvped" | "isSaved">> = {},
): FeedEvent => ({
id: e.id,
title: e.title,
description: e.description,
orgId: e.orgId,
orgName: e.orgName,
datetime: formatEventDateTime(e.datetime),
datetimeIso: e.datetime.toISOString(),
endDatetimeIso: e.endDatetime?.toISOString(),
location: e.locationName ?? "TBD",
tags: [],
flyerUrl: e.flyerUrl,
rsvpCount: 0,
rsvpCount: attendeeCounts.get(e.id) ?? 0,
friendsAttending: [],
isRsvped: false,
isSaved: false,
isRsvped: overrides.isRsvped ?? false,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it can make the same event report different state depending on which tab it came from. For example, an event that's both saved and RSVP'd gets isRsvped: true in the RSVP list but isSaved: false, while the Saved list gets the opposite. Current staging already enriches My Events from the user's actual save/RSVP state (along with tags/friends), so can we preserve that enrichment here instead of overriding one flag per list?

isSaved: overrides.isSaved ?? false,
});

return {
created: createdEvents.map(mapEvent),
rsvped: rsvpedEvents.map(mapEvent),
saved: savedEventsResult.map(mapEvent),
created: createdEvents.map((event) => mapEvent(event)),
rsvped: rsvpedEvents.map((event) => mapEvent(event, { isRsvped: true })),
saved: savedEventsResult.map((event) => mapEvent(event, { isSaved: true })),
};
}

Expand Down
Loading