From 85a424ddaaad93f97be2d8ba442da81fee9ad0db Mon Sep 17 00:00:00 2001 From: devnull-1337 Date: Tue, 15 Jul 2025 16:11:18 +0530 Subject: [PATCH 1/3] Note hierarchy appreance --- src/application/i18n/messages/en.json | 3 ++ src/application/services/useNote.ts | 50 +++++++++++++++++++-- src/application/services/useNoteSettings.ts | 24 ++++++++++ src/domain/entities/NoteSettings.ts | 5 +++ src/presentation/pages/Note.vue | 6 +-- src/presentation/pages/NoteSettings.vue | 27 ++++++++++- 6 files changed, 107 insertions(+), 8 deletions(-) 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..67c72cd6 100644 --- a/src/application/services/useNote.ts +++ b/src/application/services/useNote.ts @@ -9,6 +9,8 @@ import DomainError from '@/domain/entities/errors/Base'; import useNavbar from './useNavbar'; import { getTitle } from '@/infrastructure/utils/note'; import type { NoteHierarchy } from '@/domain/entities/NoteHierarchy'; +import useNoteSettings from '@/application/services/useNoteSettings'; +import type NoteSettings from '@/domain/entities/NoteSettings'; /** * Creates base structure for the empty note: @@ -96,6 +98,18 @@ interface UseNoteComposableState { * Note hierarchy */ noteHierarchy: Ref; + + /** + * Note settings composable + */ + noteSettings: Ref; + /** + * Updates the cover image of the note. + * @param id - The identifier of the note whose cover should be updated. + * @param data - The new cover image as binary data (Blob). + * @returns A Promise that resolves when the cover has been updated. + */ + updateCover: (id: string, data: Blob) => Promise; } interface UseNoteComposableOptions { @@ -116,6 +130,11 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt */ const currentId = computed(() => toValue(options.id)); + /** + * Note settings composable + */ + const { noteSettings, load: loadNoteSettings, updateCover } = useNoteSettings(); + /** * Currently opened note * @@ -320,12 +339,35 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt note.value = (await noteService.getNoteByHostname(location.hostname)).note; }; - onMounted(() => { + onMounted(async () => { /** - * If we have id, load note and note hierarchy + * If we have id, load note settings first, then note and note hierarchy if needed */ if (currentId.value !== null) { - void load(currentId.value); + await loadNoteSettings(currentId.value); + // Only load note and hierarchy if showNoteHierarchy is true + if (noteSettings.value?.showNoteHierarchy === true) { + void load(currentId.value); + } else { + // Load note without hierarchy + try { + const response = await noteService.getNoteById(currentId.value); + + note.value = response.note; + canEdit.value = response.accessRights.canEdit; + noteTools.value = response.tools; + parentNote.value = response.parentNote; + noteParents.value = response.parents; + // Do not call getNoteHierarchy + } catch (error) { + deleteOpenedPageByUrl(route.path); + if (error instanceof DomainError) { + void router.push(`/error/${error.statusCode}`); + } else { + void router.push('/error/500'); + } + } + } } }); @@ -414,5 +456,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt noteParents, parentNote, noteHierarchy, + noteSettings, + updateCover, }; } 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..369c159f 100644 --- a/src/presentation/pages/Note.vue +++ b/src/presentation/pages/Note.vue @@ -46,6 +46,7 @@