publish websocket on config save

This commit is contained in:
Josh Hawkins 2026-01-21 11:44:06 -06:00
parent 688bef22f2
commit 98453a5cd9
3 changed files with 27 additions and 0 deletions

View File

@ -30,6 +30,7 @@ import { Trans, useTranslation } from "react-i18next";
import { useDocDomain } from "@/hooks/use-doc-domain"; import { useDocDomain } from "@/hooks/use-doc-domain";
import NameAndIdFields from "../input/NameAndIdFields"; import NameAndIdFields from "../input/NameAndIdFields";
import { Switch } from "../ui/switch"; import { Switch } from "../ui/switch";
import { useMotionMaskState } from "@/api/ws";
type MotionMaskEditPaneProps = { type MotionMaskEditPaneProps = {
polygons?: Polygon[]; polygons?: Polygon[];
@ -71,6 +72,11 @@ export default function MotionMaskEditPane({
} }
}, [polygons, activePolygonIndex]); }, [polygons, activePolygonIndex]);
const { send: sendMotionMaskState } = useMotionMaskState(
polygon?.camera || "",
polygon?.name || "",
);
const cameraConfig = useMemo(() => { const cameraConfig = useMemo(() => {
if (polygon?.camera && config) { if (polygon?.camera && config) {
return config.cameras[polygon.camera]; return config.cameras[polygon.camera];
@ -232,6 +238,8 @@ export default function MotionMaskEditPane({
}, },
); );
updateConfig(); updateConfig();
// Publish the enabled state through websocket
sendMotionMaskState(enabled ? "ON" : "OFF");
} else { } else {
toast.error( toast.error(
t("toast.save.error.title", { t("toast.save.error.title", {
@ -268,6 +276,7 @@ export default function MotionMaskEditPane({
setIsLoading, setIsLoading,
cameraConfig, cameraConfig,
t, t,
sendMotionMaskState,
], ],
); );

View File

@ -37,6 +37,7 @@ import { useTranslation } from "react-i18next";
import { getTranslatedLabel } from "@/utils/i18n"; import { getTranslatedLabel } from "@/utils/i18n";
import NameAndIdFields from "../input/NameAndIdFields"; import NameAndIdFields from "../input/NameAndIdFields";
import { Switch } from "../ui/switch"; import { Switch } from "../ui/switch";
import { useObjectMaskState } from "@/api/ws";
type ObjectMaskEditPaneProps = { type ObjectMaskEditPaneProps = {
polygons?: Polygon[]; polygons?: Polygon[];
@ -77,6 +78,11 @@ export default function ObjectMaskEditPane({
} }
}, [polygons, activePolygonIndex]); }, [polygons, activePolygonIndex]);
const { send: sendObjectMaskState } = useObjectMaskState(
polygon?.camera || "",
polygon?.name || "",
);
const cameraConfig = useMemo(() => { const cameraConfig = useMemo(() => {
if (polygon?.camera && config) { if (polygon?.camera && config) {
return config.cameras[polygon.camera]; return config.cameras[polygon.camera];
@ -253,6 +259,8 @@ export default function ObjectMaskEditPane({
}, },
); );
updateConfig(); updateConfig();
// Publish the enabled state through websocket
sendObjectMaskState(enabled ? "ON" : "OFF");
} else { } else {
toast.error( toast.error(
t("toast.save.error.title", { t("toast.save.error.title", {
@ -292,6 +300,7 @@ export default function ObjectMaskEditPane({
setIsLoading, setIsLoading,
cameraConfig, cameraConfig,
t, t,
sendObjectMaskState,
], ],
); );

View File

@ -35,6 +35,7 @@ import { LuExternalLink } from "react-icons/lu";
import { useDocDomain } from "@/hooks/use-doc-domain"; import { useDocDomain } from "@/hooks/use-doc-domain";
import { getTranslatedLabel } from "@/utils/i18n"; import { getTranslatedLabel } from "@/utils/i18n";
import NameAndIdFields from "../input/NameAndIdFields"; import NameAndIdFields from "../input/NameAndIdFields";
import { useZoneState } from "@/api/ws";
type ZoneEditPaneProps = { type ZoneEditPaneProps = {
polygons?: Polygon[]; polygons?: Polygon[];
@ -88,6 +89,11 @@ export default function ZoneEditPane({
} }
}, [polygons, activePolygonIndex]); }, [polygons, activePolygonIndex]);
const { send: sendZoneState } = useZoneState(
polygon?.camera || "",
polygon?.name || "",
);
const cameraConfig = useMemo(() => { const cameraConfig = useMemo(() => {
if (polygon?.camera && config) { if (polygon?.camera && config) {
return config.cameras[polygon.camera]; return config.cameras[polygon.camera];
@ -475,6 +481,8 @@ export default function ZoneEditPane({
}, },
); );
updateConfig(); updateConfig();
// Publish the enabled state through websocket
sendZoneState(enabled ? "ON" : "OFF");
} else { } else {
toast.error( toast.error(
t("toast.save.error.title", { t("toast.save.error.title", {
@ -515,6 +523,7 @@ export default function ZoneEditPane({
setIsLoading, setIsLoading,
cameraConfig, cameraConfig,
t, t,
sendZoneState,
], ],
); );