mirror of
https://github.com/zadam/trilium.git
synced 2025-10-29 01:06:36 +01:00
chore(react/type_widgets): save on window closing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { MutableRef, useCallback, useContext, useDebugValue, useEffect, useLayoutEffect, useMemo, useRef, useState } from "preact/hooks";
|
||||
import { EventData, EventNames } from "../../components/app_context";
|
||||
import appContext, { EventData, EventNames } from "../../components/app_context";
|
||||
import { ParentComponent, refToJQuerySelector } from "./react_utils";
|
||||
import SpacedUpdate from "../../services/spaced_update";
|
||||
import { FilterLabelsByType, KeyboardActionNames, OptionNames, RelationNames } from "@triliumnext/commons";
|
||||
@@ -23,7 +23,6 @@ import protected_session_holder from "../../services/protected_session_holder";
|
||||
import server from "../../services/server";
|
||||
import { removeIndividualBinding } from "../../services/shortcuts";
|
||||
import { ViewScope } from "../../services/link";
|
||||
import { VirtualConsolePrinter } from "happy-dom";
|
||||
|
||||
export function useTriliumEvent<T extends EventNames>(eventName: T, handler: (data: EventData<T>) => void) {
|
||||
const parentComponent = useContext(ParentComponent);
|
||||
@@ -128,6 +127,13 @@ export function useEditorSpacedUpdate({ note, noteContext, getData, onContentCha
|
||||
await spacedUpdate.updateNowIfNecessary();
|
||||
})
|
||||
|
||||
// Save if needed upon window/browser closing.
|
||||
useEffect(() => {
|
||||
const listener = () => spacedUpdate.isAllSavedAndTriggerUpdate();
|
||||
appContext.addBeforeUnloadListener(listener);
|
||||
return () => appContext.removeBeforeUnloadListener(listener);
|
||||
}, []);
|
||||
|
||||
return spacedUpdate;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user