web: set session id on saving note

This commit is contained in:
Abdullah Atta
2024-03-11 10:45:43 +05:00
parent ccb9c492a8
commit 62bdee7789
2 changed files with 13 additions and 33 deletions

View File

@@ -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,

View File

@@ -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) => {