Every string the panel shows is computed here, server-side and in both languages: the status word, the formatted hours, the next-change line, the week strip and the banner. The renderer downstream only draws, so it has no access to the schedule and cannot disagree with this file about what the shop's hours are. Closing soon is still open and opening soon is still closed: the large word states the fact and the line under it carries the nuance, which is the only thing a passer-by can read from the pavement. A message someone took the trouble to write always wins the banner over the automatic notice. When its English translation has not landed yet, the French line shows alone rather than a placeholder. The snapshot test is the regression guard for the whole display pipeline: any change to the shape or to a computed string has to be acknowledged there before it can reach the panel. lib/screen is at 100% statements and 96% branches. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012cSY9pVhZmJUKNN7wf1Myd
87 lines
2.6 KiB
TypeScript
87 lines
2.6 KiB
TypeScript
/**
|
||
* The screen payload contract.
|
||
*
|
||
* This is the frozen boundary of the whole system: the resolver fills it, the
|
||
* renderer reads it, and a snapshot test pins it. Every string the panel shows
|
||
* is computed here, server-side — the renderer performs no business logic, it
|
||
* only draws. That is what makes the display testable without a device.
|
||
*
|
||
* Bump SCREEN_SCHEMA_VERSION when the shape changes, never silently.
|
||
*/
|
||
|
||
export const SCREEN_SCHEMA_VERSION = 1;
|
||
|
||
/**
|
||
* How much free text the bottom banner can hold before it stops fitting.
|
||
* Shared by the message editor's counter and the renderer, so the warning the
|
||
* user sees and the space actually available can never drift apart.
|
||
*/
|
||
export const MESSAGE_MAX_CHARS = 120;
|
||
|
||
export type ScreenStatus = 'OPEN' | 'CLOSED' | 'CLOSING_SOON' | 'OPENING_SOON';
|
||
|
||
/**
|
||
* Where the banner text came from: something a person wrote, or the automatic
|
||
* notice raised when the week departs from the reference schedule.
|
||
*/
|
||
export type ScreenBannerKind = 'MESSAGE' | 'SCHEDULE_TODAY' | 'SCHEDULE_WEEK';
|
||
|
||
export type ScreenToday = {
|
||
date_fr: string;
|
||
date_en: string;
|
||
status: ScreenStatus;
|
||
/** The single word shown in very large type. */
|
||
status_fr: string;
|
||
status_en: string;
|
||
/** "10:00 – 13:00 · 14:00 – 18:30", empty when closed all day. */
|
||
hours_text: string;
|
||
/** "Ferme à 18:30" / "Ouvre demain à 10:00", empty when there is nothing ahead. */
|
||
next_change_fr: string;
|
||
next_change_en: string;
|
||
is_exception: boolean;
|
||
};
|
||
|
||
export type ScreenWeekDay = {
|
||
label_fr: string;
|
||
label_en: string;
|
||
hours_text: string;
|
||
is_today: boolean;
|
||
is_closed: boolean;
|
||
is_exception: boolean;
|
||
};
|
||
|
||
export type ScreenBanner = {
|
||
kind: ScreenBannerKind;
|
||
text_fr: string;
|
||
text_en: string;
|
||
};
|
||
|
||
export type ScreenPayload = {
|
||
schema: number;
|
||
/** ISO 8601 with the shop's UTC offset, e.g. "2026-09-20T10:15:00+02:00". */
|
||
generated_at: string;
|
||
shop_name: string;
|
||
logo_url: string;
|
||
today: ScreenToday;
|
||
/** Always seven entries, Monday through Sunday of the current week. */
|
||
week: ScreenWeekDay[];
|
||
/** `null` when the shop has nothing to say, so the week block takes the room. */
|
||
banner: ScreenBanner | null;
|
||
};
|
||
|
||
/**
|
||
* Automatic banner wording. Pre-translated on purpose: these lines must never
|
||
* depend on the translation service being reachable.
|
||
*/
|
||
export const AUTO_BANNERS: Record<'SCHEDULE_TODAY' | 'SCHEDULE_WEEK', { fr: string; en: string }> =
|
||
{
|
||
SCHEDULE_TODAY: {
|
||
fr: "Changement d'horaire aujourd'hui",
|
||
en: 'Opening hours changed today',
|
||
},
|
||
SCHEDULE_WEEK: {
|
||
fr: 'Horaires exceptionnels cette semaine',
|
||
en: 'Unusual opening hours this week',
|
||
},
|
||
};
|