@@ -9,6 +9,8 @@ import DomainError from '@/domain/entities/errors/Base';
99import useNavbar from './useNavbar' ;
1010import { getTitle } from '@/infrastructure/utils/note' ;
1111import type { NoteHierarchy } from '@/domain/entities/NoteHierarchy' ;
12+ import useNoteSettings from '@/application/services/useNoteSettings' ;
13+ import type NoteSettings from '@/domain/entities/NoteSettings' ;
1214
1315/**
1416 * Creates base structure for the empty note:
@@ -96,6 +98,18 @@ interface UseNoteComposableState {
9698 * Note hierarchy
9799 */
98100 noteHierarchy : Ref < NoteHierarchy | null > ;
101+
102+ /**
103+ * Note settings composable
104+ */
105+ noteSettings : Ref < NoteSettings | null > ;
106+ /**
107+ * Updates the cover image of the note.
108+ * @param id - The identifier of the note whose cover should be updated.
109+ * @param data - The new cover image as binary data (Blob).
110+ * @returns A Promise that resolves when the cover has been updated.
111+ */
112+ updateCover : ( id : string , data : Blob ) => Promise < void > ;
99113}
100114
101115interface UseNoteComposableOptions {
@@ -116,6 +130,11 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
116130 */
117131 const currentId = computed ( ( ) => toValue ( options . id ) ) ;
118132
133+ /**
134+ * Note settings composable
135+ */
136+ const { noteSettings, load : loadNoteSettings , updateCover } = useNoteSettings ( ) ;
137+
119138 /**
120139 * Currently opened note
121140 *
@@ -320,12 +339,35 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
320339 note . value = ( await noteService . getNoteByHostname ( location . hostname ) ) . note ;
321340 } ;
322341
323- onMounted ( ( ) => {
342+ onMounted ( async ( ) => {
324343 /**
325- * If we have id, load note and note hierarchy
344+ * If we have id, load note settings first, then note and note hierarchy if needed
326345 */
327346 if ( currentId . value !== null ) {
328- void load ( currentId . value ) ;
347+ await loadNoteSettings ( currentId . value ) ;
348+ // Only load note and hierarchy if showNoteHierarchy is true
349+ if ( noteSettings . value ?. showNoteHierarchy === true ) {
350+ void load ( currentId . value ) ;
351+ } else {
352+ // Load note without hierarchy
353+ try {
354+ const response = await noteService . getNoteById ( currentId . value ) ;
355+
356+ note . value = response . note ;
357+ canEdit . value = response . accessRights . canEdit ;
358+ noteTools . value = response . tools ;
359+ parentNote . value = response . parentNote ;
360+ noteParents . value = response . parents ;
361+ // Do not call getNoteHierarchy
362+ } catch ( error ) {
363+ deleteOpenedPageByUrl ( route . path ) ;
364+ if ( error instanceof DomainError ) {
365+ void router . push ( `/error/${ error . statusCode } ` ) ;
366+ } else {
367+ void router . push ( '/error/500' ) ;
368+ }
369+ }
370+ }
329371 }
330372 } ) ;
331373
@@ -414,5 +456,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
414456 noteParents,
415457 parentNote,
416458 noteHierarchy,
459+ noteSettings,
460+ updateCover,
417461 } ;
418462}
0 commit comments