domaino/app-admin/src/routes/preview/+page.server.ts
agent 91e3e916d8 Shop block: share item loading with the admin preview, never render blank
The admin preview never received items/slots/events, so Shop and Upcoming
calendar blocks were empty there. loadShopData() (shared) now feeds both
the public layout and a new /preview loader.

A Shop block with nothing to show (no active items, a filter matching
none, or commerce data unavailable because POCKETBASE_ADMIN_* is unset)
now says so instead of rendering an empty section.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KgF3Kf47LjPGHKQHszpUAv
2026-10-06 12:06:05 +00:00

22 lines
1.1 KiB
TypeScript

import { eventOverlapsRange, getUpcomingCalendarRange, normalizeEvent } from '$lib/calendar';
import { loadShopData } from '$shared/server/shop';
import type { PageServerLoad } from './$types';
// The draft blocks come from sessionStorage (client-side), so load the data
// any block might need: shop items/slots and upcoming events. Failures leave
// the blocks empty rather than breaking the preview.
export const load: PageServerLoad = async ({ locals }) => {
const range = getUpcomingCalendarRange();
const [shop, events] = await Promise.all([
loadShopData(locals.pb).catch((e) => {
console.warn('Preview: shop data unavailable:', e instanceof Error ? e.message : e);
return { items: [], slots: [] };
}),
locals.pb
.collection('events')
.getFullList({ filter: locals.pb.filter('published = true && start <= {:end}', { end: range.end }), sort: 'start' })
.catch(() => [])
]);
const calendarEvents = events.map((event) => normalizeEvent(event)).filter((event) => eventOverlapsRange(event, range.start, range.end));
return { ...shop, calendarEvents };
};