An administrator can make named displays (Hall TV, Office monitor) under Settings -> Share links, each with an address of its own (/wall/hall-tv), the pages it rotates through in the board's order, and a rotation speed. The signed-in wall opens one from its address and can switch between them, and a wall share link can open one too. The address still wins over the display's speed, then the browser's choice. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import { useCallback } from "react";
|
|
import { useSearchParams } from "react-router-dom";
|
|
import { rotateSeconds } from "../utils/wallPages";
|
|
|
|
const KEY = "wall.rotate";
|
|
|
|
function stored(): string | null {
|
|
try {
|
|
return localStorage.getItem(KEY);
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* How the wall display rotates: how many seconds each page stays, or null for the overview alone. It lives in the address (`?rotate=30`),
|
|
* so a TV's bookmark carries it, and this browser remembers the last choice made on the board itself. A named display may say how fast too (`configured`); the address still wins over it.
|
|
*/
|
|
export function useWallRotation(configured: number | null = null) {
|
|
const [params, setParams] = useSearchParams();
|
|
const seconds = rotateSeconds(params.get("rotate"), stored(), configured);
|
|
const setSeconds = useCallback(
|
|
(next: number | null) => {
|
|
try {
|
|
localStorage.setItem(KEY, next === null ? "off" : String(next));
|
|
} catch {
|
|
/* a private window: the address alone carries it */
|
|
}
|
|
setParams(
|
|
(prev) => {
|
|
const p = new URLSearchParams(prev);
|
|
p.set("rotate", next === null ? "off" : String(next));
|
|
return p;
|
|
},
|
|
{ replace: true },
|
|
);
|
|
},
|
|
[setParams],
|
|
);
|
|
return { seconds, setSeconds };
|
|
}
|