Bandeau « Mettre à jour » à la nouvelle version ; page d'autorisation : Refuser dans la barre ; test-browser sur le site assemblé
- update-banner.js : registerServiceWorker({ onUpdateReady }), confirmation
en séance (le brouillon survit au rechargement, vérifié dans le parcours).
- test-browser : le serveur sert une copie de make site (service worker
actif) ; le parcours publie une deuxième version en réécrivant sw.js.
- Clé désignée par son dernier groupe sur les écrans de confirmation.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
08cc995eef
commit
f4fdd558c8
+16
-3
@@ -2,7 +2,7 @@
|
||||
// minuteur, le routeur et ses écrans.
|
||||
|
||||
import { createStore } from "./ui/store.js";
|
||||
import { href, startRouter } from "./ui/router.js";
|
||||
import { href, parseRoute, startRouter } from "./ui/router.js";
|
||||
import { createTimer } from "./ui/timer.js";
|
||||
import { h } from "./ui/dom.js";
|
||||
import { screenHeader } from "./ui/layout.js";
|
||||
@@ -24,6 +24,8 @@ import { connectAiScreen } from "./ui/screens/connect-ai.js";
|
||||
import { createSyncService } from "./ui/sync-service.js";
|
||||
import { readPairFragment } from "./ui/sync-model.js";
|
||||
import { toast } from "./ui/feedback.js";
|
||||
import { updateBanner } from "./ui/update-banner.js";
|
||||
import { loadDraft } from "./ui/draft-storage.js";
|
||||
|
||||
import { openEventStore } from "./infra/event-store.js";
|
||||
import { decodeProposalFragment } from "./domain/link.js";
|
||||
@@ -42,7 +44,10 @@ store.load(await db.list());
|
||||
// l'ouverture, après chaque saisie, au retour du réseau ou sur l'onglet.
|
||||
export const sync = createSyncService({
|
||||
db, store,
|
||||
onNewProposals: (n) => toast(n > 1 ? `${n} nouvelles propositions : à voir à l'accueil.` : "Nouvelle proposition : à voir à l'accueil."),
|
||||
onNewProposals: (n) => {
|
||||
const what = n > 1 ? `${n} nouvelles propositions` : "Nouvelle proposition";
|
||||
toast(parseRoute(location.hash).name === "home" ? `${what} reçue${n > 1 ? "s" : ""}.` : `${what} : à voir à l'accueil.`);
|
||||
},
|
||||
});
|
||||
await sync.start();
|
||||
|
||||
@@ -105,7 +110,15 @@ function takePairLink() {
|
||||
}
|
||||
takePairLink();
|
||||
window.addEventListener("hashchange", takePairLink);
|
||||
registerServiceWorker();
|
||||
// Nouvelle version publiée, installée et en attente : un bandeau propose de la
|
||||
// prendre tout de suite (sinon, elle prend la main au lancement suivant).
|
||||
registerServiceWorker({
|
||||
onUpdateReady: (apply) => {
|
||||
if (document.querySelector(".update")) return;
|
||||
const banner = updateBanner({ apply, inSession: () => parseRoute(location.hash).name === "session" || loadDraft() !== null });
|
||||
document.body.insertBefore(banner, document.getElementById("app"));
|
||||
},
|
||||
});
|
||||
|
||||
const timer = createTimer();
|
||||
document.body.append(timer.node);
|
||||
|
||||
@@ -99,3 +99,13 @@
|
||||
.grid-nav > .tile:last-child:nth-child(odd) { grid-column: 1 / -1; }
|
||||
.sync-keybox { display: block; margin-top: var(--space-3); padding: var(--space-3); border: var(--b) dashed var(--ink); font-size: var(--fs-lg); text-align: center; overflow-wrap: anywhere; }
|
||||
.sync-cmd { font-family: var(--font-mark); font-size: var(--fs-sm); overflow-wrap: anywhere; }
|
||||
|
||||
/* ---- nouvelle version ----------------------------------------------------------------- */
|
||||
/* Bandeau carré en tête de page, sans animation : le texte en marquage, l'action
|
||||
en aplat jaune. */
|
||||
.update {
|
||||
max-width: calc(var(--max) - 2 * var(--gutter)); margin: var(--space-2) auto 0; width: calc(100% - 2 * var(--gutter));
|
||||
display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
|
||||
border: var(--b) solid var(--ink); padding: var(--space-2) var(--space-2) var(--space-2) var(--space-3);
|
||||
}
|
||||
.update__text { font-family: var(--font-mark); font-size: var(--fs-mark); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }
|
||||
|
||||
@@ -7,7 +7,7 @@ import { h } from "../dom.js";
|
||||
import { screenHeader, actionBar } from "../layout.js";
|
||||
import { href } from "../router.js";
|
||||
import { authorizeErrorText, parseConnectRequest, refusalUrl } from "../connect-model.js";
|
||||
import { maskKey } from "../sync-model.js";
|
||||
import { keyEnd } from "../sync-model.js";
|
||||
import { fact } from "./sync.js";
|
||||
import { normalizeSyncKey } from "../../domain/sync-crypto.js";
|
||||
|
||||
@@ -98,14 +98,14 @@ export function connectAiScreen({ service, nav, hash, leave = (url) => location.
|
||||
fact("Ce qu'elle voit", "Tes données en clair, le temps de chaque requête. Son fournisseur les garde selon ses propres règles.")),
|
||||
h("h2", { class: "tape" }, "Ta clé"),
|
||||
key
|
||||
? h("p", null, "Clé de cet appareil : ", h("code", { class: "sync-key" }, maskKey(key)))
|
||||
? h("p", null, "Clé de cet appareil, celle qui se termine par ", h("code", { class: "sync-key" }, keyEnd(key)), ".")
|
||||
: [
|
||||
h("p", { class: "muted" }, "Cet appareil n'est pas relié. Colle la clé d'un appareil relié (écran Synchro), ou active la synchro ici."),
|
||||
h("div", { class: "field sync-gap" }, h("label", { class: "field__label", for: "connect-key" }, "Ma clé de synchro"), input),
|
||||
h("a", { class: "btn btn--ghost btn--block", href: href.sync() }, "Activer la synchro sur cet appareil"),
|
||||
],
|
||||
status,
|
||||
h("button", { type: "button", class: "btn btn--block sync-gap", on: { click: refuse } }, "Refuser"),
|
||||
actionBar(allow)),
|
||||
// Les deux réponses côte à côte, à portée de pouce.
|
||||
actionBar(h("button", { type: "button", class: "btn btn--ghost btn--block btn--lg", on: { click: refuse } }, "Refuser"), allow)),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import { href } from "../router.js";
|
||||
import { confirmDialog, toast } from "../feedback.js";
|
||||
import { copyText } from "../files.js";
|
||||
import { plural } from "../format.js";
|
||||
import { maskKey, pairUrl, syncView } from "../sync-model.js";
|
||||
import { keyEnd, maskKey, pairUrl, syncView } from "../sync-model.js";
|
||||
import { generateSyncKey, normalizeSyncKey } from "../../domain/sync-crypto.js";
|
||||
|
||||
/** @typedef {import("../sync-service.js").SyncService} SyncService */
|
||||
@@ -291,9 +291,9 @@ export function pairScreen({ service, store, nav, key }) {
|
||||
title: "Relier",
|
||||
node: h("div", { class: "screen" },
|
||||
head("Relier cet appareil à ton journal ? Il recevra ton programme et tes séances, et ce que tu saisis ici rejoindra tes autres appareils."),
|
||||
h("p", { class: "mark" }, "Clé ", maskKey(key)),
|
||||
h("p", { class: "mark" }, "Clé se terminant par ", keyEnd(key)),
|
||||
current && h("p", { class: "coach-note coach-note--plain sync-gap" },
|
||||
`Cet appareil est relié à un autre journal (clé ${maskKey(current)}) : il passera à celui-ci, et ses données y seront recopiées.`),
|
||||
`Cet appareil est relié à un autre journal (clé se terminant par ${keyEnd(current)}) : il passera à celui-ci, et ses données y seront recopiées.`),
|
||||
n > 0 && h("p", { class: "coach-note coach-note--plain sync-gap" },
|
||||
`Cet appareil a déjà des données (${plural(n, "événement")}) : elles seront fusionnées avec le journal. Rien n'est effacé.`),
|
||||
h("p", { class: "muted sync-gap" }, "Qui a la clé a tout : ne relie que tes propres appareils."),
|
||||
|
||||
@@ -153,6 +153,9 @@ export function readPairFragment(hash) {
|
||||
return normalizeSyncKey(raw);
|
||||
}
|
||||
|
||||
/** Le dernier groupe de la clé, pour la reconnaître sans la montrer. @param {string} syncKey */
|
||||
export const keyEnd = (syncKey) => syncKey.split("-").pop() ?? "";
|
||||
|
||||
/**
|
||||
* La clé masquée : seul son dernier groupe reste lisible, pour la reconnaître.
|
||||
* @param {string} syncKey au format affiché
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
// Bandeau « Nouvelle version disponible » : une version publiée s'est installée
|
||||
// en arrière-plan (sw-register.js, onUpdateReady) et attend. « Mettre à jour »
|
||||
// la fait prendre la main tout de suite, puis recharge la page.
|
||||
//
|
||||
// Pendant une séance, on demande d'abord : le brouillon (draft-storage.js,
|
||||
// stockage local) survit au rechargement, mais le minuteur de repos repart de
|
||||
// zéro.
|
||||
|
||||
import { h } from "./dom.js";
|
||||
import { confirmDialog } from "./feedback.js";
|
||||
|
||||
/**
|
||||
* @param {{apply: () => void, inSession: () => boolean}} o
|
||||
* apply : active la nouvelle version et recharge ; inSession : une séance est en cours
|
||||
*/
|
||||
export function updateBanner({ apply, inSession }) {
|
||||
const go = h("button", { type: "button", class: "btn btn--primary btn--sm" }, "Mettre à jour");
|
||||
go.addEventListener("click", async () => {
|
||||
if (inSession()) {
|
||||
const ok = await confirmDialog({
|
||||
title: "Mettre à jour maintenant ?",
|
||||
lines: ["Ta séance en cours est gardée sur cet appareil : elle reprend où tu en es après le rechargement.",
|
||||
"Le minuteur de repos, lui, s'arrête."],
|
||||
confirm: "Mettre à jour", cancel: "Plus tard",
|
||||
});
|
||||
if (!ok) return;
|
||||
}
|
||||
go.disabled = true;
|
||||
apply();
|
||||
});
|
||||
return h("div", { class: "update", role: "status" }, h("p", { class: "update__text" }, "Nouvelle version disponible"), go);
|
||||
}
|
||||
Reference in New Issue
Block a user