feat: explain a schedule change on the panel, and preview it in advance
Two things the shop asked for, and one it will notice. **A message on an exception.** A closure or a late opening can now carry a reason, and it reaches the panel. It shows while the door is shut and disappears the moment the shop opens — a notice explaining a late opening is worse than useless once the door is open. It outranks a free message on purpose: "closed this afternoon, back tomorrow" is what someone standing outside needs, and "new collection in store" can wait. Say so if you would rather it were the other way. The first version keyed this off the day's `isOpen`, which means "this day has opening hours" — so a day opening at 14:00 counted as open all morning, exactly when the reason is needed. A test caught it; the rule now reads the state at this minute. **Reusable phrases.** The same handful of notices get written over and over. /admin/modeles keeps them, translated once, and offers them wherever a message is composed — exceptions, closure periods, the banner. Picking one costs no translation at all: the saved English is reused directly, where the service takes the better part of ten seconds. Exception notes and holiday labels are translated too, which they were not before. After the save rather than during it, so a slow service never costs the shop its dates. **Previewing the future.** The dashboard can render the panel at any moment within about a year: "what will the window say while I'm away?" is worth answering before someone is standing in front of a locked door. The whole pipeline was already a function of "now", so this costs passing a different instant. An unparseable or absurd value falls back to the present rather than confidently rendering nonsense. Checked against a three-week holiday, which surfaced something worth knowing: the automatic "opens on…" line stays empty, because the resolver's search is bounded to fourteen days. During a long closure the message is the only thing that tells customers when the shop is back — which is a good reason for this feature to exist. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012cSY9pVhZmJUKNN7wf1Myd
This commit is contained in:
@@ -1,22 +1,30 @@
|
||||
import { publicBaseUrl } from '@/lib/config';
|
||||
import { encodeScreen } from '@/lib/screen/encode';
|
||||
import { parsePreviewTime } from '@/lib/screen/preview-time';
|
||||
import { renderScreenSvg } from '@/lib/screen/render';
|
||||
import { buildCurrentScreen } from '@/lib/screen/service';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
/**
|
||||
* The panel as it stands right now, as a PNG for the browser.
|
||||
* The panel as it stands, or as it will stand at a given moment.
|
||||
*
|
||||
* Deliberately the same pipeline the device is served from — payload, SVG,
|
||||
* threshold — so what the admin sees is what the shop window shows, down to
|
||||
* the last thresholded pixel. A preview drawn any other way would eventually
|
||||
* disagree with reality, and quietly.
|
||||
*
|
||||
* `?at=` moves the clock. The whole pipeline is already a function of "now",
|
||||
* so showing next Tuesday costs nothing but passing a different instant —
|
||||
* which is how a holiday closure can be checked before anyone is standing in
|
||||
* front of a locked door.
|
||||
*
|
||||
* Behind /api/admin, so the middleware requires a session.
|
||||
*/
|
||||
export async function GET(request: Request) {
|
||||
const { payload } = await buildCurrentScreen(new Date(), publicBaseUrl(request));
|
||||
const { at } = parsePreviewTime(new URL(request.url).searchParams.get('at'), new Date());
|
||||
|
||||
const { payload } = await buildCurrentScreen(at, publicBaseUrl(request));
|
||||
const png = encodeScreen(await renderScreenSvg(payload), 'png');
|
||||
|
||||
return new Response(new Uint8Array(png), {
|
||||
|
||||
Reference in New Issue
Block a user