Files
crosscode-platform/apps/events/frontend/src/lib/linkedEvents.ts
T
joshuaandClaude Opus 5.5 716d47242a Events 2.4.0 frontend, deploy and docs: Linked products, linked events, seo
- Site settings → Linked products (Connect, Show events from, Publish my
  events), help, command palette.
- Events from linked products on /events, the home and campus pages, and
  /events/linked/<product>/<id> (markdown with HTML off, canonical to the
  origin, no JSON-LD, not in the sitemap).
- Event page JSON-LD from @crosscode/seo; lib/eventSchema.ts removed.
- Readiness check for linked products' sync; e2e spec with a fake
  Church Website (not run yet: needs the e2e Postgres).
- crosscode: install and build the shared packages Events uses first
  (an older tag still builds as before); scripts/tests/events.bats.
- Release notes, changelogs, handovers, hub-protocol.md, and the plan's
  "Changes while building".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 12:58:50 +02:00

40 lines
1.8 KiB
TypeScript

import type { CrosscodeEvent } from "@crosscode/contracts";
import { apiFetchListForPrerender } from "@/lib/api";
/**
* Events from the church's other products (2.4.0, Settings → Linked products → Show events from):
* read-only copies as `crosscode.event/1`, each with its own page here (/events/linked/…) that
* points search engines and visitors to the product it comes from.
*/
export type LinkedEvent = {
key: string;
product: "website" | "app";
productName: string;
event: CrosscodeEvent;
};
/** Upcoming linked events for a public page. Never fails the page: no events if the API can't answer. */
export async function fetchLinkedEvents(campus?: string): Promise<LinkedEvent[]> {
const query = campus ? `?campus=${encodeURIComponent(campus)}` : "";
try {
return await apiFetchListForPrerender<LinkedEvent>(`/api/v2/linked-events${query}`, { nextOptions: { next: { revalidate: 60 } } });
} catch {
return [];
}
}
/** This site's page for a linked event. */
export const linkedEventPath = (e: LinkedEvent) => `/events/linked/${e.product}/${e.event.id}`;
/** "From the Church Website". */
export const fromLabel = (e: LinkedEvent) => `From the ${e.productName}`;
/** Our events and linked ones in one list by start time. `startOf` gives our events' start. */
export function mergeByStart<T>(ours: T[], linked: LinkedEvent[], startOf: (e: T) => string): ({ kind: "own"; event: T } | { kind: "linked"; event: LinkedEvent })[] {
const all = [
...ours.map((event) => ({ kind: "own" as const, event, at: new Date(startOf(event)).getTime() })),
...linked.map((event) => ({ kind: "linked" as const, event, at: new Date(event.event.startsAt).getTime() })),
];
return all.sort((a, b) => a.at - b.at).map((x) => (x.kind === "own" ? { kind: "own" as const, event: x.event } : { kind: "linked" as const, event: x.event }));
}