Skip to content

Commit 2aded0f

Browse files
authored
Merge pull request #259 from codex-team/fix-note-draft
fix(note): refresh editor on draft discard, refresh page title on draft save
2 parents 195a5aa + e1ed1af commit 2aded0f

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/application/services/useNote.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
130130

131131
const limitCharsForNoteTitle = 50;
132132

133+
/**
134+
* Is there any note currently saving
135+
* Used to prevent re-load note after draft is saved
136+
*/
137+
const isNoteSaving = ref<boolean>(false);
138+
133139
/**
134140
* Note Title identifier
135141
*/
@@ -213,6 +219,8 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
213219
*/
214220
const specifiedNoteTools = resolveToolsByContent(content);
215221

222+
isNoteSaving.value = true;
223+
216224
if (currentId.value === null) {
217225
/**
218226
* @todo try-catch domain errors
@@ -235,16 +243,16 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
235243
title: noteTitle.value,
236244
url: route.path,
237245
});
238-
239-
return;
246+
} else {
247+
await noteService.updateNoteContentAndTools(currentId.value, content, specifiedNoteTools);
240248
}
241249

242-
await noteService.updateNoteContentAndTools(currentId.value, content, specifiedNoteTools);
243-
244250
/**
245251
* Store just saved content in memory
246252
*/
247253
lastUpdateContent.value = content;
254+
255+
isNoteSaving.value = false;
248256
}
249257

250258
/**
@@ -300,11 +308,13 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
300308
return;
301309
}
302310

311+
const isDraftSaving = prevId === null && isNoteSaving.value;
312+
303313
/**
304314
* Case for newly created note,
305315
* we don't need to re-load it
306316
*/
307-
if (prevId === null && newId !== null) {
317+
if (isDraftSaving) {
308318
return;
309319
}
310320

0 commit comments

Comments
 (0)