feat(home): onglets Aujourd'hui / Demain pour la carte Vigilance
Some checks are pending
Deploy info-canicule / deploy (push) Waiting to run
Some checks are pending
Deploy info-canicule / deploy (push) Waiting to run
Permet au visiteur de basculer entre la carte du jour et celle de J+1 (toujours présente dans le bulletin MF, sauf entre minuit et la pub de 6h où l'onglet est désactivé avec explication). Réutilise les helpers existants (currentEcheance, maxColorByDepartement) — pas de fetch supplémentaire, J et J1 sont déjà dans le snapshot. Bonus : - dayLabel calculé depuis "maintenant Paris" plutôt qu'un sample d'alerte → fonctionne en jour calme tout-vert. - CLAUDE.md : clarifie que MF officiel est canonique et Opendatasoft fallback (au lieu de la formulation "le jour où on bascule"). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
8638b260ff
commit
15635ed0e3
2 changed files with 73 additions and 12 deletions
|
|
@ -25,7 +25,17 @@ try {
|
|||
|
||||
// Determine l'écheance "aujourd'hui réel" — peut être J ou J1 selon l'heure
|
||||
// (entre minuit et la publication du bulletin suivant ~6h, J du bulletin = hier).
|
||||
const ech = snapshot ? currentEcheance(snapshot) : 'J';
|
||||
const todayEch: 'J' | 'J1' = snapshot ? currentEcheance(snapshot) : 'J';
|
||||
// "Demain" n'existe que quand `todayEch === 'J'` : le bulletin n'a pas de J2.
|
||||
// Entre minuit et la pub ~6h, on est sur J1 = aujourd'hui réel, donc pas de "demain" dispo.
|
||||
const tomorrowAvailable = todayEch === 'J';
|
||||
|
||||
// Onglet sélectionné via ?echeance=tomorrow ; défaut = today.
|
||||
const requestedView = new URL(Astro.request.url).searchParams.get('echeance');
|
||||
const view: 'today' | 'tomorrow' =
|
||||
requestedView === 'tomorrow' && tomorrowAvailable ? 'tomorrow' : 'today';
|
||||
const ech: 'J' | 'J1' = view === 'tomorrow' ? 'J1' : todayEch;
|
||||
|
||||
const colorsByDept = snapshot ? maxColorByDepartement(snapshot, ech) : new Map();
|
||||
const alertsToday = snapshot
|
||||
? snapshot.alerts.filter((a) => a.echeance === ech && a.colorId >= 2)
|
||||
|
|
@ -63,15 +73,18 @@ const productDate = snapshot?.productDatetime
|
|||
})
|
||||
: 'inconnu';
|
||||
|
||||
// Date de validité de l'écheance affichée (pour clarifier au visiteur)
|
||||
const dayLabel = (() => {
|
||||
if (!snapshot) return '';
|
||||
const sample = snapshot.alerts.find((a) => a.echeance === ech);
|
||||
if (!sample) return '';
|
||||
return new Date(sample.beginTime).toLocaleDateString('fr-FR', {
|
||||
// Date de validité de l'écheance affichée (pour clarifier au visiteur).
|
||||
// On la dérive du "maintenant" Paris (+1 jour si l'onglet "demain" est actif),
|
||||
// pas d'un sample d'alerte : en jour calme tout est vert, donc pas d'alerte sample.
|
||||
const fmtParisDate = (d: Date) =>
|
||||
d.toLocaleDateString('fr-FR', {
|
||||
weekday: 'long', day: 'numeric', month: 'long', timeZone: 'Europe/Paris',
|
||||
});
|
||||
})();
|
||||
const nowParis = new Date();
|
||||
const tomorrowParis = new Date(nowParis.getTime() + 86_400_000);
|
||||
const todayLabel = fmtParisDate(nowParis);
|
||||
const tomorrowLabel = fmtParisDate(tomorrowParis);
|
||||
const dayLabel = view === 'tomorrow' ? tomorrowLabel : todayLabel;
|
||||
---
|
||||
|
||||
<Base>
|
||||
|
|
@ -94,6 +107,56 @@ const dayLabel = (() => {
|
|||
</div>
|
||||
</section>
|
||||
|
||||
{
|
||||
!error && snapshot && (
|
||||
<section class="container-tight pt-6">
|
||||
<div role="tablist" aria-label="Échéance de la vigilance" class="inline-flex rounded-lg border border-slate-200 bg-white p-1 text-sm shadow-sm">
|
||||
<a
|
||||
href="/"
|
||||
role="tab"
|
||||
aria-selected={view === 'today' ? 'true' : 'false'}
|
||||
class:list={[
|
||||
'rounded-md px-4 py-1.5 font-medium no-underline transition-colors',
|
||||
view === 'today'
|
||||
? 'bg-canicule-700 text-white'
|
||||
: 'text-slate-700 hover:bg-slate-100',
|
||||
]}
|
||||
>
|
||||
Aujourd'hui
|
||||
<span class="ml-1 hidden text-xs opacity-80 sm:inline capitalize">· {todayLabel}</span>
|
||||
</a>
|
||||
{tomorrowAvailable ? (
|
||||
<a
|
||||
href="/?echeance=tomorrow"
|
||||
role="tab"
|
||||
aria-selected={view === 'tomorrow' ? 'true' : 'false'}
|
||||
class:list={[
|
||||
'rounded-md px-4 py-1.5 font-medium no-underline transition-colors',
|
||||
view === 'tomorrow'
|
||||
? 'bg-canicule-700 text-white'
|
||||
: 'text-slate-700 hover:bg-slate-100',
|
||||
]}
|
||||
>
|
||||
Demain
|
||||
<span class="ml-1 hidden text-xs opacity-80 sm:inline capitalize">· {tomorrowLabel}</span>
|
||||
</a>
|
||||
) : (
|
||||
<span
|
||||
role="tab"
|
||||
aria-selected="false"
|
||||
aria-disabled="true"
|
||||
title="L'échéance « demain » n'est plus disponible : Météo France publie le prochain bulletin vers 6h, qui couvrira à nouveau aujourd'hui + demain."
|
||||
class="cursor-not-allowed rounded-md px-4 py-1.5 font-medium text-slate-400"
|
||||
>
|
||||
Demain
|
||||
<span class="ml-1 hidden text-xs sm:inline">· en attente du prochain bulletin</span>
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
<section class="container-tight py-8">
|
||||
{
|
||||
error && (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue