fix notification suspend state lost on page reload (#23989)

<camera>/notifications/suspended arrives as a string over the live connection but as a number in the camera_activity snapshot, and the truthiness guard dropped the numeric 0, so a camera with notifications off rendered as active after a reload. Normalize to a string and derive isSuspended instead of storing it.
This commit is contained in:
Josh Hawkins
2026-08-13 16:51:44 -06:00
committed by GitHub
parent fd98977506
commit 812e5308a3
4 changed files with 17 additions and 26 deletions
+2 -2
View File
@@ -205,7 +205,7 @@ function applyCameraActivity(payload: string) {
);
applyTopicUpdate(
`${name}/notifications/suspended`,
notifications_suspended || 0,
String(notifications_suspended ?? 0),
);
applyTopicUpdate(
`${name}/ptz_autotracker/state`,
@@ -806,7 +806,7 @@ export function useNotificationSuspend(camera: string): {
`${camera}/notifications/suspended`,
`${camera}/notifications/suspend`,
);
return { payload: payload as string, send };
return { payload: String(payload ?? 0), send };
}
export function useNotificationTest(): {
@@ -746,18 +746,10 @@ export function CameraNotificationSwitch({
useNotifications(camera);
const { payload: notificationSuspendUntil, send: sendNotificationSuspend } =
useNotificationSuspend(camera);
const [isSuspended, setIsSuspended] = useState<boolean>(false);
useEffect(() => {
if (notificationSuspendUntil) {
setIsSuspended(
notificationSuspendUntil !== "0" || notificationState === "OFF",
);
}
}, [notificationSuspendUntil, notificationState]);
const isSuspended =
notificationSuspendUntil !== "0" || notificationState === "OFF";
const handleSuspend = (duration: string) => {
setIsSuspended(true);
if (duration == "off") {
sendNotification("OFF");
} else {
+2 -9
View File
@@ -228,15 +228,8 @@ export default function LiveContextMenu({
useNotifications(camera);
const { payload: notificationSuspendUntil, send: sendNotificationSuspend } =
useNotificationSuspend(camera);
const [isSuspended, setIsSuspended] = useState<boolean>(false);
useEffect(() => {
if (notificationSuspendUntil) {
setIsSuspended(
notificationSuspendUntil !== "0" || notificationState === "OFF",
);
}
}, [notificationSuspendUntil, notificationState]);
const isSuspended =
notificationSuspendUntil !== "0" || notificationState === "OFF";
const handleSuspend = (duration: string) => {
if (duration === "off") {