feat(website): the event feed both ways, and Linked products

Publish my events: the Website's simple events as crosscode.event/1
(GET /api/feed/v1/events, updatedSince, removals in deleted for 90
days) and a signed event.changed to linked siblings. Show events
from: each sibling's feed every 15 minutes and at once on its signed
event.changed; read-only copies of only that sibling's events, one
bad event skipped, the last good copy kept. Admin: Linked products.
church.changed from Accounts refreshes the profile at once. Plan:
the video hero, more blocks and more pages move to website@1.1.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 14:37:42 +02:00
co-authored by Claude Opus 5.5
parent 193a338ed2
commit b767b45e64
16 changed files with 632 additions and 17 deletions
@@ -0,0 +1,70 @@
"use client";
/**
* Linked products (§8, §9): the church's other sites as the Hub lists them. Accounts is how
* people sign in here (the Website links to it by itself). With Cross Events (and later the App),
* events flow either way: "Show events from" brings its events here, read-only and linking back
* for registering; "Publish my events" offers this site's simple events to them.
*/
import { api, canEdit } from "@/admin/api";
import { Btn, Loading, Notice, Panel, Title, useAction, useAdmin, when } from "@/admin/ui";
type Product = { installId: string; product: string; url: string; connected: boolean; listed: boolean; showEvents: boolean | null; events: number; lastSyncAt: string | null; lastSyncError: string | null };
const NAMES: Record<string, string> = { accounts: "Accounts (sign-in)", events: "Cross Events", app: "Church App", website: "Website" };
export default function Linked() {
const me = useAdmin<{ user: { role: string } }>("/me");
const { data, error, reload } = useAdmin<{ publishMyEvents: boolean; products: Product[] }>("/links");
const { busy, message, run } = useAction();
if (!data || !me.data) return <Loading error={error ?? me.error} />;
const editor = canEdit(me.data.user.role);
const manager = ["owner", "admin"].includes(me.data.user.role);
return (
<>
<Title sub="Your church's other sites. Events can flow between them in either direction.">Linked products</Title>
{message && <div className="mb-4"><Notice tone={message.tone}>{message.text}</Notice></div>}
<div className="space-y-6">
<Panel title="Publish my events">
<label className="flex items-start gap-3">
<input type="checkbox" className="mt-1" checked={data.publishMyEvents} disabled={!editor || busy}
onChange={(e) => run(async () => { await api("/feed", { method: "PUT", body: { publish: e.target.checked } }); await reload(); }, "Saved.")} />
<span>Offer the events you make here to your church&apos;s other sites (Cross Events, the App). They show them as read-only copies that link back here.</span>
</label>
</Panel>
{data.products.length === 0 && <Notice>No other sites yet. When your church has Cross Events or the App, they show here within 15 minutes.</Notice>}
{data.products.map((p) => (
<Panel key={p.installId}>
<div className="flex flex-wrap items-start justify-between gap-4">
<div>
<h2 className="text-lg font-semibold">{NAMES[p.product] ?? p.product}</h2>
<a href={p.url} className="text-sm text-brand-text underline-offset-4 hover:underline" rel="noopener">{p.url}</a>
<p className="mt-1 text-sm">{p.connected ? <span className="text-green-800">Connected</span> : <span className="text-gray-600">Not connected</span>}</p>
</div>
{manager && !p.connected && p.listed && <Btn kind="primary" busy={busy} onClick={() => run(async () => { await api(`/links/${p.installId}/connect`, { body: {} }); await reload(); }, "Connected.")}>Connect</Btn>}
{manager && p.connected && p.product !== "accounts" && <Btn kind="danger" busy={busy} onClick={() => run(async () => { await api(`/links/${p.installId}`, { method: "DELETE" }); await reload(); }, "Disconnected: its events are gone from here.")}>Disconnect</Btn>}
</div>
{p.product === "accounts" && p.connected && <p className="mt-3 text-sm text-gray-600">People sign in to this website&apos;s admin through it. This link stays.</p>}
{p.connected && p.product !== "accounts" && (
<div className="mt-4 space-y-2 border-t border-gray-200 pt-4">
<label className="flex items-center gap-3">
<input type="checkbox" checked={!!p.showEvents} disabled={!editor || busy}
onChange={(e) => run(async () => { await api(`/links/${p.installId}`, { method: "PUT", body: { showEvents: e.target.checked } }); await reload(); }, e.target.checked ? "Its events show here now." : "Its events are gone from here.")} />
<span>Show events from {NAMES[p.product]} on this website</span>
</label>
{p.showEvents && (
<p className="text-sm text-gray-600">
{p.events} {p.events === 1 ? "event" : "events"} from it{p.lastSyncAt && `, last checked ${when(p.lastSyncAt)}`}.{" "}
{editor && <Btn kind="link" onClick={() => run(async () => { await api(`/links/${p.installId}/sync`, { body: {} }); await reload(); }, "Checked.")}>Check now</Btn>}
</p>
)}
{p.lastSyncError && <Notice tone="warning">Last time: {p.lastSyncError}. The events from before keep showing.</Notice>}
</div>
)}
</Panel>
))}
</div>
</>
);
}