mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-29 00:20:04 +01:00
mobile: fix editor loading multiple times
This commit is contained in:
committed by
Abdullah Atta
parent
b40fe805e7
commit
ae7908e000
@@ -143,7 +143,6 @@ const Editor = React.memo(
|
||||
<WebView
|
||||
testID={notesnook.editor.id}
|
||||
ref={editor.ref}
|
||||
onLoad={editor.onLoad}
|
||||
key={renderKey.current}
|
||||
onRenderProcessGone={onError}
|
||||
nestedScrollEnabled
|
||||
|
||||
@@ -39,7 +39,7 @@ export const ProgressBar = () => {
|
||||
const [visible, setVisible] = useState(false);
|
||||
const timer = useRef<NodeJS.Timeout>();
|
||||
const insets = useGlobalSafeAreaInsets();
|
||||
const [width, setWidth] = useState(400);
|
||||
const [width, setWidth] = useState(0);
|
||||
|
||||
const groupProgressInfo = useRef<{
|
||||
[name: string]: {
|
||||
@@ -54,7 +54,6 @@ export const ProgressBar = () => {
|
||||
|
||||
useEffect(() => {
|
||||
if (loading) {
|
||||
console.log(loading);
|
||||
if (
|
||||
loading.current === loading.total &&
|
||||
typeof loading.success === "boolean"
|
||||
@@ -116,6 +115,7 @@ export const ProgressBar = () => {
|
||||
justifyContent: "center",
|
||||
position: "absolute",
|
||||
zIndex: visible ? 1 : -1,
|
||||
opacity: visible ? 1 : 0,
|
||||
marginTop: insets.top + 45,
|
||||
width: "100%"
|
||||
}}
|
||||
|
||||
@@ -42,5 +42,6 @@ export const EventTypes = {
|
||||
showTabs: "editor-events:show-tabs",
|
||||
tabFocused: "editor-events:tab-focused",
|
||||
toc: "editor-events:toc",
|
||||
createInternalLink: "editor-events:create-internal-link"
|
||||
createInternalLink: "editor-events:create-internal-link",
|
||||
load: "editor-events:load"
|
||||
};
|
||||
|
||||
@@ -343,6 +343,12 @@ export const useEditorEvents = (
|
||||
const data = event.nativeEvent.data;
|
||||
const editorMessage = JSON.parse(data) as EditorMessage<any>;
|
||||
|
||||
if (editorMessage.type === EventTypes.load) {
|
||||
console.log("Editor loaded");
|
||||
editor.onLoad();
|
||||
return;
|
||||
}
|
||||
|
||||
if (editorMessage.type === EventTypes.back) {
|
||||
return onBackPress();
|
||||
}
|
||||
|
||||
@@ -411,8 +411,6 @@ export const useEditor = (
|
||||
const noteIsLocked =
|
||||
event.item.locked && !(event.item as NoteWithContent).content;
|
||||
|
||||
console.log("noteIsLocked", noteIsLocked);
|
||||
|
||||
// If note was already opened in a tab, focus that tab.
|
||||
if (typeof event.tabId !== "number") {
|
||||
if (useTabStore.getState().hasTabForNote(event.item.id)) {
|
||||
@@ -422,7 +420,6 @@ export const useEditor = (
|
||||
readonly: event.item.readonly || readonly,
|
||||
locked: noteIsLocked
|
||||
});
|
||||
console.log(noteIsLocked, "focused tab...");
|
||||
useTabStore.getState().focusTab(tabId);
|
||||
}
|
||||
console.log("Note already loaded, focusing the tab");
|
||||
@@ -437,7 +434,6 @@ export const useEditor = (
|
||||
}
|
||||
} else {
|
||||
if (lastTabFocused.current !== event.tabId) {
|
||||
console.log("Focused tab");
|
||||
useTabStore.getState().focusTab(event.tabId);
|
||||
}
|
||||
}
|
||||
@@ -489,6 +485,7 @@ export const useEditor = (
|
||||
);
|
||||
|
||||
await postMessage(EditorEvents.title, item.title, tabId);
|
||||
overlay(false);
|
||||
loadingState.current = currentContents.current[item.id]?.data;
|
||||
|
||||
await postMessage(
|
||||
@@ -715,45 +712,24 @@ export const useEditor = (
|
||||
|
||||
const onLoad = useCallback(async () => {
|
||||
if (currentNotes.current) overlay(true);
|
||||
clearTimeout(timers.current["editor:loaded"]);
|
||||
timers.current["editor:loaded"] = setTimeout(async () => {
|
||||
postMessage(EditorEvents.theme, theme);
|
||||
commands.setInsets(
|
||||
isDefaultEditor ? insets : { top: 0, left: 0, right: 0, bottom: 0 }
|
||||
);
|
||||
await commands.setSettings();
|
||||
postMessage(EditorEvents.theme, theme);
|
||||
commands.setInsets(
|
||||
isDefaultEditor ? insets : { top: 0, left: 0, right: 0, bottom: 0 }
|
||||
);
|
||||
await commands.setSettings();
|
||||
|
||||
if (!state.current.ready && (await onReady())) {
|
||||
state.current.ready = true;
|
||||
}
|
||||
setTimeout(() => overlay(false), 300);
|
||||
if (!state.current.ready && (await onReady())) {
|
||||
state.current.ready = true;
|
||||
}
|
||||
|
||||
const noteId = useTabStore.getState().getCurrentNoteId();
|
||||
async function restoreTabNote() {
|
||||
if (!noteId) return;
|
||||
const note = await db.notes.note(noteId);
|
||||
if (!note) {
|
||||
console.log("Editor loaded with blank note");
|
||||
loadNote({ newNote: true });
|
||||
if (tabBarRef.current?.page === 1) {
|
||||
state.current.currentlyEditing = false;
|
||||
}
|
||||
}
|
||||
const noteId = useTabStore.getState().getCurrentNoteId();
|
||||
if (!noteId) {
|
||||
overlay(false);
|
||||
loadNote({ newNote: true });
|
||||
if (tabBarRef.current?.page === 1) {
|
||||
state.current.currentlyEditing = false;
|
||||
}
|
||||
|
||||
if (noteId) {
|
||||
if (useSettingStore.getState().isAppLoading) {
|
||||
const unsub = useSettingStore.subscribe(async (state) => {
|
||||
if (!state.isAppLoading) {
|
||||
restoreTabNote();
|
||||
unsub();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
restoreTabNote();
|
||||
}
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
}, [
|
||||
onReady,
|
||||
postMessage,
|
||||
|
||||
Reference in New Issue
Block a user