forked from Github/frigate
UI fixes (#13246)
* Fix bad data in stats * Add support for changes dialog when leaving without saving config editor * Fix scrolling into view
This commit is contained in:
@@ -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(() => {
|
||||
if (config && modelRef.current) {
|
||||
modelRef.current.setValue(config);
|
||||
setHasChanges(false);
|
||||
}
|
||||
}, [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) {
|
||||
return <ActivityIndicator />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user