mobile: fix editor tab bugs

This commit is contained in:
Ammar Ahmed
2024-03-12 11:53:52 +05:00
committed by Abdullah Atta
parent 6a8ccf9401
commit 8edcfcf2f1
5 changed files with 89 additions and 19 deletions

View File

@@ -541,6 +541,8 @@ export const useAppEvents = () => {
console.error(e); console.error(e);
} }
} }
//@ts-ignore
globalThis["IS_SHARE_EXTENSION"] = false;
} else { } else {
SettingsService.appEnteredBackground(); SettingsService.appEnteredBackground();
const id = useTabStore.getState().getCurrentNoteId(); const id = useTabStore.getState().getCurrentNoteId();

View File

@@ -549,7 +549,7 @@ export const useEditorEvents = (
const hash = (editorMessage.value as Attachment)?.hash; const hash = (editorMessage.value as Attachment)?.hash;
const attachment = await db.attachments?.attachment(hash); const attachment = await db.attachments?.attachment(hash);
if (!attachment) return; if (!attachment) return;
if (attachment.type.startsWith("image/")) { if (attachment.mimeType.startsWith("image/")) {
eSendEvent("ImagePreview", editorMessage.value); eSendEvent("ImagePreview", editorMessage.value);
} else { } else {
eSendEvent("PDFPreview", attachment); eSendEvent("PDFPreview", attachment);
@@ -585,7 +585,11 @@ export const useEditorEvents = (
); );
eSendEvent(eEditorTabFocused, editorMessage.tabId); eSendEvent(eEditorTabFocused, editorMessage.tabId);
if (!editorMessage.value && editorMessage.noteId) {
if (
(!editorMessage.value || editor.currentLoadingNoteId.current) &&
editorMessage.noteId
) {
if (!useSettingStore.getState().isAppLoading) { if (!useSettingStore.getState().isAppLoading) {
const note = await db.notes.note(editorMessage.noteId); const note = await db.notes.note(editorMessage.noteId);
if (note) { if (note) {

View File

@@ -389,6 +389,7 @@ export const useEditor = (
blockIdRef.current = event.blockId; blockIdRef.current = event.blockId;
} }
state.current.currentlyEditing = true; state.current.currentlyEditing = true;
if ( if (
!state.current.ready && !state.current.ready &&
(await isEditorLoaded( (await isEditorLoaded(
@@ -412,6 +413,13 @@ export const useEditor = (
if (!event.item) return; if (!event.item) return;
const item = event.item; const item = event.item;
const currentTab = useTabStore
.getState()
.getTab(useTabStore.getState().currentTab);
if (currentTab?.previewTab && item.id !== currentTab.noteId) {
await commands.setLoading(true, useTabStore.getState().currentTab);
}
const noteIsLocked = const noteIsLocked =
(await db.vaults.itemExists(event.item as ItemReference)) && (await db.vaults.itemExists(event.item as ItemReference)) &&
!(event.item as NoteWithContent).content; !(event.item as NoteWithContent).content;
@@ -455,6 +463,7 @@ export const useEditor = (
// console.log("tab id did not match after focus in 1000ms"); // console.log("tab id did not match after focus in 1000ms");
// return; // return;
// } // }
currentLoadingNoteId.current = item.id;
console.log("Waiting for tab to focus"); console.log("Waiting for tab to focus");
return; return;
} }
@@ -775,6 +784,7 @@ export const useEditor = (
onContentChanged, onContentChanged,
editorId: editorId, editorId: editorId,
overlay, overlay,
postMessage postMessage,
currentLoadingNoteId
}; };
}; };

View File

@@ -181,7 +181,8 @@ const Tiptap = ({
const _editor = useTiptap(tiptapOptions, [tiptapOptions]); const _editor = useTiptap(tiptapOptions, [tiptapOptions]);
const update = useCallback(() => { const update = useCallback(() => {
logger("info", "update content"); logger("info", "LOADING NOTE...");
_editor.commands.setTextSelection(0);
setTick((tick) => tick + 1); setTick((tick) => tick + 1);
setTimeout(() => { setTimeout(() => {
const noteState = tabRef.current.noteId const noteState = tabRef.current.noteId
@@ -208,7 +209,7 @@ const Tiptap = ({
); );
setTimeout(() => { setTimeout(() => {
editorControllers[tabRef.current.id]?.setLoading(false); editorControllers[tabRef.current.id]?.setLoading(false);
}); }, 300);
}, []); }, []);
const controller = useEditorController({ const controller = useEditorController({
@@ -263,10 +264,10 @@ const Tiptap = ({
) { ) {
editorControllers[tabRef.current.id]?.setLoading(true); editorControllers[tabRef.current.id]?.setLoading(true);
} }
post( post(
EventTypes.tabFocused, EventTypes.tabFocused,
!!globalThis.editorControllers[tabRef.current.id]?.content.current, !!globalThis.editorControllers[tabRef.current.id]?.content.current &&
!editorControllers[tabRef.current.id]?.loading,
tabRef.current.id, tabRef.current.id,
state.getCurrentNoteId() state.getCurrentNoteId()
); );
@@ -377,7 +378,7 @@ const Tiptap = ({
onScroll={controller.scroll} onScroll={controller.scroll}
ref={containerRef} ref={containerRef}
style={{ style={{
overflowY: "scroll", overflowY: controller.loading ? "hidden" : "scroll",
height: "100%", height: "100%",
display: "block", display: "block",
position: "relative" position: "relative"
@@ -386,16 +387,21 @@ const Tiptap = ({
{settings.noHeader || tab.locked ? null : ( {settings.noHeader || tab.locked ? null : (
<> <>
<Tags settings={settings} /> <Tags settings={settings} />
<Title
titlePlaceholder={controller.titlePlaceholder} {controller.loading ? null : (
readonly={settings.readonly} <>
controller={controllerRef} <Title
title={controller.title} titlePlaceholder={controller.titlePlaceholder}
fontFamily={settings.fontFamily} readonly={settings.readonly}
dateFormat={settings.dateFormat} controller={controllerRef}
timeFormat={settings.timeFormat} title={controller.title}
/> fontFamily={settings.fontFamily}
<StatusBar container={containerRef} /> dateFormat={settings.dateFormat}
timeFormat={settings.timeFormat}
/>
<StatusBar container={containerRef} />
</>
)}
</> </>
)} )}
@@ -585,6 +591,54 @@ const Tiptap = ({
</> </>
) : ( ) : (
<> <>
<div
style={{
height: 25,
width: "94%",
backgroundColor: colors.secondary.background,
borderRadius: 5,
marginTop: 10
}}
/>
<div
style={{
flexDirection: "row",
display: "flex",
gap: 10
}}
>
<div
style={{
height: 12,
width: 40,
backgroundColor: colors.secondary.background,
borderRadius: 5,
marginTop: 10
}}
/>
<div
style={{
height: 12,
width: 50,
backgroundColor: colors.secondary.background,
borderRadius: 5,
marginTop: 10
}}
/>
<div
style={{
height: 12,
width: 100,
backgroundColor: colors.secondary.background,
borderRadius: 5,
marginTop: 10
}}
/>
</div>
<div <div
style={{ style={{
height: 16, height: 16,

View File

@@ -244,7 +244,7 @@ export function useEditorController({
} }
case "native:html": case "native:html":
htmlContentRef.current = value; htmlContentRef.current = value;
logger("info", "loading html"); logger("info", "LOADING NOTE HTML");
if (!editor) break; if (!editor) break;
update(); update();
countWords(0); countWords(0);