Skip to content

Commit

Permalink
Merge pull request #259 from codex-team/fix-note-draft
Browse files Browse the repository at this point in the history
fix(note): refresh editor on draft discard, refresh page title on draft save
  • Loading branch information
neSpecc authored Jul 13, 2024
2 parents 195a5aa + e1ed1af commit 2aded0f
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/application/services/useNote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt

const limitCharsForNoteTitle = 50;

/**
* Is there any note currently saving
* Used to prevent re-load note after draft is saved
*/
const isNoteSaving = ref<boolean>(false);

/**
* Note Title identifier
*/
Expand Down Expand Up @@ -213,6 +219,8 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
*/
const specifiedNoteTools = resolveToolsByContent(content);

isNoteSaving.value = true;

if (currentId.value === null) {
/**
* @todo try-catch domain errors
Expand All @@ -235,16 +243,16 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
title: noteTitle.value,
url: route.path,
});

return;
} else {
await noteService.updateNoteContentAndTools(currentId.value, content, specifiedNoteTools);
}

await noteService.updateNoteContentAndTools(currentId.value, content, specifiedNoteTools);

/**
* Store just saved content in memory
*/
lastUpdateContent.value = content;

isNoteSaving.value = false;
}

/**
Expand Down Expand Up @@ -300,11 +308,13 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
return;
}

const isDraftSaving = prevId === null && isNoteSaving.value;

/**
* Case for newly created note,
* we don't need to re-load it
*/
if (prevId === null && newId !== null) {
if (isDraftSaving) {
return;
}

Expand Down

0 comments on commit 2aded0f

Please sign in to comment.