A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
feat: start loading attachments after editor loads
thecodrrde5452ce129b
diff --git a/apps/web/src/components/editor/index.tsx b/apps/web/src/components/editor/index.tsxindex ad2bd853e..6ddc5bd84 100644--- a/apps/web/src/components/editor/index.tsx+++ b/apps/web/src/components/editor/index.tsx@@ -87,9 +87,20 @@ export default function EditorManager({title.current = session.title;content.current = sessionContent?.data;setTimestamp(Date.now());- if (noteId && sessionContent) await db.attachments?.downloadImages(noteId);}, []);+ const loadMedia = useCallback(async () => {+ if (previewSession.current) {+ await db.content?.downloadMedia(+ noteId,+ previewSession.current.content,+ true+ );+ } else if (noteId && content.current) {+ await db.attachments?.downloadImages(noteId);+ }+ }, [noteId]);+useEffect(() => {if (!isNewSession) return;@@ -133,6 +144,7 @@ export default function EditorManager({options={{readonly: isReadonly,onRequestFocus: () => toggleProperties(false),+ onLoadMedia: loadMedia,}}/>{arePropertiesVisible && (@@ -142,10 +154,6 @@ export default function EditorManager({content.current = sessionContent.data;previewSession.current = session;setTimestamp(Date.now());-- if (noteId && sessionContent.data) {- await db.content?.downloadMedia(noteId, sessionContent, true);- }}}/>)}@@ -159,6 +167,7 @@ type EditorOptions = {readonly?: boolean;focusMode?: boolean;onRequestFocus?: () => void;+ onLoadMedia?: () => void;};type EditorProps = {title?: string;@@ -168,7 +177,7 @@ type EditorProps = {};export function Editor(props: EditorProps) {const { content, nonce, options } = props;- const { readonly, headless } = options || {+ const { readonly, headless, onLoadMedia } = options || {headless: false,readonly: false,focusMode: false,@@ -219,6 +228,9 @@ export function Editor(props: EditorProps) {readonly={readonly}toolbarContainerId={headless ? undefined : "editorToolbar"}content={content}+ onLoad={() => {+ if (onLoadMedia) onLoadMedia();+ }}onChange={(content) => {const { id, sessionId } = editorstore.get().session;debouncedOnEditorChange(sessionId, id, sessionId, content);diff --git a/apps/web/src/components/editor/tiptap.tsx b/apps/web/src/components/editor/tiptap.tsxindex 1d8bc5ee0..0cd587657 100644--- a/apps/web/src/components/editor/tiptap.tsx+++ b/apps/web/src/components/editor/tiptap.tsx@@ -24,6 +24,7 @@ import { showBuyDialog } from "../../common/dialog-controller";type TipTapProps = {editorContainer: HTMLElement;+ onLoad?: () => void;onChange?: (content: string) => void;onInsertAttachment?: (type: AttachmentType) => void;onDownloadAttachment?: (attachment: Attachment) => void;@@ -36,6 +37,7 @@ type TipTapProps = {function TipTap(props: TipTapProps) {const {+ onLoad,onChange,onInsertAttachment,onDownloadAttachment,@@ -84,9 +86,12 @@ function TipTap(props: TipTapProps) {},},});+ if (onLoad) onLoad();},onUpdate: ({ editor }) => {- if (onChange && editor.isEditable) onChange(editor.getHTML());+ if (!editor.isEditable) return;++ if (onChange) onChange(editor.getHTML());configure({statistics: {words: {@@ -135,7 +140,8 @@ function TipTap(props: TipTapProps) {return true;},},- [readonly, nonce, isMobile]+ // IMPORTANT: only put stuff here that the editor depends on.+ [readonly, nonce]);useEffect(() => {@@ -205,17 +211,18 @@ function Portal(props: PropsWithChildren<{ containerId?: string }>) {function toIEditor(editor: Editor): IEditor {return {- focus: () => editor.commands.focus("start"),- undo: () => editor.commands.undo(),- redo: () => editor.commands.redo(),+ focus: () => editor.current?.commands.focus("start"),+ undo: () => editor.current?.commands.undo(),+ redo: () => editor.current?.commands.redo(),attachFile: (file: Attachment) => {if (file.dataurl) {- editor.commands.insertImage({ ...file, src: file.dataurl });- } else editor.commands.insertAttachment(file);+ editor.current?.commands.insertImage({ ...file, src: file.dataurl });+ } else editor.current?.commands.insertAttachment(file);},- loadImage: (hash, src) => editor.commands.updateImage({ hash, src }),+ loadImage: (hash, src) =>+ editor.current?.commands.updateImage({ hash, src }),sendAttachmentProgress: (hash, type, progress) =>- editor.commands.setAttachmentProgress({+ editor.current?.commands.setAttachmentProgress({hash,type: type as any,progress,