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
This commit is contained in:
parent
fb2157bbe0
commit
91e3e916d8
5 changed files with 92 additions and 43 deletions
22
app-admin/src/routes/preview/+page.server.ts
Normal file
22
app-admin/src/routes/preview/+page.server.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
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 };
|
||||
};
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
</svelte:head>
|
||||
|
||||
{#if blocks.length}
|
||||
<BlockRenderer {blocks} />
|
||||
<BlockRenderer {blocks} items={data.items} slots={data.slots} calendarEvents={data.calendarEvents} />
|
||||
{:else}
|
||||
<section class="mx-auto max-w-3xl px-6 py-20 text-center">
|
||||
<h1 class="text-4xl">No preview content</h1>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue