Events 3.7.2 + Website 1.6.1: no duplicate events after a reseed; "Events site" in the header

A reseed gives every event a new id without listing the old ones in the
feed's `deleted`, and consumers only fetched ?updatedSince= after the first
sync, so the old copies stayed beside the new ones.

- Both: the 15-minute feed poll and "Sync now" fetch the whole list and
  drop copies that aren't in it; the fetch after event.changed stays
  incremental.
- Events set-demo.js keeps FeedEntry and marks its live entries removed,
  resets the links' lastGoodAt, then publishes the new feed, sends
  event.changed and fetches the linked products' events back in.
- Website loadDemo lists the old published events in FeedRemoval and sends
  event.changed after publishing.
- Website header: links to the church's other sites read "Events site"
  with an external-link icon, not a second "Events".

Checked: Website backend tests (133), Events backend tests (802), both
typechecks, Website frontend build. set-demo.js not run end to end (no
local database).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-27 15:35:38 +02:00
co-authored by Claude Opus 5.5
parent a75d2f7b46
commit 7f681c9e81
24 changed files with 211 additions and 29 deletions
+23
View File
@@ -1,5 +1,28 @@
# Changelog — Church Website
## [1.6.1] — 2026-11-27
No migration, no new environment settings.
### Fixed
- **Events from Cross Events no longer show twice after Events is reseeded.** After the first
fetch, the Website only asked for what changed (`?updatedSince=`) and dropped a copy only when
the feed listed it in `deleted`. A reseed (or a restore) gives every event a new id without
listing the old ones, so the old copies stayed beside the new. The 15-minute poll and "Sync now"
now fetch the whole list and drop copies that aren't in it (`syncLink(…, { full: true })`); the
fetch after an `event.changed` still asks only for what changed.
- **Loading a demo (`npm run demo`, `crosscode demo … website`) tells Cross Events.** The old
published events go into the feed's `deleted` (`FeedRemoval`) and linked products get an
`event.changed`, so Events drops its copies straight away instead of showing them beside the
new ones.
### Changed
- **The header's links to the church's other sites say so:** "Events site" with an external-link
icon (title "Our separate site"), instead of "Events", which looked like a second link to this
site's own Events page.
## [1.6.0] — 2026-11-27
No migration, no new environment settings.
+8
View File
@@ -3,6 +3,14 @@
What each version changes for the church, in plain language (read by the Hub like Cross Events'
WHATS-NEW.md; a section shows once its version is tagged).
## 1.6.1
- **The link to your Cross Events site is easier to tell apart** in your website's menu: it now
says "Events site" with a small arrow icon, so visitors don't mistake it for your website's own
Events page.
- **Fixed: events from Cross Events could show twice** after the Events site's data was replaced.
Your website now checks the full list every 15 minutes and removes events that are gone.
## 1.6.0
- **Photos load faster on phones.** Photos in small frames (the collage at the top of the
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@crosscode/website-backend",
"version": "1.6.0",
"version": "1.6.1",
"description": "Church Website: the public site's content API, the admin API, publishing and uploads",
"private": true,
"type": "module",
+1 -1
View File
@@ -179,7 +179,7 @@ export function adminRouter(ctx: Ctx) {
r.post('/links/:id/sync', editor, handle(async (req) => {
const link = await ctx.db.productLink.findUnique({ where: { installId: param(req, 'id') } });
if (!link) throw new ApiError(404, 'NOT_LINKED', "That product isn't connected.");
return syncLink(ctx, link);
return syncLink(ctx, link, { full: true });
}));
r.put('/feed', editor, json, handle(async (req) => {
await ctx.settings.set('feed_publish', req.body?.publish === false ? 'false' : 'true');
+11 -2
View File
@@ -18,6 +18,7 @@ import { fileURLToPath } from 'node:url';
import { CHURCH_SCHEMA, WEBSITE_TEMPLATES, type agent, type Church, type WebsiteTemplate } from '@crosscode/contracts';
import type { Ctx } from '../context.js';
import { churchProfile } from '../church/profile.js';
import { markRemoved, notifyLinks } from '../feed/feed.js';
import type { SectionData } from '../site/sections.js';
import { publish } from '../site/snapshot.js';
import { TEMPLATE_HEADERS, TEMPLATE_VARIANTS, SECTION_TYPES, defaultDesign, type SiteDesign } from '../site/variants.js';
@@ -248,6 +249,10 @@ export async function loadDemo(ctx: Ctx, what: WebsiteTemplate | agent.WebsiteDe
// The site icon is a setting, so its picture stays; every other picture goes with the content.
const faviconId = classic ? null : await ctx.settings.get('favicon_media_id');
// 1.6.1: the published events that go are listed in the feed's `deleted`, so linked products
// (Cross Events) drop their copies instead of showing them beside the new ones.
const gone = (await db.simpleEvent.findMany({ where: { publishedAt: { not: null } }, select: { id: true } })).map((e) => e.id);
for (const id of gone) await markRemoved(ctx, id, true);
for (const m of ['section', 'page', 'ministry', 'leader', 'message', 'messageSeries', 'simpleEvent', 'siteVersion', 'siteDesign', 'slugHistory', 'previewLink'] as const) {
await (db[m] as unknown as { deleteMany: (a?: object) => Promise<unknown> }).deleteMany({});
}
@@ -324,9 +329,13 @@ export async function loadDemo(ctx: Ctx, what: WebsiteTemplate | agent.WebsiteDe
await db.message.create({ data: { slug, title, date: new Date(now.getTime() - ago * day), source: 'youtube', mediaUrl: 'https://www.youtube.com/watch?v=aqz-KE-bpKQ', thumbnailUrl, speaker, passage, seriesId: series.id, publishedAt: now } });
}
n = 0;
const made: string[] = [];
for (const [slug, title, inDays, description] of seed.events) {
const startsAt = new Date(Math.floor((now.getTime() + inDays * day) / day) * day + 8 * 3600e3);
await db.simpleEvent.create({ data: { slug, title, startsAt, endsAt: new Date(startsAt.getTime() + 3 * 3600e3), location: t(seed.venue), description: t(description), imageId: img[`event${n++}`] ?? null, publishedAt: now } });
made.push((await db.simpleEvent.create({ data: { slug, title, startsAt, endsAt: new Date(startsAt.getTime() + 3 * 3600e3), location: t(seed.venue), description: t(description), imageId: img[`event${n++}`] ?? null, publishedAt: now } })).id);
}
return publish(ctx, { id: opts.publishedBy ?? 'demo', role: 'system' }, classic ? `Demo church on ${seed.template}` : `Demo: ${seed.label}`);
const version = await publish(ctx, { id: opts.publishedBy ?? 'demo', role: 'system' }, classic ? `Demo church on ${seed.template}` : `Demo: ${seed.label}`);
// Linked products fetch the feed now, not at their next poll (one try; the poll catches up).
await notifyLinks(ctx, [...gone, ...made]).catch(() => {});
return version;
}
+9 -5
View File
@@ -113,15 +113,19 @@ type LinkRow = { installId: string; product: string; url: string; showEvents: bo
export type SyncResult = { installId: string; ok: boolean; imported?: number; deleted?: number; rejected?: number; error?: string };
/** Fetches one sibling's feed into read-only copies. */
export async function syncLink(ctx: Ctx, link: LinkRow): Promise<SyncResult> {
/**
* Fetches one sibling's feed into read-only copies. `full` asks for the whole list and drops copies
* no longer in it: a sibling that loses events without listing them in `deleted` (a reseed, a
* restore) would otherwise leave stale copies beside the new ones for good.
*/
export async function syncLink(ctx: Ctx, link: LinkRow, { full = false }: { full?: boolean } = {}): Promise<SyncResult> {
if (link.product === 'accounts') return { installId: link.installId, ok: true, imported: 0 };
if (!link.showEvents) {
const gone = (await ctx.db.importedEvent.deleteMany({ where: { linkId: link.installId } })).count;
return { installId: link.installId, ok: true, imported: 0, deleted: gone };
}
const now = ctx.now();
const since = link.lastGoodAt ? new Date(link.lastGoodAt.getTime() - OVERLAP_MS) : null;
const since = !full && link.lastGoodAt ? new Date(link.lastGoodAt.getTime() - OVERLAP_MS) : null;
try {
const url = await siblingUrl(ctx, link.url, FEED_PATHS.events);
if (since) url.searchParams.set('updatedSince', since.toISOString());
@@ -153,11 +157,11 @@ export async function syncLink(ctx: Ctx, link: LinkRow): Promise<SyncResult> {
}
}
/** Every linked sibling, one after another; one failing never stops the rest. */
/** Every linked sibling's whole list, one after another; one failing never stops the rest. */
export async function syncAll(ctx: Ctx) {
const links = await ctx.db.productLink.findMany({ where: { product: { not: 'accounts' } } });
let failed = 0;
for (const link of links) if (!(await syncLink(ctx, link)).ok) failed++;
for (const link of links) if (!(await syncLink(ctx, link, { full: true })).ok) failed++;
return { links: links.length, failed };
}
+13
View File
@@ -135,6 +135,19 @@ describe('showing events from Cross Events (Show events from)', () => {
assert.equal(await db.importedEvent.count(), 0);
});
it('a full fetch (the 15-minute poll) drops copies of events Events lost without saying (a reseed)', async () => {
const { ctx, events, link, db } = await site();
events.state.feed = { schema: EVENT_FEED_SCHEMA, generatedAt: new Date().toISOString(), deleted: [], events: [ev('6c7d8e9f-0a1b-4c2d-8e3f-4a5b6c7d8e9f', 'Family Fun Day', 10)] };
await syncLink(ctx, await link());
// Reseeded: the same event under a new id, and no word about the old one.
events.state.feed = { schema: EVENT_FEED_SCHEMA, generatedAt: new Date().toISOString(), deleted: [], events: [ev('9f0a1b2c-3d4e-4f5a-8b6c-7d8e9f0a1b2c', 'Family Fun Day', 10)] };
await syncLink(ctx, await link());
assert.equal(await db.importedEvent.count(), 2, 'an incremental fetch can\'t know');
await syncLink(ctx, await link(), { full: true });
assert.doesNotMatch(events.state.asked.at(-1)!, /updatedSince=/);
assert.deepEqual((await db.importedEvent.findMany()).map((e) => e.originId), ['9f0a1b2c-3d4e-4f5a-8b6c-7d8e9f0a1b2c']);
});
it('switching Show events off removes its events; a signed event.changed fetches at once', async () => {
const { ctx, events, link, db, go, app } = await site();
events.state.feed = { schema: EVENT_FEED_SCHEMA, generatedAt: new Date().toISOString(), deleted: [], events: [ev('6c7d8e9f-0a1b-4c2d-8e3f-4a5b6c7d8e9f', 'Youth camp', 10)] };
+12
View File
@@ -188,6 +188,18 @@ describe('the public site\'s content', () => {
assert.equal((await siteContent(h.ctx)).church?.name, 'Acacia Hill Church', 'the profile saved by the first demo stays');
});
it('1.6.1: loading a demo again lists the old events as removed in the feed, so Cross Events drops its copies', async () => {
const h = await harness({ linked: false });
const dir = tmp();
await loadDemo(h.ctx, 'heritage', { uploadDir: dir });
const old = (await h.db.simpleEvent.findMany()).map((e) => e.id).sort();
assert.ok(old.length > 0);
await loadDemo(h.ctx, 'community-town', { uploadDir: dir });
assert.deepEqual((await h.db.feedRemoval.findMany()).map((r) => r.eventId).sort(), old);
const now = (await h.db.simpleEvent.findMany()).map((e) => e.id);
assert.ok(now.length > 0 && now.every((id) => !old.includes(id)));
});
it('1.3.0: a profile on a site with no church profile at all saves the demo one, so the site has a name', async () => {
const h = await harness({ linked: false });
await loadDemo(h.ctx, 'clean-campus', { uploadDir: tmp() });
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@crosscode/website-frontend",
"version": "1.6.0",
"version": "1.6.1",
"private": true,
"description": "Church Website: the church's public site in its template, and the admin",
"scripts": {
+10 -4
View File
@@ -1,20 +1,23 @@
/**
* Each template's header (WEBSITE-1.0-PLAN §3, "Headers"), with its options from the Header style
* setting. Every header collapses to a Menu button on phones (a <details>, so it works without
* JavaScript). Links to the church's other sites (Events, App) sit next to the pages (§9).
* JavaScript). Links to the church's other sites sit next to the pages (§9), as "Events site" with an
* external-link icon (1.6.1), so they aren't mistaken for this site's own Events page.
*/
import Link from "next/link";
import { ExternalLink } from "lucide-react";
import { productLinks } from "@crosscode/ui";
import { ScrollSolid } from "./ScrollSolid";
import { cx } from "./parts";
import type { Published } from "./types";
type Item = { label: string; href: string; current: boolean };
/** `external`: one of the church's other sites (1.6.1), marked so it isn't mistaken for a page here. */
type Item = { label: string; href: string; current: boolean; external?: boolean };
function items(site: Published, path: string): { nav: Item[]; visit: Item | null } {
const pages = site.snapshot.pages;
const nav: Item[] = pages.filter((p) => p.inNav).map((p) => ({ label: p.navLabel, href: p.path, current: p.path === path }));
for (const l of site.church ? productLinks(site.church.links, "website") : []) nav.push({ label: l.label, href: l.href, current: false });
for (const l of site.church ? productLinks(site.church.links, "website") : []) nav.push({ label: `${l.label} site`, href: l.href, current: false, external: true });
const v = pages.find((p) => p.kind === "visit");
return { nav, visit: v ? { label: v.navLabel, href: v.path, current: v.path === path } : null };
}
@@ -36,7 +39,10 @@ function Links({ nav, className, linkClass }: { nav: Item[]; className?: string;
<ul className={className}>
{nav.map((n) => (
<li key={n.href}>
<a href={n.href} aria-current={n.current ? "page" : undefined} className={cx("no-underline hover:underline underline-offset-8", n.current && "underline", linkClass)}>{n.label}</a>
<a href={n.href} aria-current={n.current ? "page" : undefined} title={n.external ? "Our separate site" : undefined} className={cx("no-underline hover:underline underline-offset-8", n.current && "underline", n.external && "inline-flex items-center gap-1", linkClass)}>
{n.label}
{n.external && <ExternalLink className="h-[0.85em] w-[0.85em] shrink-0 opacity-70" aria-hidden />}
</a>
</li>
))}
</ul>