feat(weapons) : add conditions and unsaved changes warning
This commit is contained in:
@@ -134,6 +134,23 @@ export function useAutosave<Value, Draft = Value>({
|
||||
else if (fingerprint !== savedFingerprint) state = "unsaved";
|
||||
else state = "saved";
|
||||
|
||||
useEffect(() => {
|
||||
const browserWindow = window as Window & { __guideHasUnsavedChanges?: boolean };
|
||||
browserWindow.__guideHasUnsavedChanges = state !== "saved";
|
||||
if (state === "saved") return () => {
|
||||
browserWindow.__guideHasUnsavedChanges = false;
|
||||
};
|
||||
const warnBeforeLeaving = (event: BeforeUnloadEvent) => {
|
||||
event.preventDefault();
|
||||
event.returnValue = "";
|
||||
};
|
||||
window.addEventListener("beforeunload", warnBeforeLeaving);
|
||||
return () => {
|
||||
window.removeEventListener("beforeunload", warnBeforeLeaving);
|
||||
browserWindow.__guideHasUnsavedChanges = false;
|
||||
};
|
||||
}, [state]);
|
||||
|
||||
return {
|
||||
state,
|
||||
saveNow: () => {
|
||||
|
||||
Reference in New Issue
Block a user