mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-14 07:05:24 +03:00
Add support for changes dialog when leaving without saving config editor
This commit is contained in:
parent
f6d1f610cb
commit
c7d75bf318
@ -124,12 +124,49 @@ function ConfigEditor() {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// monitoring state
|
||||||
|
|
||||||
|
const [hasChanges, setHasChanges] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!config || !modelRef.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
modelRef.current.onDidChangeContent(() => {
|
||||||
|
if (modelRef.current?.getValue() != config) {
|
||||||
|
setHasChanges(true);
|
||||||
|
} else {
|
||||||
|
setHasChanges(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, [config]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (config && modelRef.current) {
|
if (config && modelRef.current) {
|
||||||
modelRef.current.setValue(config);
|
modelRef.current.setValue(config);
|
||||||
|
setHasChanges(false);
|
||||||
}
|
}
|
||||||
}, [config]);
|
}, [config]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let listener: ((e: BeforeUnloadEvent) => void) | undefined;
|
||||||
|
if (hasChanges) {
|
||||||
|
listener = (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.returnValue = true;
|
||||||
|
return "Exit without saving?";
|
||||||
|
};
|
||||||
|
window.addEventListener("beforeunload", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
if (listener) {
|
||||||
|
window.removeEventListener("beforeunload", listener);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [hasChanges]);
|
||||||
|
|
||||||
if (!config) {
|
if (!config) {
|
||||||
return <ActivityIndicator />;
|
return <ActivityIndicator />;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user