Complete the six application screens
Adds the day timeline, team list, employee record and leave calendar. The design export shipped data for these but no markup, so their layout is designed here from the data shapes and the established style; only Aperçu and the week grid are ports. The day view carries a per-hour headcount band. Where the week view answers "who works how much", this one answers "who is on the floor at 14:00", and the band makes coverage gaps visible without reading every lane. Two fixes the tests and linter caught: - The poste derivation variables were missing from globals.css. Hues and tiers were ported but not the --post-*-bg/fg/edge that consume them, so every shift chip would have rendered colourless. The palette test now asserts all 36 exist. - ThemeToggle synced state in an effect. The document's data-theme attribute is the real store — it is set by the inline script before React exists — so it now subscribes with useSyncExternalStore instead of keeping a copy that is wrong on first render. Counter tests cover the DST cases in both directions: a 22:00–06:00 shift lasts 7 or 9 hours on the changeover nights, never 8. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Cr9dkEHwbDgkWPnyGj1Rjv
This commit is contained in:
12 files changed
+1158
-11
No files matched your search
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useSyncExternalStore } from 'react';
|
||||
|
||||
import { Button } from '@/components/ui/Button';
|
||||
|
||||
@@ -29,20 +29,34 @@ export const THEME_INIT_SCRIPT = `
|
||||
})();
|
||||
`.trim();
|
||||
|
||||
function readTheme(): Theme {
|
||||
if (typeof document === 'undefined') return 'light';
|
||||
/**
|
||||
* L'attribut `data-theme` du document est la source de vérité : il est posé par
|
||||
* le script ci-dessus avant l'hydratation, donc avant que React n'existe.
|
||||
* On s'y abonne plutôt que d'en tenir une copie, qui serait fausse au premier
|
||||
* rendu et devrait être rattrapée après coup.
|
||||
*/
|
||||
function subscribe(onChange: () => void): () => void {
|
||||
const observer = new MutationObserver(onChange);
|
||||
observer.observe(document.documentElement, {
|
||||
attributes: true,
|
||||
attributeFilter: ['data-theme'],
|
||||
});
|
||||
return () => observer.disconnect();
|
||||
}
|
||||
|
||||
function getSnapshot(): Theme {
|
||||
return document.documentElement.getAttribute('data-theme') === 'dark'
|
||||
? 'dark'
|
||||
: 'light';
|
||||
}
|
||||
|
||||
export function ThemeToggle() {
|
||||
const [theme, setTheme] = useState<Theme>('light');
|
||||
/** Le serveur rend toujours le thème clair, que le script corrige aussitôt. */
|
||||
function getServerSnapshot(): Theme {
|
||||
return 'light';
|
||||
}
|
||||
|
||||
// Le thème réel est posé par THEME_INIT_SCRIPT avant l'hydratation ; on le
|
||||
// lit après montage plutôt que de le deviner au rendu serveur, où
|
||||
// localStorage n'existe pas.
|
||||
useEffect(() => setTheme(readTheme()), []);
|
||||
export function ThemeToggle() {
|
||||
const theme = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
||||
|
||||
function toggle() {
|
||||
const next: Theme = theme === 'dark' ? 'light' : 'dark';
|
||||
@@ -51,9 +65,8 @@ export function ThemeToggle() {
|
||||
localStorage.setItem(THEME_STORAGE_KEY, next);
|
||||
} catch {
|
||||
// Stockage indisponible (navigation privée) : le thème reste valable
|
||||
// pour la session, ce qui est préférable à une erreur.
|
||||
// pour la session, ce qui vaut mieux qu'une erreur.
|
||||
}
|
||||
setTheme(next);
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
Reference in new issue
Block a user