mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-22 14:39:34 +01:00
mobile: update word count on exit
This commit is contained in:
@@ -106,6 +106,7 @@ typeof globalThis.editorTitle !== "undefined" && editorTitle.current && editorTi
|
|||||||
if (editorController.content) editorController.content.current = null;
|
if (editorController.content) editorController.content.current = null;
|
||||||
editorController.onUpdate();
|
editorController.onUpdate();
|
||||||
editorController.setTitle(null);
|
editorController.setTitle(null);
|
||||||
|
editorController.countWords(0);
|
||||||
typeof globalThis.statusBar !== "undefined" && statusBar.current.set({date:"",saved:""});
|
typeof globalThis.statusBar !== "undefined" && statusBar.current.set({date:"",saved:""});
|
||||||
`
|
`
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ export type EditorController = {
|
|||||||
titlePlaceholder: string;
|
titlePlaceholder: string;
|
||||||
openLink: (url: string) => boolean;
|
openLink: (url: string) => boolean;
|
||||||
setTitlePlaceholder: React.Dispatch<React.SetStateAction<string>>;
|
setTitlePlaceholder: React.Dispatch<React.SetStateAction<string>>;
|
||||||
|
countWords: (ms: number) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function useEditorController(update: () => void): EditorController {
|
export function useEditorController(update: () => void): EditorController {
|
||||||
@@ -84,7 +85,18 @@ export function useEditorController(update: () => void): EditorController {
|
|||||||
post(EventTypes.title, title);
|
post(EventTypes.title, title);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const contentChange = useCallback((editor: Editor) => {
|
const countWords = useCallback((ms = 300) => {
|
||||||
|
if (typeof timers.current.wordCounter === "number")
|
||||||
|
clearTimeout(timers.current.wordCounter);
|
||||||
|
timers.current.wordCounter = setTimeout(() => {
|
||||||
|
console.time("wordCounter");
|
||||||
|
statusBar?.current?.updateWords();
|
||||||
|
console.timeEnd("wordCounter");
|
||||||
|
}, ms);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const contentChange = useCallback(
|
||||||
|
(editor: Editor) => {
|
||||||
const currentSessionId = globalThis.sessionId;
|
const currentSessionId = globalThis.sessionId;
|
||||||
post(EventTypes.contentchange);
|
post(EventTypes.contentchange);
|
||||||
if (!editor) return;
|
if (!editor) return;
|
||||||
@@ -97,7 +109,9 @@ export function useEditorController(update: () => void): EditorController {
|
|||||||
}, 300);
|
}, 300);
|
||||||
|
|
||||||
countWords(5000);
|
countWords(5000);
|
||||||
}, []);
|
},
|
||||||
|
[countWords]
|
||||||
|
);
|
||||||
|
|
||||||
const scroll = useCallback(
|
const scroll = useCallback(
|
||||||
(_event: React.UIEvent<HTMLDivElement, UIEvent>) => {},
|
(_event: React.UIEvent<HTMLDivElement, UIEvent>) => {},
|
||||||
@@ -152,19 +166,9 @@ export function useEditorController(update: () => void): EditorController {
|
|||||||
}
|
}
|
||||||
post(type); // Notify that message was delivered successfully.
|
post(type); // Notify that message was delivered successfully.
|
||||||
},
|
},
|
||||||
[update]
|
[update, countWords]
|
||||||
);
|
);
|
||||||
|
|
||||||
function countWords(ms = 300) {
|
|
||||||
if (typeof timers.current.wordCounter === "number")
|
|
||||||
clearTimeout(timers.current.wordCounter);
|
|
||||||
timers.current.wordCounter = setTimeout(() => {
|
|
||||||
console.time("wordCounter");
|
|
||||||
statusBar?.current?.updateWords();
|
|
||||||
console.timeEnd("wordCounter");
|
|
||||||
}, ms);
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isReactNative()) return; // Subscribe only in react native webview.
|
if (!isReactNative()) return; // Subscribe only in react native webview.
|
||||||
const isSafari = navigator.vendor.match(/apple/i);
|
const isSafari = navigator.vendor.match(/apple/i);
|
||||||
@@ -208,6 +212,7 @@ export function useEditorController(update: () => void): EditorController {
|
|||||||
previewAttachment,
|
previewAttachment,
|
||||||
content: htmlContentRef,
|
content: htmlContentRef,
|
||||||
openLink,
|
openLink,
|
||||||
onUpdate: onUpdate
|
onUpdate: onUpdate,
|
||||||
|
countWords
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user