diff --git a/src/application/i18n/messages/en.json b/src/application/i18n/messages/en.json index cdf3ca77..1fff3f13 100644 --- a/src/application/i18n/messages/en.json +++ b/src/application/i18n/messages/en.json @@ -49,6 +49,9 @@ "availabilityTitle": "Availability", "availabilityCaption": "Should the Note be available by its URL for people who knows it?", "availabilityRowTitle": "Note is published", + "noteHierarchyTitle": "Note hierarchy", + "noteHierarchyCaption": "Show the note hierarchy on the left menu?", + "noteHierarchyRowTitle": "Show note hierarchy", "inviteCollaboratorTitle": "Invite a collaborator", "inviteCollaboratorCaption": "Send this link to someone you want to add as an editor or reader.", "revokeHashButton": "Revoke", diff --git a/src/application/services/useNote.ts b/src/application/services/useNote.ts index 74342032..9d999420 100644 --- a/src/application/services/useNote.ts +++ b/src/application/services/useNote.ts @@ -96,6 +96,18 @@ interface UseNoteComposableState { * Note hierarchy */ noteHierarchy: Ref; + + /** + * Load note by id + * @param id - Note identifier + */ + load: (id: NoteId) => Promise; + + /** + * Load note hierarchy separately when needed + * @param id - Note identifier + */ + loadHierarchy: (id: NoteId) => Promise; } interface UseNoteComposableOptions { @@ -206,7 +218,6 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt noteTools.value = response.tools; parentNote.value = response.parentNote; noteParents.value = response.parents; - void getNoteHierarchy(id); } catch (error) { deleteOpenedPageByUrl(route.path); if (error instanceof DomainError) { @@ -217,6 +228,14 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt } } + /** + * Load note hierarchy separately when needed + * @param id - Note identifier + */ + async function loadHierarchy(id: NoteId): Promise { + await getNoteHierarchy(id); + } + /** * Returns list of tools used in the note * @param content - content of the note @@ -279,11 +298,6 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt 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); } @@ -313,13 +327,6 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt parentNote.value = undefined; } - /** - * Get note by custom hostname - */ - const resolveHostname = async (): Promise => { - note.value = (await noteService.getNoteByHostname(location.hostname)).note; - }; - onMounted(() => { /** * If we have id, load note and note hierarchy @@ -329,6 +336,13 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt } }); + /** + * Get note by custom hostname + */ + const resolveHostname = async (): Promise => { + note.value = (await noteService.getNoteByHostname(location.hostname)).note; + }; + /** * Reset note to the initial state */ @@ -414,5 +428,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt noteParents, parentNote, noteHierarchy, + load, + loadHierarchy, }; } diff --git a/src/application/services/useNoteSettings.ts b/src/application/services/useNoteSettings.ts index 7e2d38a3..5ce2f125 100644 --- a/src/application/services/useNoteSettings.ts +++ b/src/application/services/useNoteSettings.ts @@ -33,6 +33,13 @@ interface UseNoteSettingsComposableState { */ updateIsPublic: (id: NoteId, newIsPublicValue: boolean) => Promise; + /** + * Update field showNoteHierarchy in note settings + * @param id - Note id + * @param newShowNoteHierarchyValue - new showNoteHierarchy + */ + updateShowNoteHierarchy: (id: NoteId, newShowNoteHierarchyValue: boolean) => Promise; + /** * Revoke invitation hash * @param id - note id @@ -116,6 +123,22 @@ export default function (): UseNoteSettingsComposableState { } } + /** + * Update field showNoteHierarchy in note settings + * @param id - Note id + * @param newShowNoteHierarchyValue - new showNoteHierarchy + */ + async function updateShowNoteHierarchy(id: NoteId, newShowNoteHierarchyValue: boolean): Promise { + const { showNoteHierarchy } = await noteSettingsService.patchNoteSettingsByNoteId(id, { showNoteHierarchy: newShowNoteHierarchyValue }); + + /** + * If note settings were not loaded till this moment for some reason, do nothing + */ + if (noteSettings.value) { + noteSettings.value.showNoteHierarchy = showNoteHierarchy; + } + } + /** * Revoke invitation hash * @param id - Note id @@ -198,5 +221,6 @@ export default function (): UseNoteSettingsComposableState { revokeHash, changeRole, deleteNoteById, + updateShowNoteHierarchy, }; } diff --git a/src/domain/entities/NoteSettings.ts b/src/domain/entities/NoteSettings.ts index 93b1551b..f71ea615 100644 --- a/src/domain/entities/NoteSettings.ts +++ b/src/domain/entities/NoteSettings.ts @@ -38,4 +38,9 @@ export default interface NoteSettings { * Note cover image id */ cover: string; + + /** + * Show note heirarchy + */ + showNoteHierarchy: boolean; } diff --git a/src/presentation/pages/Note.vue b/src/presentation/pages/Note.vue index ce00bc7b..b512b9f0 100644 --- a/src/presentation/pages/Note.vue +++ b/src/presentation/pages/Note.vue @@ -46,8 +46,9 @@