|
|
|
|
@@ -22,7 +22,7 @@ import { EVENTS } from "@notesnook/core/dist/common";
|
|
|
|
|
import { useThemeEngineStore } from "@notesnook/theme";
|
|
|
|
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
|
|
|
import WebView from "react-native-webview";
|
|
|
|
|
import { db } from "../../../common/database";
|
|
|
|
|
import { DatabaseLogger, db } from "../../../common/database";
|
|
|
|
|
import useGlobalSafeAreaInsets from "../../../hooks/use-global-safe-area-insets";
|
|
|
|
|
import { DDS } from "../../../services/device-detection";
|
|
|
|
|
import {
|
|
|
|
|
@@ -147,7 +147,12 @@ export const useEditor = (
|
|
|
|
|
lastContentChangeTime.current = 0;
|
|
|
|
|
resetContent && (await commands.clearContent());
|
|
|
|
|
resetContent && (await commands.clearTags());
|
|
|
|
|
|
|
|
|
|
if (resetState) {
|
|
|
|
|
const newSessionId = makeSessionId();
|
|
|
|
|
await commands.setSessionId(newSessionId);
|
|
|
|
|
setSessionId(newSessionId);
|
|
|
|
|
|
|
|
|
|
isDefaultEditor &&
|
|
|
|
|
useEditorStore.getState().setCurrentlyEditingNote(null);
|
|
|
|
|
placeholderTip.current = TipManager.placeholderTip();
|
|
|
|
|
@@ -264,7 +269,8 @@ export const useEditor = (
|
|
|
|
|
saveCount.current++;
|
|
|
|
|
return id;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.log("Error saving note: ", e);
|
|
|
|
|
console.error(e);
|
|
|
|
|
DatabaseLogger.error(e as Error);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
[commands, isDefaultEditor, postMessage, readonly, reset]
|
|
|
|
|
@@ -279,6 +285,7 @@ export const useEditor = (
|
|
|
|
|
noteId: currentNote.current?.id as string
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
if (!note.contentId) return;
|
|
|
|
|
currentContent.current = await db.content?.raw(note.contentId);
|
|
|
|
|
}
|
|
|
|
|
}, []);
|
|
|
|
|
@@ -366,12 +373,23 @@ export const useEditor = (
|
|
|
|
|
if (!item.forced && currentNote.current?.id === item.id) return;
|
|
|
|
|
state.current.movedAway = false;
|
|
|
|
|
state.current.currentlyEditing = true;
|
|
|
|
|
isDefaultEditor && editorState.setCurrentlyEditingNote(item.id);
|
|
|
|
|
currentNote.current && (await reset(false, false));
|
|
|
|
|
|
|
|
|
|
if (currentNote.current?.id !== item.id) {
|
|
|
|
|
currentNote.current && (await reset(false, false));
|
|
|
|
|
isDefaultEditor && editorState.setCurrentlyEditingNote(item.id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await loadContent(item as NoteType);
|
|
|
|
|
if (loadingState.current === currentContent.current?.data) {
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
currentNote.current?.id === item.id &&
|
|
|
|
|
loadingState.current &&
|
|
|
|
|
currentContent.current?.data &&
|
|
|
|
|
loadingState.current === currentContent.current?.data
|
|
|
|
|
) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
!currentContent.current?.data ||
|
|
|
|
|
currentContent.current?.data.length < 50000
|
|
|
|
|
@@ -389,17 +407,20 @@ export const useEditor = (
|
|
|
|
|
lockedSessionId.current = nextSessionId;
|
|
|
|
|
sessionHistoryId.current = Date.now();
|
|
|
|
|
setSessionId(nextSessionId);
|
|
|
|
|
|
|
|
|
|
commands.setSessionId(nextSessionId);
|
|
|
|
|
sessionIdRef.current = nextSessionId;
|
|
|
|
|
currentNote.current = item as NoteType;
|
|
|
|
|
await commands.setStatus(getFormattedDate(item.dateEdited), "Saved");
|
|
|
|
|
await postMessage(EditorEvents.title, item.title);
|
|
|
|
|
loadingState.current = currentContent.current?.data;
|
|
|
|
|
await postMessage(
|
|
|
|
|
EditorEvents.html,
|
|
|
|
|
currentContent.current?.data,
|
|
|
|
|
10000
|
|
|
|
|
);
|
|
|
|
|
if (currentContent.current?.data) {
|
|
|
|
|
await postMessage(
|
|
|
|
|
EditorEvents.html,
|
|
|
|
|
currentContent.current?.data,
|
|
|
|
|
10000
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
loadingState.current = undefined;
|
|
|
|
|
useEditorStore.getState().setReadonly(item.readonly);
|
|
|
|
|
await commands.setTags(currentNote.current);
|
|
|
|
|
@@ -525,6 +546,14 @@ export const useEditor = (
|
|
|
|
|
}) => {
|
|
|
|
|
if (lock.current || lockedSessionId.current === forSessionId) return;
|
|
|
|
|
lastContentChangeTime.current = Date.now();
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
sessionHistoryId.current &&
|
|
|
|
|
Date.now() - sessionHistoryId.current > 5 * 60 * 1000
|
|
|
|
|
) {
|
|
|
|
|
sessionHistoryId.current = Date.now();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (type === EditorEvents.content) {
|
|
|
|
|
currentContent.current = {
|
|
|
|
|
data: content,
|
|
|
|
|
|