diff --git a/src/app/e/[code]/g/[token]/page.tsx b/src/app/e/[code]/g/[token]/page.tsx
index 4de20d7..c20b6c7 100644
--- a/src/app/e/[code]/g/[token]/page.tsx
+++ b/src/app/e/[code]/g/[token]/page.tsx
@@ -4,10 +4,13 @@ import { notFound } from "next/navigation";
import { CancelledEventNotice } from "@/components/CancelledEventNotice";
import { EventUnavailable } from "@/components/EventUnavailable";
import { RsvpForm } from "@/components/RsvpForm";
+import { UpdatedDetailsNotice } from "@/components/UpdatedDetailsNotice";
import { getDb } from "@/db/client";
import type { RsvpStatus } from "@/domain/headcount";
+import { coverFor } from "@/lib/cover";
import { eventState } from "@/lib/event-state";
import { formatWhen } from "@/lib/format";
+import { relativeDateLabel } from "@/lib/relative-date";
import { NotFoundError } from "@/services/errors";
import { getGuestByToken, getPublicEvent } from "@/services/rsvp";
import { updateGuestRsvp } from "../../actions";
@@ -47,6 +50,19 @@ export default async function GuestEditPage({ params }: PageProps<"/e/[code]/g/[
if (state === "deleted") return ;
const cancelled = state === "cancelled";
+ // A returning guest only needs the notice if the move happened after they
+ // answered; cancellation has its own banner.
+ const now = new Date();
+ const changedAt = cancelled ? null : event.detailsChangedAt;
+ const updated =
+ changedAt && changedAt.getTime() > guest.createdAt.getTime()
+ ? {
+ relative: relativeDateLabel(changedAt, now, event.timezone),
+ when: formatWhen(event.startsAt, "", event.timezone),
+ location: event.location,
+ }
+ : null;
+
const personalNote = (
This is your personal link โ don't share it.{" "}
@@ -69,6 +85,7 @@ export default async function GuestEditPage({ params }: PageProps<"/e/[code]/g/[
when: formatWhen(event.startsAt, event.location, event.timezone),
hostName: event.hostName,
goingCount: event.goingCount,
+ cover: coverFor(event),
}}
initial={guest}
action={updateGuestRsvp.bind(null, code, token)}
@@ -88,6 +105,7 @@ export default async function GuestEditPage({ params }: PageProps<"/e/[code]/g/[
)}
+ {updated ? : null}
{personalNote}
}
diff --git a/src/app/e/[code]/page.tsx b/src/app/e/[code]/page.tsx
index 2df16d1..45a42a6 100644
--- a/src/app/e/[code]/page.tsx
+++ b/src/app/e/[code]/page.tsx
@@ -4,12 +4,15 @@ import { notFound, redirect } from "next/navigation";
import { CancelledEventNotice } from "@/components/CancelledEventNotice";
import { EventUnavailable } from "@/components/EventUnavailable";
import { RsvpForm } from "@/components/RsvpForm";
+import { UpdatedDetailsNotice } from "@/components/UpdatedDetailsNotice";
import { getDb } from "@/db/client";
+import { coverFor } from "@/lib/cover";
import { eventState } from "@/lib/event-state";
import { formatWhen } from "@/lib/format";
import { guestCookieName } from "@/lib/guest-cookie";
import { eventPreview, wantsBlankForm } from "@/lib/guest-page";
import { calendarDetails, googleCalendarUrl } from "@/lib/ics";
+import { changedRecently, relativeDateLabel } from "@/lib/relative-date";
import { getBaseUrl, shareUrl } from "@/server/base-url";
import { NotFoundError } from "@/services/errors";
import { getGuestByToken, getPublicEvent } from "@/services/rsvp";
@@ -47,6 +50,18 @@ export default async function GuestPage({ params, searchParams }: PageProps<"/e/
if (state === "deleted") return ;
const cancelled = state === "cancelled";
+ // Anonymous visitors have no RSVP date to compare with, so a recent move
+ // shows for two weeks. Cancelled events keep the cancellation banner instead.
+ const now = new Date();
+ const changedAt = cancelled ? null : event.detailsChangedAt;
+ const updated = changedAt && changedRecently(changedAt, now)
+ ? {
+ relative: relativeDateLabel(changedAt, now, event.timezone),
+ when: formatWhen(event.startsAt, "", event.timezone),
+ location: event.location,
+ }
+ : null;
+
// A returning guest goes straight to their edit page. A missing, invalid or
// stale cookie is ignored. `?new=1` ("Not you?") skips this and shows a blank form.
const token = blank ? undefined : (await cookies()).get(guestCookieName(code))?.value;
@@ -77,10 +92,17 @@ export default async function GuestPage({ params, searchParams }: PageProps<"/e/
when: formatWhen(event.startsAt, event.location, event.timezone),
hostName: event.hostName,
goingCount: event.goingCount,
+ cover: coverFor(event),
}}
action={submitGuestRsvp.bind(null, code)}
readOnly={cancelled}
- notice={cancelled ? : undefined}
+ notice={
+ cancelled ? (
+
+ ) : updated ? (
+
+ ) : undefined
+ }
/>
{cancelled ? null : (
diff --git a/src/app/host/events/[id]/edit/actions.test.ts b/src/app/host/events/[id]/edit/actions.test.ts
index 5dfe560..b6361a1 100644
--- a/src/app/host/events/[id]/edit/actions.test.ts
+++ b/src/app/host/events/[id]/edit/actions.test.ts
@@ -65,15 +65,29 @@ function form(over: Record = {}) {
describe("updateEventAction", () => {
it("saves and redirects back to the Guests tab", async () => {
- await expect(updateEventAction(eventId, { error: null }, form())).rejects.toThrow(
+ // Same time, zone and place: a title-only edit sends no change alert.
+ const titleOnly = form({
+ title: "Cookout 2",
+ startsAt: "2026-07-04T18:00",
+ location: "Backyard",
+ timezone: "UTC",
+ });
+ await expect(updateEventAction(eventId, { error: null }, titleOnly)).rejects.toThrow(
`NEXT_REDIRECT:/host/events/${eventId}`,
);
expect(await getHostEvent(db, "host-1", eventId)).toMatchObject({
- title: "Burger Night",
- location: "The patio",
+ title: "Cookout 2",
+ location: "Backyard",
});
});
+ it("redirects with changed=1 when the time or place moved", async () => {
+ await expect(updateEventAction(eventId, { error: null }, form())).rejects.toThrow(
+ `NEXT_REDIRECT:/host/events/${eventId}?changed=1`,
+ );
+ expect((await getHostEvent(db, "host-1", eventId)).detailsChangedAt).toBeInstanceOf(Date);
+ });
+
it("returns a friendly error for bad input and saves nothing", async () => {
expect(await updateEventAction(eventId, { error: null }, form({ location: " " }))).toEqual({
error: "Where is it?",
diff --git a/src/app/host/events/[id]/edit/actions.ts b/src/app/host/events/[id]/edit/actions.ts
index 2f07d15..6d0105c 100644
--- a/src/app/host/events/[id]/edit/actions.ts
+++ b/src/app/host/events/[id]/edit/actions.ts
@@ -28,12 +28,15 @@ export async function updateEventAction(
formData: FormData,
): Promise {
const host = await requireHost();
+ let result: { detailsChanged: boolean };
try {
- await updateEvent(await getDb(), host.id, eventId, {
+ result = await updateEvent(await getDb(), host.id, eventId, {
title: text(formData, "title"),
startsAt: text(formData, "startsAt"),
location: text(formData, "location"),
timezone: text(formData, "timezone") || undefined,
+ coverEmoji: text(formData, "coverEmoji") || null,
+ coverColor: text(formData, "coverColor") || null,
});
} catch (error) {
if (error instanceof ValidationError) return { error: error.message };
@@ -43,7 +46,9 @@ export async function updateEventAction(
// The title and time show in the layout header and on the dashboard.
revalidatePath(`/host/events/${encodeURIComponent(eventId)}`, "layout");
revalidatePath("/host");
- redirect(`/host/events/${encodeURIComponent(eventId)}`);
+ // A moved time or place lands on the Guests tab with a copyable heads-up.
+ const query = result.detailsChanged ? "?changed=1" : "";
+ redirect(`/host/events/${encodeURIComponent(eventId)}${query}`);
}
/**
diff --git a/src/app/host/events/[id]/edit/page.tsx b/src/app/host/events/[id]/edit/page.tsx
index bda3010..e713817 100644
--- a/src/app/host/events/[id]/edit/page.tsx
+++ b/src/app/host/events/[id]/edit/page.tsx
@@ -27,6 +27,8 @@ export default async function EditEventPage({ params }: PageProps<"/host/events/
startsAt: dateToZonedLocal(event.startsAt, event.timezone),
location: event.location,
timezone: event.timezone,
+ coverEmoji: event.coverEmoji,
+ coverColor: event.coverColor,
}}
action={updateEventAction.bind(null, event.id)}
backHref={`/host/events/${encodeURIComponent(event.id)}`}
diff --git a/src/app/host/events/[id]/layout.tsx b/src/app/host/events/[id]/layout.tsx
index 4123f83..0bf6998 100644
--- a/src/app/host/events/[id]/layout.tsx
+++ b/src/app/host/events/[id]/layout.tsx
@@ -3,8 +3,10 @@ import type { ReactNode } from "react";
import { CancelledEventNotice } from "@/components/CancelledEventNotice";
import { CopyCancellationButton } from "@/components/CopyCancellationButton";
import { CopyLinkButton } from "@/components/CopyLinkButton";
+import { CoverChip } from "@/components/CoverChip";
import { EventTabs } from "@/components/EventTabs";
import { Wordmark } from "@/components/ui/Wordmark";
+import { coverFor } from "@/lib/cover";
import { formatWhen } from "@/lib/format";
import { getBaseUrl, shareUrl } from "@/server/base-url";
import { loadHostEvent } from "@/server/host-event";
@@ -57,23 +59,26 @@ export default async function EventLayout({
-
-
{event.title}
-
- {formatWhen(event.startsAt, event.location, event.timezone)}
-
-
-
- Edit details
-
-
+
+
+
+
{event.title}
+
+ {formatWhen(event.startsAt, event.location, event.timezone)}
+
+
+
+ Edit details
+
+
+
diff --git a/src/app/host/events/[id]/page.tsx b/src/app/host/events/[id]/page.tsx
index b670449..103f6e0 100644
--- a/src/app/host/events/[id]/page.tsx
+++ b/src/app/host/events/[id]/page.tsx
@@ -1,6 +1,9 @@
+import Link from "next/link";
+import { ChangeNotice } from "@/components/ChangeNotice";
import { GuestsPanel } from "@/components/GuestsPanel";
import { DevGuestTools } from "@/components/dev/DevGuestTools";
import { getDb } from "@/db/client";
+import { formatWhen } from "@/lib/format";
import { devToolsEnabled } from "@/server/dev-tools";
import { requireHost } from "@/server/auth";
import { loadHostEvent } from "@/server/host-event";
@@ -17,9 +20,11 @@ import { addInviteesAction, removeGuestAction, setMaybePercentAction } from "./a
export const dynamic = "force-dynamic";
-export default async function GuestsTab({ params }: PageProps<"/host/events/[id]">) {
+export default async function GuestsTab({ params, searchParams }: PageProps<"/host/events/[id]">) {
// Layouts and pages are authorised independently: check ownership here too.
const { event } = await loadHostEvent((await params).id);
+ // Set by updateEventAction when the time, zone or place moved.
+ const changed = (await searchParams).changed === "1";
const host = await requireHost();
const db = await getDb();
const overview = await getGuestsOverview(db, host.id, event.id);
@@ -30,6 +35,18 @@ export default async function GuestsTab({ params }: PageProps<"/host/events/[id]
return (
<>
+ {changed && !event.cancelledAt ? (
+
+
+
+ Dismiss
+
+
+ ) : null}
+ {countdown ? {countdown} : null}
+ {glance.yes} yes
+ {glance.maybe} maybe
+ {glance.no} no
+ {glance.noReply > 0 ? {noReply} : null}
+
+ );
+}
+
+function EventTicket({
+ event,
+ baseUrl,
+ glance,
+ now,
+ showGlance,
+}: {
+ event: EventSummary;
+ baseUrl: string;
+ glance?: EventGlance;
+ now: Date;
+ /** Upcoming and live only: past and cancelled cards stay quiet. */
+ showGlance: boolean;
+}) {
return (
-
-
{event.title}
- {event.cancelledAt ? (
-
- Cancelled
-
- ) : null}
-
- {formatWhen(event.startsAt, event.location, event.timezone)}
-
-
+
+
+
+
+
{event.title}
+ {event.cancelledAt ? (
+
+ Cancelled
+
+ ) : null}
+
+ {formatWhen(event.startsAt, event.location, event.timezone)}
+
+
+ {showGlance ? (
+
+ ) : null}
+
+
Plan for
~{event.planFor}
@@ -54,6 +98,12 @@ export default async function HostDashboardPage({ searchParams }: PageProps<"/ho
// Lazy, host-scoped purge: anything deleted more than 30 days ago goes for good.
await purgeDeletedEvents(db, host.id);
const [events, baseUrl] = await Promise.all([listHostEvents(db, host.id), getBaseUrl()]);
+ // One batched read for every card's answer counts; no per-event queries.
+ const glance = await glanceForEvents(
+ db,
+ events.map((event) => event.id),
+ );
+ const now = new Date();
// Set by deleteEventAction (the id, never the title): the notice stays until the
// host follows the Dismiss link or Undo restores the event.
@@ -126,7 +176,14 @@ export default async function HostDashboardPage({ searchParams }: PageProps<"/ho
{upcoming.map((event) => (
-
+
))}
@@ -139,7 +196,14 @@ export default async function HostDashboardPage({ searchParams }: PageProps<"/ho
{past.map((event) => (
-
+
))}
diff --git a/src/components/ChangeNotice.tsx b/src/components/ChangeNotice.tsx
new file mode 100644
index 0000000..3ec2a5d
--- /dev/null
+++ b/src/components/ChangeNotice.tsx
@@ -0,0 +1,60 @@
+"use client";
+
+import { useState } from "react";
+import { Button } from "./ui/Button";
+
+/** The sentence the host pastes into their group chat; Spread never sends it. */
+export function changeNoticeMessage(title: string, when: string, location: string): string {
+ return `Heads up: ${title} is now ${when} at ${location}`;
+}
+
+/**
+ * Shown on the Guests tab right after a time or place change, so the host can
+ * tell everyone in their own chat.
+ */
+export function ChangeNotice({
+ title,
+ when,
+ location,
+}: {
+ title: string;
+ /** Pre-formatted day and time, e.g. "Sat, Nov 14 ยท 7pm". */
+ when: string;
+ location: string;
+}) {
+ const [state, setState] = useState<"idle" | "copied" | "failed">("idle");
+ const message = changeNoticeMessage(title, when, location);
+
+ async function copy() {
+ try {
+ await navigator.clipboard.writeText(message);
+ setState("copied");
+ } catch {
+ setState("failed");
+ }
+ }
+
+ return (
+
+
{message}
+
+ Copy this into your group chat. Spread doesn't message guests for you.
+
+
+ {state === "copied" ? "Copied!" : "Copy heads-up message"}
+
+ {state !== "idle" ? (
+
+ {state === "copied"
+ ? "Heads-up copied. Paste it into your group chat."
+ : "Couldn't copy. Select the message above and copy it manually."}
+
+ ) : null}
+
+ );
+}
diff --git a/src/components/CoverChip.tsx b/src/components/CoverChip.tsx
new file mode 100644
index 0000000..31e1d46
--- /dev/null
+++ b/src/components/CoverChip.tsx
@@ -0,0 +1,28 @@
+import type { Cover } from "@/lib/cover";
+
+const sizes = {
+ sm: "h-8 w-8 text-base",
+ md: "h-10 w-10 text-xl",
+ lg: "h-14 w-14 text-3xl",
+} as const;
+
+/** A preset emoji on its palette colour: the event's small cover badge. */
+export function CoverChip({
+ cover,
+ size = "md",
+ className = "",
+}: {
+ cover: Cover;
+ size?: keyof typeof sizes;
+ className?: string;
+}) {
+ return (
+
+ {cover.emoji}
+
+ );
+}
diff --git a/src/components/CoverPicker.tsx b/src/components/CoverPicker.tsx
new file mode 100644
index 0000000..23fb9d3
--- /dev/null
+++ b/src/components/CoverPicker.tsx
@@ -0,0 +1,72 @@
+"use client";
+
+import { useState } from "react";
+import { COVER_COLORS, COVERS, coverFor } from "@/lib/cover";
+
+/**
+ * A radio group for the event cover: one emoji and one palette colour. State
+ * lives here so a rejected save keeps the host's choice. Every option is a
+ * native radio with an accessible label ("Party popper", "Mustard").
+ */
+export function CoverPicker({
+ initialEmoji,
+ initialColor,
+}: {
+ initialEmoji?: string | null;
+ initialColor?: string | null;
+}) {
+ const initial = coverFor({ coverEmoji: initialEmoji, coverColor: initialColor });
+ const [emoji, setEmoji] = useState(initial.emoji);
+ const [color, setColor] = useState(initial.color);
+
+ return (
+
+ Cover
+
+ A small badge for this event on your list and your guests' page.
+
+
+
+ {COVERS.map((cover) => (
+
+ setEmoji(cover.emoji)}
+ aria-label={cover.label}
+ className="peer sr-only"
+ />
+
+ {cover.emoji}
+
+
+ ))}
+
+
+
+ {COVER_COLORS.map((choice) => (
+
+ setColor(choice.key)}
+ aria-label={choice.label}
+ className="peer sr-only"
+ />
+
+
+ ))}
+
+
+ );
+}
diff --git a/src/components/EditEventForm.test.tsx b/src/components/EditEventForm.test.tsx
index 5b517b9..3563f98 100644
--- a/src/components/EditEventForm.test.tsx
+++ b/src/components/EditEventForm.test.tsx
@@ -7,6 +7,8 @@ const initial = {
startsAt: "2026-11-14T19:00",
location: "The patio",
timezone: "America/Chicago",
+ coverEmoji: null,
+ coverColor: null,
};
describe("EditEventForm", () => {
@@ -45,4 +47,27 @@ describe("EditEventForm", () => {
expect(screen.getByLabelText("Date and time")).toHaveValue("2026-11-14T19:00");
expect(screen.getByLabelText("Where?")).toHaveValue(" ");
});
+
+ it("shows the event's cover and sends a newly picked one", async () => {
+ const action = vi.fn().mockResolvedValue({ error: null });
+ render(
+
,
+ );
+ expect(screen.getByRole("group", { name: "Cover" })).toBeInTheDocument();
+ expect(screen.getByRole("radio", { name: "Pizza" })).toBeChecked();
+ expect(screen.getByRole("radio", { name: "Pickle" })).toBeChecked();
+
+ fireEvent.click(screen.getByRole("radio", { name: "Taco" }));
+ fireEvent.click(screen.getByRole("radio", { name: "Ketchup" }));
+ fireEvent.click(screen.getByRole("button", { name: "Save changes" }));
+
+ await waitFor(() => expect(action).toHaveBeenCalled());
+ const data = action.mock.calls[0][1] as FormData;
+ expect(data.get("coverEmoji")).toBe("๐ฎ");
+ expect(data.get("coverColor")).toBe("ketchup");
+ });
});
diff --git a/src/components/EditEventForm.tsx b/src/components/EditEventForm.tsx
index e7b195e..b4bafdb 100644
--- a/src/components/EditEventForm.tsx
+++ b/src/components/EditEventForm.tsx
@@ -2,6 +2,7 @@
import Link from "next/link";
import { useActionState, useState } from "react";
+import { CoverPicker } from "./CoverPicker";
import { Button } from "./ui/Button";
import { Card } from "./ui/Card";
import { Field } from "./ui/Field";
@@ -22,6 +23,9 @@ export interface EditEventInitial {
location: string;
/** IANA zone the time above is in; it stays the same when saving. */
timezone: string;
+ /** Preset cover; null means the default (๐ on mustard). */
+ coverEmoji: string | null;
+ coverColor: string | null;
}
export function EditEventForm({
@@ -68,6 +72,7 @@ export function EditEventForm({
value={location}
onChange={(e) => setLocation(e.target.value)}
/>
+
{state.error ? (
{
expect(await screen.findByRole("alert")).toHaveTextContent("Where is it?");
});
+
+ it("starts on the default cover and sends a picked one", async () => {
+ const action = vi.fn().mockResolvedValue({ error: null });
+ render( );
+
+ expect(screen.getByRole("radio", { name: "Party popper" })).toBeChecked();
+ expect(screen.getByRole("radio", { name: "Mustard" })).toBeChecked();
+ fireEvent.click(screen.getByRole("radio", { name: "Pizza" }));
+ fireEvent.click(screen.getByRole("radio", { name: "Sage" }));
+
+ fireEvent.change(screen.getByLabelText("What's the occasion?"), { target: { value: "Cookout" } });
+ fireEvent.change(screen.getByLabelText("Date and time"), { target: { value: "2026-11-14T19:00" } });
+ fireEvent.change(screen.getByLabelText("Where?"), { target: { value: "Backyard" } });
+ fireEvent.click(screen.getByRole("button", { name: "Create event" }));
+
+ await waitFor(() => expect(action).toHaveBeenCalled());
+ const data = action.mock.calls[0][1] as FormData;
+ expect(data.get("coverEmoji")).toBe("๐");
+ expect(data.get("coverColor")).toBe("pickle-soft");
+ });
});
diff --git a/src/components/NewEventForm.tsx b/src/components/NewEventForm.tsx
index da2bfea..dd98c3f 100644
--- a/src/components/NewEventForm.tsx
+++ b/src/components/NewEventForm.tsx
@@ -2,6 +2,7 @@
import Link from "next/link";
import { useActionState, useSyncExternalStore } from "react";
+import { CoverPicker } from "./CoverPicker";
import { Button } from "./ui/Button";
import { Field } from "./ui/Field";
import { Wordmark } from "./ui/Wordmark";
@@ -58,6 +59,7 @@ export function NewEventForm({ action }: { action: NewEventAction }) {
required
placeholder="Will's backyard"
/>
+
{state.error ? (
{
status: "maybe",
plusOneNames: ["Sam", "Alex"],
foodNotes: "no peanuts",
+ createdAt: new Date("2026-11-01T12:00:00Z"),
}}
/>,
);
@@ -168,6 +169,7 @@ describe("RsvpForm", () => {
status: "maybe",
plusOneNames: ["Sam", "Alex"],
foodNotes: "no peanuts",
+ createdAt: new Date("2026-11-01T12:00:00Z"),
}}
/>,
);
diff --git a/src/components/RsvpForm.tsx b/src/components/RsvpForm.tsx
index 391e6d4..ba9a1dd 100644
--- a/src/components/RsvpForm.tsx
+++ b/src/components/RsvpForm.tsx
@@ -2,7 +2,9 @@
import { useActionState, useState, type ReactNode } from "react";
import type { RsvpStatus } from "@/domain/headcount";
+import type { Cover } from "@/lib/cover";
import type { GuestView } from "@/services/rsvp";
+import { CoverChip } from "./CoverChip";
import { Button } from "./ui/Button";
import { Field } from "./ui/Field";
import { Wordmark } from "./ui/Wordmark";
@@ -15,6 +17,8 @@ export interface RsvpFormEvent {
when: string;
hostName: string;
goingCount: number;
+ /** The event's preset cover, resolved on the server; omitted means none. */
+ cover?: Cover;
}
export interface RsvpFormState {
@@ -44,7 +48,10 @@ function SlipHead({ event, readOnly }: { event: RsvpFormEvent; readOnly: boolean
{event.hostName} is hosting
-
{event.title}
+
+ {event.cover ? : null}
+
{event.title}
+
{event.when}
{readOnly
diff --git a/src/components/UpdatedDetailsNotice.tsx b/src/components/UpdatedDetailsNotice.tsx
new file mode 100644
index 0000000..39f78e2
--- /dev/null
+++ b/src/components/UpdatedDetailsNotice.tsx
@@ -0,0 +1,23 @@
+/** Guest-facing note that the host moved the party: "Updated 3 days ago: now โฆ". */
+export function UpdatedDetailsNotice({
+ relative,
+ when,
+ location,
+}: {
+ /** "today", "yesterday", "3 days ago". */
+ relative: string;
+ /** Pre-formatted day and time, e.g. "Sat, Nov 14 ยท 7pm". */
+ when: string;
+ location: string;
+}) {
+ return (
+
+
+ Updated {relative}: now {when} at {location}.
+
+
+ );
+}
diff --git a/src/lib/cover.test.ts b/src/lib/cover.test.ts
new file mode 100644
index 0000000..e51fb19
--- /dev/null
+++ b/src/lib/cover.test.ts
@@ -0,0 +1,52 @@
+import { describe, expect, it } from "vitest";
+import {
+ COVER_COLOR_KEYS,
+ COVER_COLORS,
+ COVER_EMOJI,
+ COVERS,
+ coverFor,
+ DEFAULT_COVER_COLOR,
+ DEFAULT_COVER_EMOJI,
+} from "./cover";
+
+describe("coverFor", () => {
+ it("falls back to ๐ and mustard when the event has no cover", () => {
+ expect(coverFor({ coverEmoji: null, coverColor: null })).toEqual({
+ emoji: DEFAULT_COVER_EMOJI,
+ emojiLabel: "Party popper",
+ color: DEFAULT_COVER_COLOR,
+ className: "bg-mustard",
+ });
+ expect(coverFor({})).toMatchObject({
+ emoji: DEFAULT_COVER_EMOJI,
+ color: DEFAULT_COVER_COLOR,
+ });
+ });
+
+ it("resolves a stored preset to its label and palette class", () => {
+ expect(coverFor({ coverEmoji: "๐", coverColor: "pickle" })).toEqual({
+ emoji: "๐",
+ emojiLabel: "Pizza",
+ color: "pickle",
+ className: "bg-pickle",
+ });
+ });
+
+ it("ignores values outside the preset lists", () => {
+ expect(coverFor({ coverEmoji: "๐", coverColor: "neon" })).toMatchObject({
+ emoji: DEFAULT_COVER_EMOJI,
+ color: DEFAULT_COVER_COLOR,
+ });
+ });
+
+ it("exposes every preset once for the picker and server validation", () => {
+ expect(COVER_EMOJI).toHaveLength(8);
+ expect(new Set(COVER_EMOJI).size).toBe(8);
+ expect(COVERS.map((cover) => cover.emoji)).toEqual(COVER_EMOJI);
+ expect(COVER_COLOR_KEYS).toHaveLength(6);
+ expect(new Set(COVER_COLOR_KEYS).size).toBe(6);
+ for (const color of COVER_COLORS) {
+ expect(color.className).toMatch(/^bg-/);
+ }
+ });
+});
diff --git a/src/lib/cover.ts b/src/lib/cover.ts
new file mode 100644
index 0000000..9e41b79
--- /dev/null
+++ b/src/lib/cover.ts
@@ -0,0 +1,81 @@
+/**
+ * Event covers: one preset emoji on one palette colour, chosen when the host
+ * creates or edits an event. Values are validated server-side against these
+ * lists, so a cover is always printable from a `bg-*` class Tailwind can see.
+ */
+
+export interface CoverChoice {
+ emoji: string;
+ label: string;
+}
+
+export const COVERS: readonly CoverChoice[] = [
+ { emoji: "๐", label: "Party popper" },
+ { emoji: "๐", label: "Burger" },
+ { emoji: "๐", label: "Birthday cake" },
+ { emoji: "๐", label: "Pizza" },
+ { emoji: "๐ฎ", label: "Taco" },
+ { emoji: "๐ฅ", label: "Clinking glasses" },
+ { emoji: "๐", label: "Pumpkin" },
+ { emoji: "๐", label: "Christmas tree" },
+];
+
+/** The emoji as a non-empty tuple, ready for `z.enum`. */
+export const COVER_EMOJI = COVERS.map((cover) => cover.emoji) as [string, ...string[]];
+
+export interface CoverColorChoice {
+ /** Stored on `events.coverColor` and sent by the picker. */
+ key: string;
+ label: string;
+ /** One of the palette classes from globals.css. */
+ className: string;
+}
+
+export const COVER_COLORS: readonly CoverColorChoice[] = [
+ { key: "mustard", label: "Mustard", className: "bg-mustard" },
+ { key: "ketchup", label: "Ketchup", className: "bg-ketchup" },
+ { key: "pickle", label: "Pickle", className: "bg-pickle" },
+ { key: "cream-deep", label: "Peach", className: "bg-cream-deep" },
+ { key: "ink", label: "Charcoal", className: "bg-ink" },
+ { key: "pickle-soft", label: "Sage", className: "bg-pickle-soft" },
+];
+
+/** Colour keys as a non-empty tuple, ready for `z.enum`. */
+export const COVER_COLOR_KEYS = COVER_COLORS.map((color) => color.key) as [
+ string,
+ ...string[],
+];
+
+export const DEFAULT_COVER_EMOJI = "๐";
+export const DEFAULT_COVER_COLOR = "mustard";
+
+/** What every screen renders for an event with no cover (or an unknown one). */
+export interface Cover {
+ emoji: string;
+ /** Accessible name for the emoji, e.g. "Party popper". */
+ emojiLabel: string;
+ color: string;
+ className: string;
+}
+
+const DEFAULT_EMOJI_CHOICE =
+ COVERS.find((cover) => cover.emoji === DEFAULT_COVER_EMOJI) ?? COVERS[0];
+const DEFAULT_COLOR_CHOICE =
+ COVER_COLORS.find((color) => color.key === DEFAULT_COVER_COLOR) ?? COVER_COLORS[0];
+
+/** Resolves stored (possibly null) cover values to the preset to render. */
+export function coverFor(event: {
+ coverEmoji?: string | null;
+ coverColor?: string | null;
+}): Cover {
+ const emoji =
+ COVERS.find((cover) => cover.emoji === event.coverEmoji) ?? DEFAULT_EMOJI_CHOICE;
+ const color =
+ COVER_COLORS.find((choice) => choice.key === event.coverColor) ?? DEFAULT_COLOR_CHOICE;
+ return {
+ emoji: emoji.emoji,
+ emojiLabel: emoji.label,
+ color: color.key,
+ className: color.className,
+ };
+}
diff --git a/src/lib/relative-date.test.ts b/src/lib/relative-date.test.ts
new file mode 100644
index 0000000..9a4f5c2
--- /dev/null
+++ b/src/lib/relative-date.test.ts
@@ -0,0 +1,77 @@
+import { describe, expect, it } from "vitest";
+import {
+ changedRecently,
+ countdownLabel,
+ DETAILS_CHANGE_NOTICE_DAYS,
+ relativeDateLabel,
+} from "./relative-date";
+
+const at = (iso: string) => new Date(iso);
+
+describe("relativeDateLabel", () => {
+ const now = at("2026-11-15T12:00:00Z");
+
+ it("says today for the same calendar day", () => {
+ expect(relativeDateLabel(at("2026-11-15T01:00:00Z"), now, "UTC")).toBe("today");
+ });
+
+ it("says yesterday for the day before", () => {
+ expect(relativeDateLabel(at("2026-11-14T23:00:00Z"), now, "UTC")).toBe("yesterday");
+ });
+
+ it("counts whole days since", () => {
+ expect(relativeDateLabel(at("2026-11-12T18:00:00Z"), now, "UTC")).toBe("3 days ago");
+ });
+
+ it("counts in the event's zone, not UTC", () => {
+ // 22:00 Chicago on Nov 14 and 06:00 Chicago on Nov 15 are the same UTC day.
+ const then = at("2026-11-15T04:00:00Z");
+ expect(relativeDateLabel(then, now, "UTC")).toBe("today");
+ expect(relativeDateLabel(then, now, "America/Chicago")).toBe("yesterday");
+ });
+});
+
+describe("countdownLabel", () => {
+ const now = at("2026-11-15T12:00:00Z");
+
+ it("says today for a later party the same day", () => {
+ expect(countdownLabel(at("2026-11-15T23:00:00Z"), "UTC", now)).toBe("today");
+ });
+
+ it("says tomorrow for the next calendar day", () => {
+ expect(countdownLabel(at("2026-11-16T02:00:00Z"), "UTC", now)).toBe("tomorrow");
+ });
+
+ it("counts days for a party further out", () => {
+ expect(countdownLabel(at("2026-11-21T18:00:00Z"), "UTC", now)).toBe("in 6 days");
+ });
+
+ it("has no countdown once the calendar day has passed", () => {
+ expect(countdownLabel(at("2026-11-14T18:00:00Z"), "UTC", now)).toBeNull();
+ });
+
+ it("uses the event's zone for the day boundary", () => {
+ // 01:00 UTC on Nov 16 is still the evening of Nov 15 in Chicago.
+ const startsAt = at("2026-11-16T01:00:00Z");
+ expect(countdownLabel(startsAt, "UTC", now)).toBe("tomorrow");
+ expect(countdownLabel(startsAt, "America/Chicago", now)).toBe("today");
+ });
+});
+
+describe("changedRecently", () => {
+ const now = at("2026-11-15T12:00:00Z");
+
+ it("is false with no change recorded", () => {
+ expect(changedRecently(null, now)).toBe(false);
+ });
+
+ it("is true inside the 14-day window and false outside it", () => {
+ expect(changedRecently(at("2026-11-01T12:00:00Z"), now)).toBe(true);
+ expect(
+ changedRecently(
+ new Date(now.getTime() - (DETAILS_CHANGE_NOTICE_DAYS + 1) * 24 * 60 * 60 * 1000),
+ now,
+ ),
+ ).toBe(false);
+ });
+});
diff --git a/src/lib/relative-date.ts b/src/lib/relative-date.ts
new file mode 100644
index 0000000..786b2e6
--- /dev/null
+++ b/src/lib/relative-date.ts
@@ -0,0 +1,61 @@
+/**
+ * Calendar-day phrasing: "today", "tomorrow", "in 6 days"; "yesterday",
+ * "3 days ago". Days are counted in a chosen IANA zone, so a host in Chicago
+ * doesn't see "tomorrow" flip at midnight UTC.
+ */
+
+const MS_PER_DAY = 24 * 60 * 60 * 1000;
+
+/** How long an anonymous guest keeps seeing the "Updated โฆ" notice. */
+export const DETAILS_CHANGE_NOTICE_DAYS = 14;
+
+/** Days since the Unix epoch for the calendar date in `timeZone`. */
+function dayNumber(date: Date, timeZone?: string): number {
+ const parts = new Intl.DateTimeFormat("en-CA", {
+ timeZone,
+ year: "numeric",
+ month: "2-digit",
+ day: "2-digit",
+ }).formatToParts(date);
+ const part = (type: string) =>
+ Number(parts.find((candidate) => candidate.type === type)?.value ?? "0");
+ return Math.floor(Date.UTC(part("year"), part("month") - 1, part("day")) / MS_PER_DAY);
+}
+
+/** "today", "yesterday", "3 days ago". A future timestamp reads as "today". */
+export function relativeDateLabel(
+ then: Date,
+ now: Date = new Date(),
+ timeZone?: string,
+): string {
+ const days = dayNumber(now, timeZone) - dayNumber(then, timeZone);
+ if (days <= 0) return "today";
+ if (days === 1) return "yesterday";
+ return `${days} days ago`;
+}
+
+/**
+ * "today", "tomorrow", "in 6 days" for an event still ahead; null once its
+ * calendar day has passed (the dashboard hides past cards anyway).
+ */
+export function countdownLabel(
+ startsAt: Date,
+ timeZone: string,
+ now: Date = new Date(),
+): string | null {
+ const days = dayNumber(startsAt, timeZone) - dayNumber(now, timeZone);
+ if (days < 0) return null;
+ if (days === 0) return "today";
+ if (days === 1) return "tomorrow";
+ return `in ${days} days`;
+}
+
+/** True when the details changed within the last `days` (anonymous guest window). */
+export function changedRecently(
+ changedAt: Date | null,
+ now: Date = new Date(),
+ days: number = DETAILS_CHANGE_NOTICE_DAYS,
+): boolean {
+ if (!changedAt) return false;
+ return now.getTime() - changedAt.getTime() <= days * MS_PER_DAY;
+}
diff --git a/src/services/events.test.ts b/src/services/events.test.ts
index ed33801..0543209 100644
--- a/src/services/events.test.ts
+++ b/src/services/events.test.ts
@@ -15,6 +15,7 @@ import {
deleteEvent,
findDeletedHostEvent,
getHostEvent,
+ glanceForEvents,
headcountForEvents,
listHostEvents,
noReplyNames,
@@ -101,6 +102,75 @@ describe("createEvent", () => {
});
});
+describe("event covers", () => {
+ it("stores a preset emoji and colour, and leaves the default when none is given", async () => {
+ const { id } = await createEvent(db, "host-1", {
+ ...input,
+ coverEmoji: "๐",
+ coverColor: "pickle",
+ });
+ expect(await getHostEvent(db, "host-1", id)).toMatchObject({
+ coverEmoji: "๐",
+ coverColor: "pickle",
+ });
+
+ const plain = await createEvent(db, "host-1", { ...input, title: "Plain" });
+ expect(await getHostEvent(db, "host-1", plain.id)).toMatchObject({
+ coverEmoji: null,
+ coverColor: null,
+ });
+ const summary = (await listHostEvents(db, "host-1")).find((e) => e.id === plain.id);
+ expect(summary).toMatchObject({ coverEmoji: null, coverColor: null });
+ });
+
+ it("rejects emoji and colours outside the presets", async () => {
+ await expect(
+ createEvent(db, "host-1", { ...input, coverEmoji: "๐" }),
+ ).rejects.toBeInstanceOf(ValidationError);
+ await expect(
+ createEvent(db, "host-1", { ...input, coverColor: "neon" }),
+ ).rejects.toBeInstanceOf(ValidationError);
+
+ const { id } = await createEvent(db, "host-1", input);
+ await expect(
+ updateEvent(db, "host-1", id, {
+ title: "Cookout",
+ startsAt: "2026-07-04T18:00",
+ location: "Backyard",
+ timezone: "UTC",
+ coverEmoji: "๐",
+ }),
+ ).rejects.toBeInstanceOf(ValidationError);
+ expect((await getHostEvent(db, "host-1", id)).coverEmoji).toBeNull();
+ });
+
+ it("changes the cover without marking the details as changed, and leaves it alone when omitted", async () => {
+ const { id } = await createEvent(db, "host-1", input);
+ const edit = {
+ title: "Fourth of July",
+ startsAt: "2026-07-04T18:00",
+ location: "Backyard",
+ timezone: "UTC",
+ };
+
+ const changed = await updateEvent(db, "host-1", id, {
+ ...edit,
+ coverEmoji: "๐ฎ",
+ coverColor: "ketchup",
+ });
+ expect(changed.detailsChanged).toBe(false);
+ const event = await getHostEvent(db, "host-1", id);
+ expect(event).toMatchObject({ coverEmoji: "๐ฎ", coverColor: "ketchup" });
+ expect(event.detailsChangedAt).toBeNull();
+
+ await updateEvent(db, "host-1", id, edit);
+ expect(await getHostEvent(db, "host-1", id)).toMatchObject({
+ coverEmoji: "๐ฎ",
+ coverColor: "ketchup",
+ });
+ });
+});
+
describe("listHostEvents", () => {
it("returns only that host's events, soonest first, with a headcount", async () => {
const later = await createEvent(db, "host-1", {
@@ -146,6 +216,38 @@ describe("headcountForEvents", () => {
});
});
+describe("glanceForEvents", () => {
+ it("counts answers and unreplied invitees per event", async () => {
+ const a = await createEvent(db, "host-1", { ...input, title: "A" });
+ const b = await createEvent(db, "host-1", {
+ ...input,
+ title: "B",
+ startsAt: new Date("2026-08-01T18:00:00Z"),
+ });
+ await addInvitees(db, "host-1", a.id, ["Alex", "Sam", "Jo"]);
+ await submitRsvp(db, { shareCode: a.shareCode, name: " alex ", status: "yes", plusOneNames: [] });
+ await submitRsvp(db, { shareCode: a.shareCode, name: "Bea", status: "maybe", plusOneNames: [] });
+ await submitRsvp(db, { shareCode: a.shareCode, name: "Cy", status: "no", plusOneNames: [] });
+ await addInvitees(db, "host-1", b.id, ["Dee"]);
+ await submitRsvp(db, { shareCode: b.shareCode, name: "Dee", status: "yes", plusOneNames: [] });
+
+ const glance = await glanceForEvents(db, [a.id, b.id]);
+ // Alex's reply matches the invitee case-insensitively; Sam and Jo are silent.
+ expect(glance.get(a.id)).toEqual({ yes: 1, maybe: 1, no: 1, noReply: 2 });
+ expect(glance.get(b.id)).toEqual({ yes: 1, maybe: 0, no: 0, noReply: 0 });
+ });
+
+ it("leaves deleted events and unknown ids out", async () => {
+ const { id, shareCode } = await createEvent(db, "host-1", input);
+ await submitRsvp(db, { shareCode, name: "Alex", status: "yes", plusOneNames: [] });
+ await deleteEvent(db, "host-1", id);
+
+ const glance = await glanceForEvents(db, [id, "missing"]);
+ expect(glance.size).toBe(0);
+ expect(await glanceForEvents(db, [])).toEqual(new Map());
+ });
+});
+
describe("getHostEvent", () => {
it("throws NotFoundError for another host's event", async () => {
const { id } = await createEvent(db, "host-1", input);
@@ -253,6 +355,60 @@ describe("updateEvent", () => {
});
});
+describe("updateEvent details change alerts", () => {
+ const unchanged = {
+ title: "Fourth of July",
+ startsAt: "2026-07-04T18:00",
+ location: "Backyard",
+ timezone: "UTC",
+ };
+
+ it("does not count a title-only edit", async () => {
+ const { id } = await createEvent(db, "host-1", input);
+ const result = await updateEvent(db, "host-1", id, { ...unchanged, title: "July Cookout" });
+ expect(result).toEqual({ detailsChanged: false });
+ const event = await getHostEvent(db, "host-1", id);
+ expect(event.title).toBe("July Cookout");
+ expect(event.detailsChangedAt).toBeNull();
+ });
+
+ it("stamps detailsChangedAt when the start time changes", async () => {
+ const { id } = await createEvent(db, "host-1", input);
+ const result = await updateEvent(db, "host-1", id, {
+ ...unchanged,
+ startsAt: "2026-07-04T19:00",
+ });
+ expect(result).toEqual({ detailsChanged: true });
+ expect((await getHostEvent(db, "host-1", id)).detailsChangedAt).toBeInstanceOf(Date);
+ });
+
+ it("stamps detailsChangedAt when the time zone changes", async () => {
+ const { id } = await createEvent(db, "host-1", input);
+ const result = await updateEvent(db, "host-1", id, {
+ ...unchanged,
+ timezone: "America/Chicago",
+ });
+ expect(result).toEqual({ detailsChanged: true });
+ expect((await getHostEvent(db, "host-1", id)).timezone).toBe("America/Chicago");
+ });
+
+ it("stamps detailsChangedAt when the location changes", async () => {
+ const { id } = await createEvent(db, "host-1", input);
+ const result = await updateEvent(db, "host-1", id, { ...unchanged, location: "The park" });
+ expect(result).toEqual({ detailsChanged: true });
+ expect((await getHostEvent(db, "host-1", id)).location).toBe("The park");
+ });
+
+ it("leaves an earlier stamp alone when saving the same details again", async () => {
+ const { id } = await createEvent(db, "host-1", input);
+ const stamp = new Date("2026-06-01T12:00:00Z");
+ await updateEvent(db, "host-1", id, { ...unchanged, location: "The park" }, stamp);
+ const result = await updateEvent(db, "host-1", id, { ...unchanged, location: "The park" });
+ expect(result).toEqual({ detailsChanged: false });
+ expect((await getHostEvent(db, "host-1", id)).detailsChangedAt).toEqual(stamp);
+ });
+});
+
describe("deleteEvent", () => {
it("hides the host's event from every host read path but keeps its data", async () => {
await seedStarterRecipes(db);
diff --git a/src/services/events.ts b/src/services/events.ts
index 5289009..794c0c4 100644
--- a/src/services/events.ts
+++ b/src/services/events.ts
@@ -4,6 +4,7 @@ import { z } from "zod";
import type { Db } from "@/db/client";
import { events, guests, invitees, plusOnes } from "@/db/schema";
import { computeHeadcount, type Headcount, type HeadcountGuest } from "@/domain/headcount";
+import { COVER_COLOR_KEYS, COVER_EMOJI } from "@/lib/cover";
import { assertTimeZone, zonedLocalToDate } from "@/lib/zoned-time";
import { NotFoundError, ValidationError } from "./errors";
@@ -17,6 +18,9 @@ export interface CreateEventInput {
hostName: string;
/** IANA zone the host chose the time in. Defaults to UTC. */
timezone?: string;
+ /** Preset cover; null or omitted means the default (๐ on mustard). */
+ coverEmoji?: string | null;
+ coverColor?: string | null;
}
export interface EventSummary {
@@ -30,6 +34,18 @@ export interface EventSummary {
planFor: number;
/** Set while the event is cancelled; the dashboard shows a badge (deleted events never list). */
cancelledAt: Date | null;
+ /** Stored cover values; the dashboard resolves them with `coverFor`. */
+ coverEmoji: string | null;
+ coverColor: string | null;
+}
+
+/** "At a glance" answers for a dashboard card, batched for every event at once. */
+export interface EventGlance {
+ yes: number;
+ maybe: number;
+ no: number;
+ /** Invitees with no guest of the same trimmed, case-insensitive name. */
+ noReply: number;
}
const MAX_TITLE = 100;
@@ -45,8 +61,19 @@ const detailsShape = {
location: z.string().trim().min(1, "Where is it?").max(MAX_LOCATION),
};
+/**
+ * Cover values come from the picker's radio group. Unknown values are rejected
+ * (a crafted POST must not store an emoji or class Tailwind can't render); null
+ * or omitted means the default cover.
+ */
+const coverShape = {
+ coverEmoji: z.enum(COVER_EMOJI, { error: "Pick a cover from the list" }).nullish(),
+ coverColor: z.enum(COVER_COLOR_KEYS, { error: "Pick a cover colour from the list" }).nullish(),
+};
+
const createSchema = z.object({
...detailsShape,
+ ...coverShape,
hostName: z.string().trim().min(1).max(MAX_NAME),
startsAt: z.date().refine((d) => !Number.isNaN(d.getTime()), "Pick a valid date and time"),
timezone: z.string().min(1).default("UTC"),
@@ -75,7 +102,13 @@ export async function createEvent(
const shareCode = newShareCode();
const [row] = await db
.insert(events)
- .values({ ...data, hostId, shareCode })
+ .values({
+ ...data,
+ coverEmoji: data.coverEmoji ?? null,
+ coverColor: data.coverColor ?? null,
+ hostId,
+ shareCode,
+ })
.onConflictDoNothing({ target: events.shareCode })
.returning({ id: events.id });
if (row) return { id: row.id, shareCode };
@@ -90,29 +123,62 @@ export interface UpdateEventInput {
location: string;
/** IANA zone the time was typed in. Defaults to the event's current zone. */
timezone?: string;
+ /** Preset cover; null clears it to the default, omitted leaves it untouched. */
+ coverEmoji?: string | null;
+ coverColor?: string | null;
+}
+
+export interface UpdateEventResult {
+ /**
+ * True when the start time, time zone or location actually changed. Title-only
+ * edits and cover-only edits leave it false, so no "Updated" notice goes out.
+ */
+ detailsChanged: boolean;
}
/**
- * Edits an event's title, time and place with the same validation as createEvent.
- * The share code, host name, maybe percent and all RSVPs are left alone.
+ * Edits an event's title, time, place and cover with the same validation as
+ * createEvent. The share code, host name, maybe percent and all RSVPs are left
+ * alone. A change to the time, zone or place stamps `detailsChangedAt` so guest
+ * pages and the host's heads-up message know the details moved.
*/
export async function updateEvent(
db: Db,
hostId: string,
eventId: string,
input: UpdateEventInput,
-): Promise
{
+ now: Date = new Date(),
+): Promise {
const event = await getHostEvent(db, hostId, eventId);
- const parsed = z.object(detailsShape).safeParse(input);
+ const parsed = z.object({ ...detailsShape, ...coverShape }).safeParse(input);
if (!parsed.success) {
throw new ValidationError(parsed.error.issues.map((i) => i.message).join("; "));
}
const timezone = input.timezone || event.timezone;
const startsAt = zonedLocalToDate(input.startsAt, timezone);
+ const detailsChanged =
+ event.startsAt.getTime() !== startsAt.getTime() ||
+ event.timezone !== timezone ||
+ event.location !== parsed.data.location;
+
await db
.update(events)
- .set({ ...parsed.data, startsAt, timezone })
+ .set({
+ title: parsed.data.title,
+ location: parsed.data.location,
+ startsAt,
+ timezone,
+ ...(detailsChanged ? { detailsChangedAt: now } : {}),
+ // Omitted cover fields belong to a caller that doesn't edit the cover.
+ ...(input.coverEmoji !== undefined
+ ? { coverEmoji: parsed.data.coverEmoji ?? null }
+ : {}),
+ ...(input.coverColor !== undefined
+ ? { coverColor: parsed.data.coverColor ?? null }
+ : {}),
+ })
.where(and(eq(events.id, eventId), eq(events.hostId, hostId)));
+ return { detailsChanged };
}
/**
@@ -231,6 +297,8 @@ export async function listHostEvents(db: Db, hostId: string): Promise name.trim().toLowerCase();
+/**
+ * Answer counts and "haven't replied" totals for every event in one go, so the
+ * dashboard never runs per-card queries. Deleted events are left out, matching
+ * `listHostEvents`; an unknown id simply has no entry. Three queries in total,
+ * whatever the number of events.
+ */
+export async function glanceForEvents(
+ db: Db,
+ eventIds: string[],
+): Promise> {
+ const result = new Map();
+ if (eventIds.length === 0) return result;
+
+ const liveEvents = await db
+ .select({ id: events.id })
+ .from(events)
+ .where(and(inArray(events.id, eventIds), isNull(events.deletedAt)));
+ const liveIds = liveEvents.map((event) => event.id);
+ if (liveIds.length === 0) return result;
+
+ const [guestRows, inviteeRows] = await Promise.all([
+ db
+ .select({ eventId: guests.eventId, name: guests.name, status: guests.status })
+ .from(guests)
+ .where(inArray(guests.eventId, liveIds)),
+ db
+ .select({ eventId: invitees.eventId, name: invitees.name })
+ .from(invitees)
+ .where(inArray(invitees.eventId, liveIds)),
+ ]);
+
+ const replied = new Map>();
+ for (const id of liveIds) {
+ result.set(id, { yes: 0, maybe: 0, no: 0, noReply: 0 });
+ replied.set(id, new Set());
+ }
+
+ for (const guest of guestRows) {
+ const glance = result.get(guest.eventId);
+ if (!glance) continue;
+ glance[guest.status] += 1;
+ replied.get(guest.eventId)?.add(nameKey(guest.name));
+ }
+
+ // Same rule as noReplyNames: an invitee counts as answered once a guest of the
+ // same trimmed, case-insensitive name exists, whatever that guest's status.
+ for (const invitee of inviteeRows) {
+ const glance = result.get(invitee.eventId);
+ if (!glance) continue;
+ if (!replied.get(invitee.eventId)?.has(nameKey(invitee.name))) glance.noReply += 1;
+ }
+
+ return result;
+}
+
/** Adds expected invitees: trimmed, blanks dropped, no case-insensitive duplicates. */
export async function addInvitees(
db: Db,
diff --git a/src/services/rsvp.test.ts b/src/services/rsvp.test.ts
index a70fcb3..2eed302 100644
--- a/src/services/rsvp.test.ts
+++ b/src/services/rsvp.test.ts
@@ -185,6 +185,7 @@ describe("getGuestByToken", () => {
status: "yes",
plusOneNames: ["Sam"],
foodNotes: "no nuts",
+ createdAt: expect.any(Date),
});
});
@@ -210,6 +211,9 @@ describe("getPublicEvent", () => {
goingCount: 4,
cancelledAt: null,
deletedAt: null,
+ detailsChangedAt: null,
+ coverEmoji: null,
+ coverColor: null,
});
const json = JSON.stringify(result);
for (const secret of ["Alex", "Sam", "Jo", "Bea", "secret allergy", "Cy", "Dee"]) {
diff --git a/src/services/rsvp.ts b/src/services/rsvp.ts
index 27cba1c..02050ac 100644
--- a/src/services/rsvp.ts
+++ b/src/services/rsvp.ts
@@ -20,6 +20,8 @@ export interface GuestView {
status: RsvpStatus;
plusOneNames: string[];
foodNotes: string | null;
+ /** When this guest answered: an earlier details change is already known to them. */
+ createdAt: Date;
}
const MAX_NAME = 80;
@@ -71,6 +73,11 @@ export interface PublicEvent {
cancelledAt: Date | null;
/** Set while the event is in the bin: the page shows "no longer available". */
deletedAt: Date | null;
+ /** Last time the time, zone or place moved; drives the guest "Updated" notice. */
+ detailsChangedAt: Date | null;
+ /** Preset cover; null means the default (๐ on mustard). */
+ coverEmoji: string | null;
+ coverColor: string | null;
}
const RSVP_CLOSED_DELETED = "This event is no longer available.";
@@ -177,6 +184,7 @@ export async function getGuestByToken(
status: guest.status,
plusOneNames: pos.map((p) => p.name),
foodNotes: guest.foodNotes,
+ createdAt: guest.createdAt,
};
}
@@ -199,6 +207,9 @@ export async function getPublicEvent(db: Db, shareCode: string): Promise