French in, English out, with the character counter tied to the same constant the renderer uses — so the warning and the space actually available on the panel cannot drift apart. Translation is a second call, not part of the save. A slow or broken service must never cost the shop its message: the row is stored first and marked pending, the translation follows, and a failure shows as a badge with a retry rather than as a lost notice. The status transitions are the subtle part and are pinned by tests. Editing the French clears the English, including a translation someone had corrected by hand — a translation of text that has changed is worse than no translation. Editing only the dates or the priority leaves it alone. A hand-written translation is never overwritten while its French stands, and emptying it returns the row to pending. "On the screen" is decided by the same selector the renderer uses, so the badge cannot disagree with the panel about which message is live. The preview is served by the device's own pipeline — payload, SVG, threshold — so what the admin sees is the shop window down to the last thresholded pixel. A preview drawn any other way would eventually disagree with reality, quietly. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012cSY9pVhZmJUKNN7wf1Myd
55 lines
1.8 KiB
TypeScript
55 lines
1.8 KiB
TypeScript
import { auth } from '@/lib/auth';
|
|
import { prisma } from '@/lib/db';
|
|
import { selectActiveMessage } from '@/lib/screen/viewmodel';
|
|
|
|
import MessageManager, { type MessageRow } from './MessageManager';
|
|
|
|
export const metadata = { title: 'Messages — ITA ITO' };
|
|
|
|
export default async function MessagesPage() {
|
|
const [session, rows] = await Promise.all([
|
|
auth(),
|
|
prisma.message.findMany({ orderBy: [{ isActive: 'desc' }, { priority: 'desc' }, { createdAt: 'desc' }] }),
|
|
]);
|
|
|
|
const now = new Date();
|
|
|
|
// Which message the screen is actually showing, decided by the same function
|
|
// the renderer uses — so the badge cannot drift from the panel.
|
|
const live = selectActiveMessage(
|
|
rows.map((row) => ({
|
|
textFr: row.textFr,
|
|
textEn: row.textEn,
|
|
startsAt: row.startsAt,
|
|
endsAt: row.endsAt,
|
|
priority: row.priority,
|
|
isActive: row.isActive,
|
|
})),
|
|
now,
|
|
);
|
|
|
|
const messages: MessageRow[] = rows.map((row) => ({
|
|
id: row.id,
|
|
textFr: row.textFr,
|
|
textEn: row.textEn,
|
|
translationStatus: row.translationStatus,
|
|
startsAt: row.startsAt ? row.startsAt.toISOString().slice(0, 16).replace('T', ' ') : null,
|
|
endsAt: row.endsAt ? row.endsAt.toISOString().slice(0, 16).replace('T', ' ') : null,
|
|
priority: row.priority,
|
|
isActive: row.isActive,
|
|
isLive: live?.textFr === row.textFr && row.isActive,
|
|
}));
|
|
|
|
return (
|
|
<main className="mx-auto max-w-3xl px-4 py-10">
|
|
<h1 className="text-2xl">Messages</h1>
|
|
<p className="mt-2 max-w-prose text-[var(--ink-muted)]">
|
|
Le bandeau bas de l’écran. Saisi en français, traduit automatiquement en anglais. Un message
|
|
libre prend la place du bandeau automatique « horaires exceptionnels ».
|
|
</p>
|
|
|
|
<MessageManager canEdit={session?.user?.role === 'admin'} messages={messages} />
|
|
</main>
|
|
);
|
|
}
|