-
Notifications
You must be signed in to change notification settings - Fork 6
fix: switching between notes may override note #336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -201,13 +201,23 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt | |
| try { | ||
| const response = await noteService.getNoteById(id); | ||
|
|
||
| /** | ||
| * Id changed, loaded another note | ||
| */ | ||
| if (currentId.value !== id) { | ||
| return; | ||
| } | ||
|
|
||
| note.value = response.note; | ||
| canEdit.value = response.accessRights.canEdit; | ||
| noteTools.value = response.tools; | ||
| parentNote.value = response.parentNote; | ||
| noteParents.value = response.parents; | ||
| void getNoteHierarchy(id); | ||
| } catch (error) { | ||
| if (currentId.value !== id) { | ||
| return; | ||
| } | ||
| deleteOpenedPageByUrl(route.path); | ||
| if (error instanceof DomainError) { | ||
| void router.push(`/error/${error.statusCode}`); | ||
|
|
@@ -255,9 +265,14 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt | |
| */ | ||
| const specifiedNoteTools = resolveToolsByContent(content); | ||
|
|
||
| /** | ||
| * Id may be changed | ||
| */ | ||
| const savedNoteId = currentId.value; | ||
|
|
||
| isNoteSaving.value = true; | ||
|
|
||
| if (currentId.value === null) { | ||
| if (savedNoteId === null) { | ||
| /** | ||
| * @todo try-catch domain errors | ||
| */ | ||
|
|
@@ -273,25 +288,26 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt | |
| }, | ||
| }); | ||
|
|
||
| patchOpenedPageByUrl( | ||
| route.path, | ||
| { | ||
| title: noteTitle.value, | ||
| url: route.path, | ||
| }); | ||
| patchOpenedPageByUrl(route.path, { | ||
| title: noteTitle.value, | ||
| url: route.path, | ||
| }); | ||
|
|
||
| /** | ||
| * Get note Hierarchy when new Note is created | ||
| */ | ||
| void getNoteHierarchy(noteCreated.id); | ||
| } else { | ||
| await noteService.updateNoteContentAndTools(currentId.value, content, specifiedNoteTools); | ||
| await noteService.updateNoteContentAndTools(savedNoteId, content, specifiedNoteTools); | ||
| } | ||
|
|
||
| /** | ||
| * Store just saved content in memory | ||
| * If id changed, do not store content | ||
| */ | ||
| lastUpdateContent.value = content; | ||
| if (currentId.value === savedNoteId) { | ||
| lastUpdateContent.value = content; | ||
| } | ||
|
|
||
| isNoteSaving.value = false; | ||
| } | ||
|
|
@@ -391,13 +407,16 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt | |
| }); | ||
|
|
||
| watch(noteTitle, (currentNoteTitle) => { | ||
| if (route.name == 'note') { | ||
| patchOpenedPageByUrl( | ||
| route.path, | ||
| { | ||
| title: currentNoteTitle, | ||
| url: route.path, | ||
| }); | ||
| if (route.name == 'note' && currentId.value !== null) { | ||
| /** | ||
| * URL may have changed, use note id | ||
| */ | ||
| const noteUrl = `/note/${currentId.value}`; | ||
|
|
||
| patchOpenedPageByUrl(noteUrl, { | ||
| title: currentNoteTitle, | ||
| url: noteUrl, | ||
| }); | ||
| } | ||
|
Comment on lines
409
to
420
|
||
| updateNoteHierarchyContent(noteHierarchy.value, currentNoteTitle); | ||
| }); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use strict equality (===) instead of loose equality (==) for consistency with the rest of the codebase and to avoid potential type coercion issues.