From 73f4b3613f2e5c6f760c9ee87f35fc300d8a94fa Mon Sep 17 00:00:00 2001 From: dependentmadani Date: Thu, 7 Nov 2024 13:46:31 +0100 Subject: [PATCH 1/8] feat: display the note parents structure --- src/application/services/useNote.ts | 25 +++++++++++++++++++++++++ src/domain/entities/NoteDTO.ts | 5 +++++ 2 files changed, 30 insertions(+) diff --git a/src/application/services/useNote.ts b/src/application/services/useNote.ts index 938fbc0f..d77956be 100644 --- a/src/application/services/useNote.ts +++ b/src/application/services/useNote.ts @@ -158,6 +158,13 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt */ const parentNote = ref(undefined); + /** + * Note parents of the actual note + * + * Actual note by default + */ + const noteParents = ref([]); + /** * Load note by id * @param id - Note identifier got from composable argument @@ -172,6 +179,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt canEdit.value = response.accessRights.canEdit; noteTools.value = response.tools; parentNote.value = response.parentNote; + noteParents.value = response.parents; } /** @@ -265,6 +273,23 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt parentNote.value = undefined; } + /** + * Format the received note parents into presentation format + */ + async function formatNoteParents(): Promise { + if (currentId.value === null) { + throw new Error('note id is not defined'); + } + let presentationFormat = ''; + + for (let value of noteParents.value) { + presentationFormat += getTitle(value.content) + ' > '; + } + presentationFormat += noteTitle.value; + + return presentationFormat; + } + /** * Get note by custom hostname */ diff --git a/src/domain/entities/NoteDTO.ts b/src/domain/entities/NoteDTO.ts index 986c3ca7..b0cedc12 100644 --- a/src/domain/entities/NoteDTO.ts +++ b/src/domain/entities/NoteDTO.ts @@ -25,4 +25,9 @@ export interface NoteDTO { * Editor tools */ tools: EditorTool[]; + + /** + * Note parents + */ + parents: Note[]; } From 6ba36acaf80729c1f7c487f71bcd2ffcd3c998f3 Mon Sep 17 00:00:00 2001 From: dependentmadani Date: Thu, 7 Nov 2024 14:34:42 +0100 Subject: [PATCH 2/8] fix: lint and build errors --- src/application/services/useNote.ts | 5 +++-- .../transport/notes-api/types/GetNoteResponsePayload.ts | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/application/services/useNote.ts b/src/application/services/useNote.ts index d77956be..2539e9f3 100644 --- a/src/application/services/useNote.ts +++ b/src/application/services/useNote.ts @@ -276,12 +276,12 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt /** * Format the received note parents into presentation format */ - async function formatNoteParents(): Promise { + function formatNoteParents(): string { if (currentId.value === null) { throw new Error('note id is not defined'); } let presentationFormat = ''; - + for (let value of noteParents.value) { presentationFormat += getTitle(value.content) + ' > '; } @@ -340,6 +340,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt }); watch(noteTitle, (currentNoteTitle) => { + formatNoteParents(); patchOpenedPageByUrl( route.path, { diff --git a/src/infrastructure/transport/notes-api/types/GetNoteResponsePayload.ts b/src/infrastructure/transport/notes-api/types/GetNoteResponsePayload.ts index b43dff21..bee38d7f 100644 --- a/src/infrastructure/transport/notes-api/types/GetNoteResponsePayload.ts +++ b/src/infrastructure/transport/notes-api/types/GetNoteResponsePayload.ts @@ -10,4 +10,5 @@ export type GetNoteResponsePayload = { accessRights: NoteAccessRights; parentNote: Note | undefined; tools: EditorTool[]; + parents: Note[]; }; From d9988fb79c7bb1d48ba4c8d30eef12fdcccff2b0 Mon Sep 17 00:00:00 2001 From: dependentmadani Date: Fri, 8 Nov 2024 16:13:48 +0100 Subject: [PATCH 3/8] update: few modification of format function as well the docs --- src/application/services/useNote.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/application/services/useNote.ts b/src/application/services/useNote.ts index 2539e9f3..d3b33383 100644 --- a/src/application/services/useNote.ts +++ b/src/application/services/useNote.ts @@ -163,7 +163,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt * * Actual note by default */ - const noteParents = ref([]); + let noteParents: Note[] = []; /** * Load note by id @@ -179,7 +179,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt canEdit.value = response.accessRights.canEdit; noteTools.value = response.tools; parentNote.value = response.parentNote; - noteParents.value = response.parents; + noteParents = response.parents; } /** @@ -274,18 +274,24 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt } /** - * Format the received note parents into presentation format + * Reform the received note parents from api into presentation format. + * @returns An array of Note objects representing the formatted note parents. + * @throws {Error} If the note id is not defined. */ - function formatNoteParents(): string { + function formatNoteParents(): Note[] { if (currentId.value === null) { throw new Error('note id is not defined'); } - let presentationFormat = ''; + let presentationFormat: Note[] = []; - for (let value of noteParents.value) { - presentationFormat += getTitle(value.content) + ' > '; + if (noteParents.length > 2) { + presentationFormat = [noteParents[0]]; + presentationFormat.push({ id: currentId.value, + content: note.value?.content as NoteContent }); + } else { + presentationFormat = [...noteParents, { id: currentId.value, + content: note.value?.content as NoteContent }]; } - presentationFormat += noteTitle.value; return presentationFormat; } From 7baf8f1f7cc574e0b97398dbd0042298452e8122 Mon Sep 17 00:00:00 2001 From: Madani Badaoui Date: Sun, 24 Nov 2024 17:40:16 +0100 Subject: [PATCH 4/8] update (useNote): small modification in format function, and update in useNoteComposableState interface --- src/application/services/useNote.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/application/services/useNote.ts b/src/application/services/useNote.ts index d3b33383..c9c5655c 100644 --- a/src/application/services/useNote.ts +++ b/src/application/services/useNote.ts @@ -70,6 +70,11 @@ interface UseNoteComposableState { */ unlinkParent: () => Promise; + /** + * Get the format of note parents + */ + formatNoteParents: () => Note[]; + /** * Defines if user can edit note */ @@ -284,13 +289,13 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt } let presentationFormat: Note[] = []; - if (noteParents.length > 2) { - presentationFormat = [noteParents[0]]; - presentationFormat.push({ id: currentId.value, - content: note.value?.content as NoteContent }); + if (noteParents.length === 0) { + presentationFormat.push({ + id: currentId.value, + content: note.value?.content as NoteContent, + }); } else { - presentationFormat = [...noteParents, { id: currentId.value, - content: note.value?.content as NoteContent }]; + presentationFormat = noteParents; } return presentationFormat; @@ -364,6 +369,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt resolveToolsByContent, save, unlinkParent, + formatNoteParents, parentNote, }; } From 931460d55419ead879f0c948b75319c693b0170f Mon Sep 17 00:00:00 2001 From: dependentmadani Date: Wed, 27 Nov 2024 17:48:41 +0100 Subject: [PATCH 5/8] update: fix description of a doc --- src/application/services/useNote.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/application/services/useNote.ts b/src/application/services/useNote.ts index c9c5655c..0f1cfdf5 100644 --- a/src/application/services/useNote.ts +++ b/src/application/services/useNote.ts @@ -71,7 +71,7 @@ interface UseNoteComposableState { unlinkParent: () => Promise; /** - * Get the format of note parents + * Returns an array of Note objects representing the formatted note parents. */ formatNoteParents: () => Note[]; From 441586db34758eb26f4c574c43d3f958276faff8 Mon Sep 17 00:00:00 2001 From: dependentmadani Date: Sun, 8 Dec 2024 21:45:24 +0100 Subject: [PATCH 6/8] update: few changes on how to display the note structure, still need work to be done --- src/presentation/pages/Note.vue | 35 +++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/presentation/pages/Note.vue b/src/presentation/pages/Note.vue index d0cd75aa..d811be12 100644 --- a/src/presentation/pages/Note.vue +++ b/src/presentation/pages/Note.vue @@ -4,11 +4,18 @@ :style="{ '--opacity': id && note ? 1 : 0 }" >