v0.2.0 — config admin (météo forcée, flash info, édition classe) + PWA
- DB : table day_weather (override admin par jour), flash_message sur classes - API : PUT/DELETE /api/config/day-weather, PUT /api/config/flash, PATCH /api/config/class - SSE : day_weather.updated/deleted, flash.updated, class.updated - Front : bandeau flash info, indicateur 'forcé' sur la frise, modale météo admin - Onglet Plus : panneau admin (flash info + édition classe), tout admin modifiable - PWA : manifest.webmanifest, service worker, meta Apple, icônes 192/512 - Web version accessible sur iOS via Safari (Ajouter à l'écran d'accueil)
This commit is contained in:
parent
6d154ed5fb
commit
246f989bdc
16 changed files with 782 additions and 86 deletions
|
|
@ -2,9 +2,20 @@
|
|||
<html lang="fr" class="h-full">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover" />
|
||||
<meta name="theme-color" content="#020617" />
|
||||
<title>Météo Exam</title>
|
||||
|
||||
<!-- PWA -->
|
||||
<link rel="manifest" href="/manifest.webmanifest" />
|
||||
<link rel="apple-touch-icon" href="/icon-192.png" />
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
<meta name="mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
||||
<meta name="apple-mobile-web-app-title" content="Météo Exam" />
|
||||
<meta name="description" content="Le calendrier des évaluations scolaires, en bulletin météo interactif." />
|
||||
|
||||
<!-- Fonts -->
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
||||
<link
|
||||
|
|
@ -19,5 +30,12 @@
|
|||
<body class="bg-slate-950 text-slate-100 font-sans h-full">
|
||||
<div id="app" class="flex items-center justify-center min-h-screen"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
<script>
|
||||
if ('serviceWorker' in navigator) {
|
||||
window.addEventListener('load', () => {
|
||||
navigator.serviceWorker.register('/sw.js').catch(() => {})
|
||||
})
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
BIN
web/public/icon-192.png
Normal file
BIN
web/public/icon-192.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
BIN
web/public/icon-512.png
Normal file
BIN
web/public/icon-512.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
31
web/public/manifest.webmanifest
Normal file
31
web/public/manifest.webmanifest
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"name": "Météo Exam",
|
||||
"short_name": "Météo Exam",
|
||||
"description": "Le calendrier des évaluations scolaires, en bulletin météo interactif.",
|
||||
"start_url": "/",
|
||||
"display": "standalone",
|
||||
"background_color": "#020617",
|
||||
"theme_color": "#020617",
|
||||
"orientation": "portrait",
|
||||
"lang": "fr",
|
||||
"icons": [
|
||||
{
|
||||
"src": "/icon-192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png",
|
||||
"purpose": "any"
|
||||
},
|
||||
{
|
||||
"src": "/icon-512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png",
|
||||
"purpose": "any"
|
||||
},
|
||||
{
|
||||
"src": "/icon-512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable"
|
||||
}
|
||||
]
|
||||
}
|
||||
39
web/public/sw.js
Normal file
39
web/public/sw.js
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
* Service worker Météo Exam.
|
||||
* - Cache les assets statiques (app shell) pour un démarrage hors ligne.
|
||||
* - Les appels API passent en network-first : les données restent fraîches.
|
||||
*/
|
||||
|
||||
const CACHE_NAME = 'meteo-exam-v2'
|
||||
const STATIC_ASSETS = ['/', '/index.html', '/manifest.webmanifest']
|
||||
|
||||
self.addEventListener('install', (event) => {
|
||||
event.waitUntil(
|
||||
caches.open(CACHE_NAME).then((cache) => cache.addAll(STATIC_ASSETS)),
|
||||
)
|
||||
self.skipWaiting()
|
||||
})
|
||||
|
||||
self.addEventListener('activate', (event) => {
|
||||
event.waitUntil(
|
||||
caches.keys().then((keys) =>
|
||||
Promise.all(keys.filter((k) => k !== CACHE_NAME).map((k) => caches.delete(k))),
|
||||
),
|
||||
)
|
||||
self.clients.claim()
|
||||
})
|
||||
|
||||
self.addEventListener('fetch', (event) => {
|
||||
const { request } = event
|
||||
const url = new URL(request.url)
|
||||
|
||||
// API et flux SSE : toujours réseau, pas de cache.
|
||||
if (url.pathname.startsWith('/api/')) return
|
||||
|
||||
// Assets statiques : cache d'abord, réseau en secours.
|
||||
if (request.method === 'GET' && (url.origin === self.location.origin || url.hostname === 'localhost')) {
|
||||
event.respondWith(
|
||||
caches.match(request).then((cached) => cached ?? fetch(request).catch(() => caches.match('/index.html'))),
|
||||
)
|
||||
}
|
||||
})
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { Capacitor, CapacitorHttp } from '@capacitor/core'
|
||||
import type { Exam, Session, StreamEvent } from '@meteo-exam/shared'
|
||||
import type { ClassInfo, DayWeather, Exam, FlashInfo, Session, StreamEvent, WeatherKind } from '@meteo-exam/shared'
|
||||
import { getBaseUrl, getToken } from './config'
|
||||
|
||||
export class ApiFailure extends Error {
|
||||
|
|
@ -13,7 +13,7 @@ export class ApiFailure extends Error {
|
|||
}
|
||||
|
||||
interface RequestOptions {
|
||||
method?: 'GET' | 'POST' | 'PATCH' | 'DELETE'
|
||||
method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'
|
||||
body?: unknown
|
||||
/** Jeton explicite, sinon celui du stockage local. */
|
||||
token?: string | null
|
||||
|
|
@ -106,6 +106,23 @@ export const api = {
|
|||
request<Exam>(`/api/exams/${id}`, { method: 'PATCH', body: input }),
|
||||
|
||||
deleteExam: (id: number) => request<void>(`/api/exams/${id}`, { method: 'DELETE' }),
|
||||
|
||||
// --- Config admin ---
|
||||
listDayWeather: () => request<DayWeather[]>('/api/config/day-weather'),
|
||||
|
||||
setDayWeather: (dayKey: string, kind: WeatherKind) =>
|
||||
request<DayWeather>('/api/config/day-weather', { method: 'PUT', body: { dayKey, kind } }),
|
||||
|
||||
clearDayWeather: (dayKey: string) =>
|
||||
request<void>(`/api/config/day-weather/${encodeURIComponent(dayKey)}`, { method: 'DELETE' }),
|
||||
|
||||
getFlash: () => request<FlashInfo>('/api/config/flash'),
|
||||
|
||||
setFlash: (message: string) =>
|
||||
request<FlashInfo>('/api/config/flash', { method: 'PUT', body: { message } }),
|
||||
|
||||
updateClass: (name: string, level: string | null) =>
|
||||
request<ClassInfo>('/api/config/class', { method: 'PATCH', body: { name, level } }),
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
114
web/src/store.ts
114
web/src/store.ts
|
|
@ -1,4 +1,4 @@
|
|||
import type { Exam, Session } from '@meteo-exam/shared'
|
||||
import type { ClassInfo, Exam, FlashInfo, Session } from '@meteo-exam/shared'
|
||||
import { dominantKind, type WeatherKind } from '@meteo-exam/shared'
|
||||
import { api, openStream } from './api'
|
||||
import { clearToken, getToken, setToken } from './config'
|
||||
|
|
@ -11,13 +11,17 @@ type Listener = () => void
|
|||
interface State {
|
||||
session: Session | null
|
||||
exams: Exam[]
|
||||
/** Jours affichés par la frise, indépendamment de la fenêtre chargée. */
|
||||
stripDays: Date[]
|
||||
selectedDay: string | null
|
||||
loading: boolean
|
||||
error: string | null
|
||||
/** Passé à true quand le jeton est refusé : l'app revient à l'écran d'accueil. */
|
||||
signedOut: boolean
|
||||
/** Overrides météo posés par l'admin, indexés par jour local AAAA-MM-JJ. */
|
||||
dayWeather: Map<string, WeatherKind>
|
||||
/** Flash info du jour (peut être null). */
|
||||
flash: FlashInfo | null
|
||||
/** Infos classe en direct (nom, niveau). */
|
||||
klass: ClassInfo | null
|
||||
}
|
||||
|
||||
const state: State = {
|
||||
|
|
@ -28,6 +32,9 @@ const state: State = {
|
|||
loading: false,
|
||||
error: null,
|
||||
signedOut: false,
|
||||
dayWeather: new Map(),
|
||||
flash: null,
|
||||
klass: null,
|
||||
}
|
||||
|
||||
const listeners = new Set<Listener>()
|
||||
|
|
@ -47,7 +54,6 @@ export const getState = (): Readonly<State> => state
|
|||
const windowBounds = (): { from: string; to: string } => {
|
||||
const from = new Date()
|
||||
from.setHours(0, 0, 0, 0)
|
||||
// On charge large : la frise fait 7 jours mais les cartes listent la fenêtre.
|
||||
const to = new Date(from.getTime() + WINDOW_DAYS * 86_400_000)
|
||||
return { from: from.toISOString(), to: to.toISOString() }
|
||||
}
|
||||
|
|
@ -65,17 +71,48 @@ export async function loadExams(): Promise<void> {
|
|||
emit()
|
||||
}
|
||||
|
||||
export async function loadConfig(): Promise<void> {
|
||||
try {
|
||||
const [dayWeather, flash] = await Promise.all([api.listDayWeather(), api.getFlash()])
|
||||
state.dayWeather = new Map(dayWeather.map((dw) => [dw.dayKey, dw.kind]))
|
||||
state.flash = flash
|
||||
} catch {
|
||||
// config secondaire : on ignore silencieusement
|
||||
}
|
||||
emit()
|
||||
}
|
||||
|
||||
function connectStream(): void {
|
||||
closeStream?.()
|
||||
closeStream = openStream((event) => {
|
||||
if (event.type === 'ping') return
|
||||
if (event.type === 'exam.deleted') {
|
||||
const idx = state.exams.findIndex((e) => e.id === event.examId)
|
||||
if (idx >= 0) state.exams.splice(idx, 1)
|
||||
} else {
|
||||
const index = state.exams.findIndex((e) => e.id === event.exam.id)
|
||||
if (index >= 0) state.exams[index] = event.exam
|
||||
else state.exams.push(event.exam)
|
||||
switch (event.type) {
|
||||
case 'ping':
|
||||
return
|
||||
case 'exam.deleted': {
|
||||
const idx = state.exams.findIndex((e) => e.id === event.examId)
|
||||
if (idx >= 0) state.exams.splice(idx, 1)
|
||||
break
|
||||
}
|
||||
case 'exam.created':
|
||||
case 'exam.updated': {
|
||||
const index = state.exams.findIndex((e) => e.id === event.exam.id)
|
||||
if (index >= 0) state.exams[index] = event.exam
|
||||
else state.exams.push(event.exam)
|
||||
break
|
||||
}
|
||||
case 'day_weather.updated':
|
||||
state.dayWeather.set(event.dayWeather.dayKey, event.dayWeather.kind)
|
||||
break
|
||||
case 'day_weather.deleted':
|
||||
state.dayWeather.delete(event.dayKey)
|
||||
break
|
||||
case 'flash.updated':
|
||||
state.flash = event.flash
|
||||
break
|
||||
case 'class.updated':
|
||||
state.klass = event.klass
|
||||
if (state.session) state.session = { ...state.session, klass: event.klass }
|
||||
break
|
||||
}
|
||||
state.exams.sort((a, b) => a.startsAt.localeCompare(b.startsAt))
|
||||
emit()
|
||||
|
|
@ -93,13 +130,17 @@ export async function bootstrap(): Promise<void> {
|
|||
emit()
|
||||
try {
|
||||
state.session = await api.me(token)
|
||||
state.klass = state.session.klass
|
||||
state.signedOut = false
|
||||
await loadExams()
|
||||
await Promise.all([loadExams(), loadConfig()])
|
||||
connectStream()
|
||||
} catch {
|
||||
clearToken()
|
||||
state.session = null
|
||||
state.exams = []
|
||||
state.dayWeather.clear()
|
||||
state.flash = null
|
||||
state.klass = null
|
||||
state.signedOut = true
|
||||
} finally {
|
||||
state.loading = false
|
||||
|
|
@ -110,10 +151,11 @@ export async function bootstrap(): Promise<void> {
|
|||
export async function loginAs(token: string, session: Session): Promise<void> {
|
||||
setToken(token)
|
||||
state.session = session
|
||||
state.klass = session.klass
|
||||
state.signedOut = false
|
||||
state.loading = true
|
||||
emit()
|
||||
await loadExams()
|
||||
await Promise.all([loadExams(), loadConfig()])
|
||||
connectStream()
|
||||
state.loading = false
|
||||
emit()
|
||||
|
|
@ -128,6 +170,9 @@ export function signOut(): void {
|
|||
state.selectedDay = null
|
||||
state.signedOut = false
|
||||
state.error = null
|
||||
state.dayWeather.clear()
|
||||
state.flash = null
|
||||
state.klass = null
|
||||
emit()
|
||||
}
|
||||
|
||||
|
|
@ -156,8 +201,14 @@ export function examsByDay(): Map<string, Exam[]> {
|
|||
return grouped
|
||||
}
|
||||
|
||||
/** Statut d'un jour : override admin > statut dominant des évaluations. */
|
||||
export function dayStatus(key: string): WeatherKind {
|
||||
return dominantKind(examsByDay().get(key) ?? [])
|
||||
return state.dayWeather.get(key) ?? dominantKind(examsByDay().get(key) ?? [])
|
||||
}
|
||||
|
||||
/** true si l'admin a forcé la météo de ce jour. */
|
||||
export function isDayOverridden(key: string): boolean {
|
||||
return state.dayWeather.has(key)
|
||||
}
|
||||
|
||||
export function todayExams(): Exam[] {
|
||||
|
|
@ -168,6 +219,14 @@ export function findExam(id: number): Exam | undefined {
|
|||
return state.exams.find((e) => e.id === id)
|
||||
}
|
||||
|
||||
export function currentFlash(): FlashInfo | null {
|
||||
return state.flash
|
||||
}
|
||||
|
||||
export function currentKlass(): ClassInfo | null {
|
||||
return state.klass ?? state.session?.klass ?? null
|
||||
}
|
||||
|
||||
// --- Écriture (admin) -------------------------------------------------------
|
||||
|
||||
export async function saveExam(input: unknown, id?: number): Promise<Exam> {
|
||||
|
|
@ -186,3 +245,28 @@ export async function removeExam(id: number): Promise<void> {
|
|||
state.exams = state.exams.filter((e) => e.id !== id)
|
||||
emit()
|
||||
}
|
||||
|
||||
export async function setDayWeather(dayKey: string, kind: WeatherKind): Promise<void> {
|
||||
await api.setDayWeather(dayKey, kind)
|
||||
state.dayWeather.set(dayKey, kind)
|
||||
emit()
|
||||
}
|
||||
|
||||
export async function clearDayWeather(dayKey: string): Promise<void> {
|
||||
await api.clearDayWeather(dayKey)
|
||||
state.dayWeather.delete(dayKey)
|
||||
emit()
|
||||
}
|
||||
|
||||
export async function setFlash(message: string): Promise<void> {
|
||||
const flash = await api.setFlash(message)
|
||||
state.flash = flash
|
||||
emit()
|
||||
}
|
||||
|
||||
export async function updateClass(name: string, level: string | null): Promise<void> {
|
||||
const klass = await api.updateClass(name, level)
|
||||
state.klass = klass
|
||||
if (state.session) state.session = { ...state.session, klass }
|
||||
emit()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,40 @@
|
|||
import { h, mount } from '../dom'
|
||||
import { getBaseUrl, setBaseUrl, DEFAULT_BASE_URL } from '../config'
|
||||
import { signOut } from '../store'
|
||||
import {
|
||||
currentFlash,
|
||||
currentKlass,
|
||||
isAdmin,
|
||||
setFlash,
|
||||
signOut,
|
||||
updateClass,
|
||||
} from '../store'
|
||||
import { showToast } from '../toast'
|
||||
|
||||
const inputClass =
|
||||
'w-full bg-slate-900/80 border border-slate-700/80 rounded-xl px-3.5 py-2.5 text-sm text-slate-100 placeholder-slate-500 focus:outline-none focus:border-sky-500 transition-colors'
|
||||
|
||||
const labelClass = 'block text-[10px] font-black uppercase tracking-wider text-slate-500 mb-1.5'
|
||||
|
||||
export function renderPlus(root: HTMLElement, rerender: () => void): void {
|
||||
const klass = currentKlass()
|
||||
const flash = currentFlash()
|
||||
const admin = isAdmin()
|
||||
|
||||
const serverInput = h('input', {
|
||||
class: 'w-full bg-slate-900/80 border border-slate-700/80 rounded-xl px-3.5 py-2.5 text-sm text-slate-100 focus:outline-none focus:border-sky-500 transition-colors',
|
||||
class: inputClass,
|
||||
value: getBaseUrl(),
|
||||
autocomplete: 'off',
|
||||
inputMode: 'url',
|
||||
})
|
||||
|
||||
const nameInput = h('input', { class: inputClass, value: klass?.name ?? '', placeholder: 'Terminale S2' })
|
||||
const levelInput = h('input', { class: inputClass, value: klass?.level ?? '', placeholder: 'Lycée' })
|
||||
const flashInput = h('textarea', {
|
||||
class: `${inputClass} min-h-[70px] resize-none`,
|
||||
placeholder: 'Message du jour pour la classe…',
|
||||
})
|
||||
flashInput.value = flash?.message ?? ''
|
||||
|
||||
const legendItems: { icon: string; title: string; accent: string; desc: string }[] = [
|
||||
{ icon: '☀️', title: 'Grand Soleil', accent: 'text-sky-400', desc: 'Journée calme. Aucun examen répertorié ni suspecté.' },
|
||||
{ icon: '🌫️', title: 'Brouillard', accent: 'text-purple-400', desc: 'Zone d’incertitude. Rumeur ou sous-entendu d’un professeur.' },
|
||||
|
|
@ -19,69 +43,140 @@ export function renderPlus(root: HTMLElement, rerender: () => void): void {
|
|||
{ icon: '🚨', title: 'Alerte Rouge / Tempête', accent: 'text-red-500', desc: 'Examen blanc, épreuve commune ou gros devoir de fin de trimestre.' },
|
||||
]
|
||||
|
||||
mount(
|
||||
root,
|
||||
const children: (Node | null)[] = []
|
||||
|
||||
// --- Panneau admin ---
|
||||
if (admin) {
|
||||
children.push(
|
||||
h(
|
||||
'div',
|
||||
{ class: 'bg-slate-800 border border-slate-700 rounded-2xl p-4 space-y-4' },
|
||||
h('div', { class: 'flex items-center gap-2' },
|
||||
h('i', { class: 'fa-solid fa-user-shield text-sky-400' }),
|
||||
h('h3', { class: 'text-xs font-black text-slate-400 uppercase tracking-wider' }, 'Configuration admin'),
|
||||
),
|
||||
|
||||
// Flash info
|
||||
h('div', {},
|
||||
h('span', { class: labelClass }, 'Flash info du jour'),
|
||||
flashInput,
|
||||
h('p', { class: 'text-[10px] text-slate-600 font-semibold mt-1' },
|
||||
'Message visible par toute la classe sur l’écran Météo.'),
|
||||
h(
|
||||
'button',
|
||||
{
|
||||
class: 'mt-2 w-full bg-sky-500 text-slate-950 text-xs font-extrabold py-2.5 rounded-xl active:scale-95 transition-transform',
|
||||
onclick: async () => {
|
||||
try {
|
||||
await setFlash(flashInput.value.trim())
|
||||
showToast('Flash info mis à jour', 'success')
|
||||
rerender()
|
||||
} catch (error) {
|
||||
showToast(error instanceof Error ? error.message : 'Erreur', 'reject')
|
||||
}
|
||||
},
|
||||
},
|
||||
'Publier le flash info',
|
||||
),
|
||||
),
|
||||
|
||||
// Édition classe
|
||||
h('div', { class: 'pt-3 border-t border-slate-700/60' },
|
||||
h('span', { class: labelClass }, 'Nom de la classe'),
|
||||
h('div', { class: 'grid grid-cols-2 gap-3' }, nameInput, levelInput),
|
||||
h(
|
||||
'button',
|
||||
{
|
||||
class: 'mt-2 w-full bg-indigo-500 text-white text-xs font-extrabold py-2.5 rounded-xl active:scale-95 transition-transform',
|
||||
onclick: async () => {
|
||||
try {
|
||||
await updateClass(nameInput.value.trim(), levelInput.value.trim() || null)
|
||||
showToast('Classe mise à jour', 'success')
|
||||
rerender()
|
||||
} catch (error) {
|
||||
showToast(error instanceof Error ? error.message : 'Erreur', 'reject')
|
||||
}
|
||||
},
|
||||
},
|
||||
'Enregistrer la classe',
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
// --- Serveur ---
|
||||
children.push(
|
||||
h(
|
||||
'div',
|
||||
{ class: 'space-y-5' },
|
||||
{ class: 'bg-slate-800 border border-slate-700 rounded-2xl p-4' },
|
||||
h('h3', { class: 'text-xs font-black text-slate-400 uppercase tracking-wider mb-3' }, 'Serveur API'),
|
||||
serverInput,
|
||||
h('p', { class: 'text-[10px] text-slate-500 font-semibold mt-2' },
|
||||
'Adresse de l’API. Émulateur : 10.0.2.2:8787 · Réseau local : IP du PC · Public : URL Tailscale.'),
|
||||
h(
|
||||
'div',
|
||||
{ class: 'bg-slate-800 border border-slate-700 rounded-2xl p-4' },
|
||||
h('h3', { class: 'text-xs font-black text-slate-400 uppercase tracking-wider mb-3' }, 'Serveur API'),
|
||||
serverInput,
|
||||
h('p', { class: 'text-[10px] text-slate-500 font-semibold mt-2' },
|
||||
'Adresse de l’API. Sur l’émulateur Android : 10.0.2.2:8787'),
|
||||
h(
|
||||
'button',
|
||||
{
|
||||
class: 'mt-3 w-full bg-sky-500 text-slate-950 text-xs font-extrabold py-2.5 rounded-xl active:scale-95 transition-transform',
|
||||
onclick: () => {
|
||||
setBaseUrl(serverInput.value.trim() || DEFAULT_BASE_URL)
|
||||
showToast('Adresse du serveur enregistrée', 'success')
|
||||
rerender()
|
||||
},
|
||||
'button',
|
||||
{
|
||||
class: 'mt-3 w-full bg-sky-500 text-slate-950 text-xs font-extrabold py-2.5 rounded-xl active:scale-95 transition-transform',
|
||||
onclick: () => {
|
||||
setBaseUrl(serverInput.value.trim() || DEFAULT_BASE_URL)
|
||||
showToast('Adresse du serveur enregistrée', 'success')
|
||||
rerender()
|
||||
},
|
||||
'Enregistrer l’adresse',
|
||||
),
|
||||
},
|
||||
'Enregistrer l’adresse',
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
// --- Session ---
|
||||
children.push(
|
||||
h(
|
||||
'div',
|
||||
{ class: 'bg-slate-800 border border-slate-700 rounded-2xl p-4' },
|
||||
h('h3', { class: 'text-xs font-black text-slate-400 uppercase tracking-wider mb-1' }, 'Session'),
|
||||
h(
|
||||
'div',
|
||||
{ class: 'bg-slate-800 border border-slate-700 rounded-2xl p-4' },
|
||||
h('h3', { class: 'text-xs font-black text-slate-400 uppercase tracking-wider mb-1' }, 'Session'),
|
||||
h(
|
||||
'button',
|
||||
{
|
||||
class: 'w-full bg-rose-500/10 border border-rose-500/25 text-rose-400 text-xs font-extrabold py-2.5 rounded-xl active:scale-95 transition-transform',
|
||||
onclick: () => {
|
||||
signOut()
|
||||
rerender()
|
||||
},
|
||||
'button',
|
||||
{
|
||||
class: 'w-full bg-rose-500/10 border border-rose-500/25 text-rose-400 text-xs font-extrabold py-2.5 rounded-xl active:scale-95 transition-transform',
|
||||
onclick: () => {
|
||||
signOut()
|
||||
rerender()
|
||||
},
|
||||
h('i', { class: 'fa-solid fa-right-from-bracket mr-1.5' }),
|
||||
'Se déconnecter',
|
||||
),
|
||||
},
|
||||
h('i', { class: 'fa-solid fa-right-from-bracket mr-1.5' }),
|
||||
'Se déconnecter',
|
||||
),
|
||||
h('div', {},
|
||||
h('h3', { class: 'text-xs font-black text-slate-400 uppercase tracking-wider mb-2' }, 'Légende météorologique'),
|
||||
h('div', { class: 'grid grid-cols-1 gap-2.5' },
|
||||
...legendItems.map((item) =>
|
||||
h(
|
||||
'div',
|
||||
{ class: 'bg-slate-800/80 border border-slate-700/60 rounded-xl p-3 flex items-center gap-3' },
|
||||
h('span', { class: 'text-3xl' }, item.icon),
|
||||
h('div', {},
|
||||
h('h4', { class: `text-sm font-black ${item.accent}` }, item.title),
|
||||
h('p', { class: 'text-xs text-slate-300 font-medium' }, item.desc),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
// --- Légende ---
|
||||
children.push(
|
||||
h('div', {},
|
||||
h('h3', { class: 'text-xs font-black text-slate-400 uppercase tracking-wider mb-2' }, 'Légende météorologique'),
|
||||
h('div', { class: 'grid grid-cols-1 gap-2.5' },
|
||||
...legendItems.map((item) =>
|
||||
h(
|
||||
'div',
|
||||
{ class: 'bg-slate-800/80 border border-slate-700/60 rounded-xl p-3 flex items-center gap-3' },
|
||||
h('span', { class: 'text-3xl' }, item.icon),
|
||||
h('div', {},
|
||||
h('h4', { class: `text-sm font-black ${item.accent}` }, item.title),
|
||||
h('p', { class: 'text-xs text-slate-300 font-medium' }, item.desc),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
h(
|
||||
'p',
|
||||
{ class: 'text-[10px] text-slate-600 font-semibold text-center' },
|
||||
'Météo Exam — v0.1.0 · Radar de rumeurs et métriques en phase 2',
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
children.push(
|
||||
h(
|
||||
'p',
|
||||
{ class: 'text-[10px] text-slate-600 font-semibold text-center' },
|
||||
'Météo Exam — v0.2.0 · Radar de rumeurs en phase 2',
|
||||
),
|
||||
)
|
||||
|
||||
mount(root, ...children.filter((c): c is Node => c !== null))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,12 +13,16 @@ import {
|
|||
} from '../dates'
|
||||
import { examCard, examDetail, weatherBadge } from './cards'
|
||||
import {
|
||||
clearDayWeather,
|
||||
currentFlash,
|
||||
dayStatus,
|
||||
examsByDay,
|
||||
getState,
|
||||
isAdmin,
|
||||
isDayOverridden,
|
||||
removeExam,
|
||||
selectDay,
|
||||
setDayWeather,
|
||||
setError,
|
||||
} from '../store'
|
||||
import { showToast } from '../toast'
|
||||
|
|
@ -105,7 +109,7 @@ function todayHero(onOpen: (exam: Exam) => void): HTMLElement {
|
|||
}
|
||||
|
||||
/** Frise horizontale des 7 prochains jours. */
|
||||
function weekStrip(): HTMLElement {
|
||||
function weekStrip(onAdminDay: (dayKey: string) => void): HTMLElement {
|
||||
const { stripDays, selectedDay } = getState()
|
||||
const today = new Date()
|
||||
|
||||
|
|
@ -118,6 +122,7 @@ function weekStrip(): HTMLElement {
|
|||
const count = examsByDay().get(key)?.length ?? 0
|
||||
const isToday = isSameDay(date, today)
|
||||
const active = selectedDay === key
|
||||
const overridden = isDayOverridden(key)
|
||||
|
||||
return h(
|
||||
'button',
|
||||
|
|
@ -127,7 +132,10 @@ function weekStrip(): HTMLElement {
|
|||
? 'bg-slate-700/60 border-sky-400/60'
|
||||
: 'bg-slate-800/70 border-slate-700/60'
|
||||
}`,
|
||||
onclick: () => selectDay(key),
|
||||
onclick: () => {
|
||||
if (isAdmin()) onAdminDay(key)
|
||||
else selectDay(key)
|
||||
},
|
||||
},
|
||||
h('span', { class: `text-[9px] font-black tracking-wider ${isToday ? 'text-sky-400' : 'text-slate-500'}` },
|
||||
isToday ? "AUJ." : dayNameShort(date)),
|
||||
|
|
@ -135,11 +143,118 @@ function weekStrip(): HTMLElement {
|
|||
h('span', { class: 'text-base leading-none' }, WEATHER[status].icon),
|
||||
h('span', { class: 'text-[9px] font-bold text-slate-500' },
|
||||
count === 0 ? '—' : `${count} éval.`),
|
||||
overridden
|
||||
? h('span', { class: 'text-[7px] font-black text-sky-400 uppercase' }, 'forcé')
|
||||
: null,
|
||||
)
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
/** Bandeau flash info du jour (message rédigé par l'admin). */
|
||||
function flashBanner(): HTMLElement | null {
|
||||
const flash = currentFlash()
|
||||
if (!flash?.message) return null
|
||||
return h(
|
||||
'div',
|
||||
{ class: 'bg-gradient-to-r from-sky-500/15 to-indigo-500/15 border border-sky-400/25 rounded-2xl p-3.5 flex items-start gap-2.5' },
|
||||
h('span', { class: 'text-lg leading-none mt-0.5' }, '📻'),
|
||||
h(
|
||||
'div',
|
||||
{ class: 'flex-1' },
|
||||
h('p', { class: 'text-[10px] font-black uppercase tracking-wider text-sky-400 mb-0.5' }, 'Flash info du jour'),
|
||||
h('p', { class: 'text-xs font-bold text-slate-200 leading-relaxed' }, flash.message),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
/** Modale admin : forcer la météo d'un jour. */
|
||||
function openDayWeatherModal(dayKeyValue: string, rerender: () => void): void {
|
||||
const overlay = h('div', {
|
||||
class: 'fixed inset-0 z-[95] bg-slate-950/80 backdrop-blur-sm flex items-end sm:items-center justify-center',
|
||||
})
|
||||
const close = (): void => overlay.remove()
|
||||
|
||||
const current = dayStatus(dayKeyValue)
|
||||
const [y, m, d] = dayKeyValue.split('-').map(Number)
|
||||
const date = new Date(y!, (m ?? 1) - 1, d ?? 1)
|
||||
|
||||
const options = h(
|
||||
'div',
|
||||
{ class: 'grid grid-cols-1 gap-2' },
|
||||
...(['soleil', 'brouillard', 'vent', 'orage', 'tempete'] as const).map((kind) => {
|
||||
const meta = WEATHER[kind]
|
||||
const active = current === kind && isDayOverridden(dayKeyValue)
|
||||
return h(
|
||||
'button',
|
||||
{
|
||||
class: `flex items-center gap-3 p-3 rounded-xl border text-left transition-colors ${
|
||||
active ? meta.badge : 'bg-slate-800/60 border-slate-700 text-slate-300'
|
||||
}`,
|
||||
onclick: async () => {
|
||||
try {
|
||||
await setDayWeather(dayKeyValue, kind)
|
||||
showToast(`Météo forcée : ${meta.label}`, 'success')
|
||||
close()
|
||||
rerender()
|
||||
} catch (error) {
|
||||
setError(error instanceof Error ? error.message : 'Erreur')
|
||||
showToast('Erreur lors de la mise à jour', 'reject')
|
||||
}
|
||||
},
|
||||
},
|
||||
h('span', { class: 'text-2xl' }, meta.icon),
|
||||
h('div', {},
|
||||
h('p', { class: 'text-sm font-black' }, meta.title),
|
||||
h('p', { class: 'text-[11px] font-semibold opacity-70' }, meta.hint),
|
||||
),
|
||||
)
|
||||
}),
|
||||
isDayOverridden(dayKeyValue)
|
||||
? h(
|
||||
'button',
|
||||
{
|
||||
class: 'w-full mt-2 bg-slate-800 border border-slate-700 text-slate-300 text-xs font-extrabold py-2.5 rounded-xl active:scale-95 transition-transform',
|
||||
onclick: async () => {
|
||||
try {
|
||||
await clearDayWeather(dayKeyValue)
|
||||
showToast('Override météo retiré', 'info')
|
||||
close()
|
||||
rerender()
|
||||
} catch (error) {
|
||||
setError(error instanceof Error ? error.message : 'Erreur')
|
||||
}
|
||||
},
|
||||
},
|
||||
h('i', { class: 'fa-solid fa-rotate-left mr-1.5' }),
|
||||
'Retirer l’override (météo auto)',
|
||||
)
|
||||
: null,
|
||||
)
|
||||
|
||||
const panel = h(
|
||||
'div',
|
||||
{ class: 'w-full sm:max-w-md bg-slate-900 border border-slate-700 rounded-t-[2rem] sm:rounded-[2rem] p-5 max-h-[85vh] overflow-y-auto no-scrollbar shadow-2xl' },
|
||||
h(
|
||||
'div',
|
||||
{ class: 'flex items-start justify-between gap-3 mb-4' },
|
||||
h('div', {},
|
||||
h('h2', { class: 'text-lg font-black text-slate-100' }, 'Météo du jour'),
|
||||
h('p', { class: 'text-xs text-slate-400 font-semibold mt-0.5' }, longDate(date)),
|
||||
),
|
||||
h('button', { class: 'text-slate-400 hover:text-slate-200 text-lg', onclick: close },
|
||||
h('i', { class: 'fa-solid fa-xmark' })),
|
||||
),
|
||||
options,
|
||||
)
|
||||
|
||||
overlay.append(panel)
|
||||
overlay.addEventListener('click', (event) => {
|
||||
if (event.target === overlay) close()
|
||||
})
|
||||
document.body.append(overlay)
|
||||
}
|
||||
|
||||
/** Liste groupée par jour, filtrée ou non par la frise. */
|
||||
function dayList(onOpen: (exam: Exam) => void): HTMLElement {
|
||||
const { selectedDay, stripDays } = getState()
|
||||
|
|
@ -261,16 +376,19 @@ function openDetail(exam: Exam, rerender: () => void): void {
|
|||
export function renderWeek(root: HTMLElement, rerender: () => void): void {
|
||||
const { error, session } = getState()
|
||||
const open = (exam: Exam): void => openDetail(exam, rerender)
|
||||
const openAdminDay = (dk: string): void => openDayWeatherModal(dk, rerender)
|
||||
|
||||
const children: (Node | null)[] = [
|
||||
flashBanner(),
|
||||
todayHero(open),
|
||||
h(
|
||||
'div',
|
||||
{ class: 'flex justify-between items-center pt-2' },
|
||||
h('h3', { class: 'text-base font-extrabold text-slate-200 uppercase tracking-wider' }, 'La carte de la semaine'),
|
||||
h('span', { class: 'text-xs font-bold text-sky-400' }, '7 prochains jours'),
|
||||
h('span', { class: 'text-xs font-bold text-sky-400' },
|
||||
isAdmin() ? 'Tapez un jour pour forcer la météo' : '7 prochains jours'),
|
||||
),
|
||||
weekStrip(),
|
||||
weekStrip(openAdminDay),
|
||||
]
|
||||
|
||||
if (error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue