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:
agent 2026-10-06 12:06:05 +00:00
parent fb2157bbe0
commit 91e3e916d8
5 changed files with 92 additions and 43 deletions

View file

@ -130,6 +130,14 @@
<h2 class="mb-12 text-center font-serif text-3xl text-charcoal md:text-4xl">{data.title}</h2>
{/if}
{#if !visibleItems.length}
<!-- Never an empty section: no active items, a filter that matches none,
or commerce data unavailable (see the public layout's server log). -->
<p class="rounded-2xl border border-dashed border-charcoal/15 px-6 py-10 text-center text-charcoal/60">
Nothing is available to book right now — please check back soon.
</p>
{/if}
<div class={isList ? 'flex flex-col gap-8' : 'grid gap-8 sm:grid-cols-2 lg:grid-cols-3'}>
{#each visibleItems as item (item.id)}
{@const ui = cardStates[item.id]}
@ -204,7 +212,7 @@
class="inline-flex items-center justify-center gap-2 rounded-full px-6 py-2.5 text-sm font-medium transition {ui?.pickerOpen
? 'border border-charcoal/15 text-charcoal hover:bg-charcoal/5'
: itemSlotsByDay?.size
? 'bg-sage text-white hover:bg-sage-dark'
? 'bg-sage text-primary-content hover:bg-sage-dark'
: 'cursor-not-allowed bg-charcoal/10 text-charcoal/50'}"
disabled={!itemSlotsByDay?.size && !ui?.pickerOpen}
onclick={() => togglePicker(item.id)}
@ -214,7 +222,7 @@
{:else}
<button
type="button"
class="inline-flex items-center justify-center gap-2 rounded-full bg-sage px-6 py-2.5 text-sm font-medium text-white transition hover:bg-sage-dark disabled:cursor-not-allowed disabled:bg-charcoal/10 disabled:text-charcoal/50"
class="inline-flex items-center justify-center gap-2 rounded-full bg-sage px-6 py-2.5 text-sm font-medium text-primary-content transition hover:bg-sage-dark disabled:cursor-not-allowed disabled:bg-charcoal/10 disabled:text-charcoal/50"
disabled={soldOut || ui?.adding}
onclick={() => addItem(item.id)}
>
@ -252,7 +260,7 @@
aria-pressed={selected}
onclick={() => (ui.selectedDayKey = day.dateKey)}
class="aspect-square rounded-full text-sm transition {selected
? 'bg-sage font-semibold text-white'
? 'bg-sage font-semibold text-primary-content'
: selectable
? 'cursor-pointer bg-sage/15 font-medium text-charcoal hover:bg-sage/35'
: 'cursor-default text-charcoal/25'} {!day.inMonth ? 'opacity-40' : ''} {day.isToday &&

View file

@ -0,0 +1,52 @@
import type PocketBase from 'pocketbase';
import { getFileUrl } from '../pb';
import type { ItemRecord, SlotRecord } from '../types';
/**
* Active items and future available slots, shaped for the Shop/Checkout
* blocks. Used by the public layout and the admin draft preview so both
* render the same shop.
*
* `pb` must be able to read items, slots and media (admin client on the
* public site, the logged-in superuser in the admin). Errors propagate.
*/
export async function loadShopData(pb: PocketBase): Promise<{ items: ItemRecord[]; slots: SlotRecord[] }> {
const [itemRecords, slotRecords] = await Promise.all([
pb.collection('items').getFullList({ filter: 'active = true', sort: 'name', expand: 'image' }),
pb.collection('slots').getFullList({
filter: pb.filter("status = 'available' && start >= {:now}", { now: new Date() }),
sort: 'start'
})
]);
const items = itemRecords.map((record): ItemRecord => {
const media = record.expand?.image;
return {
id: record.id,
name: record.name,
description: record.description || '',
price: record.price,
image: record.image || '',
imageUrl: media ? getFileUrl('media', media.id, media.file) : '',
type: record.type,
stock: record.stock ?? null,
duration: record.duration ?? null,
active: record.active
};
});
const slots = slotRecords.map(
(record): SlotRecord => ({
id: record.id,
item: record.item,
start: record.start,
end: record.end || '',
status: record.status,
heldUntil: record.heldUntil || null,
order: record.order || null,
notes: record.notes || ''
})
);
return { items, slots };
}