diff --git a/README.md b/README.md
index b230299..b83ae38 100644
--- a/README.md
+++ b/README.md
@@ -60,7 +60,7 @@ whether the page is running or paused.
The page checks 26 hosts on the internet, the WAN hosts:
-- `datavi.be`, pinned to the top at start
+- `datavi.be`, pinned to the top by default
- the Anthropic API and the OpenAI API
- the AWS Console, the Google Cloud Console and Microsoft Azure
- Cloudflare, Fastly, Akamai, Google, GitHub and Backblaze B2
@@ -130,7 +130,7 @@ top, and the figure still shows its real value.
From time to time, the page sorts the WAN rows by their latest latency: fastest
first, failed last. The pin button at the left of a row keeps the row at the
-top; pinned rows are sorted by name. `datavi.be` is pinned at start.
+top; pinned rows are sorted by name. `datavi.be` is pinned until you unpin it.
`Pause` stops the checks: the graphs keep scrolling with a gap for each paused
round, and the figures and dots turn gray. The `Interval` menu sets the time
@@ -138,6 +138,10 @@ between rounds: 1, 2, 3, 5, 10, 15, 30 or 60 seconds. Changing it clears the
history and starts a new round at once. The `Debug log` checkbox in the footer
opens a panel with the page's last 1000 log lines.
+The page keeps the interval and the pinned rows in the browser's `localStorage`,
+so a reload starts with them. Each browser keeps its own. A browser with no
+usable storage starts at 3 seconds with `datavi.be` pinned.
+
## Reporting
Every 60 seconds the page posts its undelivered samples as a report to
@@ -380,6 +384,8 @@ The page is built with Vite and Tailwind CSS v4. All its code is in
method `HEAD`.
- `HostState` and `AppState`: one host's history and status, and the whole
page's state.
+- `savedInterval`, `savedPinnedNames`, `saveInterval` and `savePinnedNames`:
+ read and write the interval and the pinned WAN hosts in `localStorage`.
- `measureLatency`: one check. `tick`: one round, which checks every host in
parallel. It draws each row as soon as its check ends, and with a WAN host's
row also the summary and the health box.
diff --git a/test/unit/main.test.js b/test/unit/main.test.js
index 91c0b9b..7e7f0e2 100644
--- a/test/unit/main.test.js
+++ b/test/unit/main.test.js
@@ -17,6 +17,10 @@ import {
log,
measureLatency,
Reporter,
+ savedInterval,
+ savedPinnedNames,
+ saveInterval,
+ savePinnedNames,
tick,
updateClocks,
updateSummary,
@@ -1054,3 +1058,90 @@ for (const { timedOut, unreachable = 0, answered, latency, health } of [
assert.equal(state.healthStatus(), health);
});
}
+
+// Gives test t a browser storage that keeps its values in saved, or, with
+// saved null, one that throws on every read and write, as a browser with
+// storage turned off does. It is removed when the test ends.
+function mockStorage(t, saved) {
+ const fail = () => {
+ throw new Error("The operation is insecure.");
+ };
+ globalThis.localStorage =
+ saved === null
+ ? { getItem: fail, setItem: fail }
+ : {
+ getItem: (key) => saved[key] ?? null,
+ setItem: (key, value) => {
+ saved[key] = value;
+ },
+ };
+ t.after(() => delete globalThis.localStorage);
+}
+
+// The interval menu's selected option in the page buildUI draws.
+function selectedInterval(t) {
+ const app = {};
+ t.mock.method(globalThis.document, "getElementById", () => app);
+ buildUI(new AppState([]));
+ return app.innerHTML.match(/`;
+ }).join("\n");
+}
+
export function buildUI(state) {
const app = document.getElementById("app");
app.innerHTML = `
@@ -869,14 +938,7 @@ export function buildUI(state) {
@@ -1520,7 +1582,8 @@ async function init() {
log.info(`Gateway detected: ${gateway.url}`);
}
- const state = new AppState(localHosts);
+ CONFIG.updateInterval = savedInterval();
+ const state = new AppState(localHosts, savedPinnedNames());
buildUI(state);
log.info("UI built, starting tick loop");
@@ -1560,6 +1623,7 @@ async function init() {
if (!host) return;
host.pinned = !host.pinned;
log.notice(`${host.pinned ? "Pinned" : "Unpinned"} ${host.name}`);
+ savePinnedNames(state);
sortAndRebuildWAN(state);
});
@@ -1592,6 +1656,7 @@ async function init() {
.addEventListener("change", (e) => {
const newInterval = parseInt(e.target.value, 10);
CONFIG.updateInterval = newInterval;
+ saveInterval(newInterval);
log.notice(
`Interval changed to ${humanDuration(newInterval / 1000)}, history reset`,
);