mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-24 07:29:30 +01:00
editor: update word count immediately after note is loaded
Previously when opening note, the word count on mobile would be 0, then update to actual word count. This has been fixed so correct word count shows when opening not without any delay.
This commit is contained in:
@@ -33,7 +33,12 @@ function StatusBar({ container }: { container: RefObject<HTMLDivElement> }) {
|
|||||||
const currentWords = useRef(words);
|
const currentWords = useRef(words);
|
||||||
const interval = useRef(0);
|
const interval = useRef(0);
|
||||||
const statusBar = useRef({
|
const statusBar = useRef({
|
||||||
set: setStatus
|
set: setStatus,
|
||||||
|
updateWords: () => {
|
||||||
|
const words = getTotalWords(editor as Editor) + " words";
|
||||||
|
if (currentWords.current === words) return;
|
||||||
|
setWords(words);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
globalThis.statusBar = statusBar;
|
globalThis.statusBar = statusBar;
|
||||||
|
|
||||||
@@ -66,11 +71,10 @@ function StatusBar({ container }: { container: RefObject<HTMLDivElement> }) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
clearInterval(interval.current);
|
clearInterval(interval.current);
|
||||||
interval.current = setInterval(() => {
|
interval.current = setInterval(
|
||||||
const words = getTotalWords(editor as Editor) + " words";
|
statusBar.current.updateWords,
|
||||||
if (currentWords.current === words) return;
|
3000
|
||||||
setWords(words);
|
) as unknown as number;
|
||||||
}, 3000) as unknown as number;
|
|
||||||
return () => {
|
return () => {
|
||||||
clearInterval(interval.current);
|
clearInterval(interval.current);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -123,12 +123,13 @@ export function useEditorController(update: () => void): EditorController {
|
|||||||
from,
|
from,
|
||||||
to
|
to
|
||||||
});
|
});
|
||||||
|
statusBar.current?.updateWords();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "native:html":
|
case "native:html":
|
||||||
htmlContentRef.current = value;
|
htmlContentRef.current = value;
|
||||||
update();
|
update();
|
||||||
|
statusBar.current?.updateWords();
|
||||||
break;
|
break;
|
||||||
case "native:theme":
|
case "native:theme":
|
||||||
useEditorThemeStore.getState().setColors(message.value);
|
useEditorThemeStore.getState().setColors(message.value);
|
||||||
@@ -156,7 +157,6 @@ export function useEditorController(update: () => void): EditorController {
|
|||||||
if (isSafari) {
|
if (isSafari) {
|
||||||
root = window;
|
root = window;
|
||||||
}
|
}
|
||||||
console.log("recreating messaging");
|
|
||||||
root.addEventListener("message", onMessage);
|
root.addEventListener("message", onMessage);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ declare global {
|
|||||||
saved: string;
|
saved: string;
|
||||||
}>
|
}>
|
||||||
>;
|
>;
|
||||||
|
updateWords: () => void;
|
||||||
}>;
|
}>;
|
||||||
var __PLATFORM__: "ios" | "android";
|
var __PLATFORM__: "ios" | "android";
|
||||||
var readonly: boolean;
|
var readonly: boolean;
|
||||||
|
|||||||
Reference in New Issue
Block a user