diff --git a/src/application/services/useNote.ts b/src/application/services/useNote.ts index 831c60e9..235d970a 100644 --- a/src/application/services/useNote.ts +++ b/src/application/services/useNote.ts @@ -1,8 +1,7 @@ -import { onMounted, ref, type Ref, type MaybeRefOrGetter, computed, toValue, watch } from 'vue'; -import { noteService, editorToolsService } from '@/domain'; -import type { Note, NoteContent, NoteId } from '@/domain/entities/Note'; -import type { NoteTool } from '@/domain/entities/Note'; -import { useRouter, useRoute } from 'vue-router'; +import { computed, type MaybeRefOrGetter, onMounted, ref, type Ref, toValue, watch } from 'vue'; +import { editorToolsService, noteService } from '@/domain'; +import type { Note, NoteContent, NoteId, NoteTool } from '@/domain/entities/Note'; +import { useRoute, useRouter } from 'vue-router'; import type { NoteDraft } from '@/domain/entities/NoteDraft'; import type EditorTool from '@/domain/entities/EditorTool'; import DomainError from '@/domain/entities/errors/Base'; @@ -188,9 +187,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt * @param id - note id */ async function getNoteHierarchy(id: NoteId): Promise { - let response = await noteService.getNoteHierarchy(id); - - noteHierarchy.value = response; + noteHierarchy.value = await noteService.getNoteHierarchy(id); } /** @@ -263,6 +260,10 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt */ const noteCreated = await noteService.createNote(content, specifiedNoteTools, parentId); + /** + * Fetch note's parents after saving the note + */ + noteParents.value = (await noteService.getNoteById(noteCreated.id)).parents; /** * Replace the current route with note id */ diff --git a/src/presentation/components/breadcrumbs/BreadCrumbs.vue b/src/presentation/components/breadcrumbs/BreadCrumbs.vue index b73434e9..1b71a514 100644 --- a/src/presentation/components/breadcrumbs/BreadCrumbs.vue +++ b/src/presentation/components/breadcrumbs/BreadCrumbs.vue @@ -2,10 +2,10 @@ - {{ parent.content ? getTitle(parent.content) : '...' }} + {{ parentTitle(parent.content) }} (); /** * Note parents hierarchy @@ -40,6 +41,23 @@ const displayedParents = computed(() => { return props.noteParents; }); + +/** + * title of the parent + * + * @param content - parent's content + * @returns {string} - parent title in string implementation + */ +function parentTitle(content: string | null | OutputData): string { + if (content === null) { + return '...'; + } + if (typeof content === 'string') { + return content; + } + + return getTitle(content); +}