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
web: set session id on saving note
Abdullah Atta144d3625271e
diff --git a/apps/web/src/components/editor/index.tsx b/apps/web/src/components/editor/index.tsxindex b5919ec9e..d20dd1143 100644--- a/apps/web/src/components/editor/index.tsx+++ b/apps/web/src/components/editor/index.tsx@@ -73,16 +73,10 @@ type DocumentPreview = {hash: string;};-function saveContent(- noteId: string,- sessionId: string,- ignoreEdit: boolean,- content: () => string-) {- console.log("SAVE to note");- useEditorStore.getState().saveSessionContent(noteId, sessionId, ignoreEdit, {+function saveContent(noteId: string, ignoreEdit: boolean, content: string) {+ useEditorStore.getState().saveSessionContent(noteId, ignoreEdit, {type: "tiptap",- data: content()+ data: content});}const deferredSave = debounceWithId(saveContent, 100);@@ -277,12 +271,7 @@ function EditorView({ id }: { id: string }) {onPreviewDocument={(url) => setDocPreview(url)}onContentChange={() => (lastSavedTime.current = Date.now())}onSave={(content, ignoreEdit) => {- const session = useEditorStore- .getState()- .getSession(id, ["default"]);- console.log("ON SAVE", session);- if (!session) return;- deferredSave(id, id, session.sessionId, ignoreEdit, content);+ deferredSave(session.id, session.id, ignoreEdit, data);}}options={{readonly: isReadonly || isPreviewSession,diff --git a/apps/web/src/stores/editor-store.ts b/apps/web/src/stores/editor-store.tsindex b4bdf8ada..2aece99a4 100644--- a/apps/web/src/stores/editor-store.ts+++ b/apps/web/src/stores/editor-store.ts@@ -468,11 +468,15 @@ class EditorStore extends BaseStore<EditorStore> {this.setSaveState(id, 0);try {- // if (partial.content) currentSession.content = partial.content;+ const sessionId =+ "sessionId" in currentSession+ ? currentSession.sessionId+ : `${Date.now()}`;+if (isLockedSession(currentSession)) {await db.vault.save({content: partial.content,- sessionId: partial.sessionId,+ sessionId,id});} else {@@ -483,22 +487,11 @@ class EditorStore extends BaseStore<EditorStore> {? currentSession.note.dateEdited: undefined,content: partial.content,- sessionId: partial.sessionId,+ sessionId,id});}- // if (currentSession && currentSession.id !== id) {- // noteStore.refresh();- // throw new Error("Aborting save operation: old session.");- // }- // if (!id) throw new Error("Note not saved.");-- // let note = await db.notes.note(id);- // if (!note) throw new Error("Note not saved.");-- // hashNavigate(`/notes/${id}/edit`, { replace: true, notify: false });-const defaultNotebook = db.settings.getDefaultNotebook();if (currentSession.type === "new" && currentSession.context) {const { type } = currentSession.context;@@ -531,7 +524,7 @@ class EditorStore extends BaseStore<EditorStore> {id,note,saveState: SaveState.Saved,- sessionId: partial.sessionId || `${Date.now()}`,+ sessionId,attachmentsLength,pinned: currentSession.pinned,content: partial.content@@ -609,12 +602,10 @@ class EditorStore extends BaseStore<EditorStore> {saveSessionContent = (id: string,- sessionId: string,ignoreEdit: boolean,content: NoteContent<false>) => {- // const dateEdited = ignoreEdit ? this.get().session.dateEdited : undefined;- return this.saveSession(id, { sessionId, content, ignoreEdit });+ return this.saveSession(id, { content, ignoreEdit });};setSaveState = (id: string, saveState: SaveState) => {