Skip to content

Commit

Permalink
fix(note): refresh editor on draft discard, refresh page title on dra…
Browse files Browse the repository at this point in the history
…ft save
  • Loading branch information
neSpecc committed Jul 13, 2024
1 parent 195a5aa commit e1ed1af
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 e1ed1af

Please sign in to comment.