diff --git a/src/application/services/useNote.ts b/src/application/services/useNote.ts index c6e820d3..938fbc0f 100644 --- a/src/application/services/useNote.ts +++ b/src/application/services/useNote.ts @@ -6,6 +6,7 @@ import { useRouter, useRoute } from 'vue-router'; import type { NoteDraft } from '@/domain/entities/NoteDraft'; import type EditorTool from '@/domain/entities/EditorTool'; import useHeader from './useHeader'; +import { getTitle } from '@/infrastructure/utils/note'; /** * Creates base structure for the empty note: @@ -128,8 +129,6 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt const route = useRoute(); - const limitCharsForNoteTitle = 50; - /** * Is there any note currently saving * Used to prevent re-load note after draft is saved @@ -142,13 +141,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt const noteTitle = computed(() => { const noteContent = lastUpdateContent.value ?? note.value?.content; - const firstNoteBlock = noteContent?.blocks[0]; - - if (!firstNoteBlock || !Boolean(firstNoteBlock.data.text)) { - return 'Note'; - } else { - return firstNoteBlock.data.text.slice(0, limitCharsForNoteTitle); - } + return getTitle(noteContent); }); /** diff --git a/src/infrastructure/utils/note.ts b/src/infrastructure/utils/note.ts index 7c602519..ddd01bb0 100644 --- a/src/infrastructure/utils/note.ts +++ b/src/infrastructure/utils/note.ts @@ -1,24 +1,22 @@ import { type OutputData } from '@editorjs/editorjs'; -import { useI18n } from 'vue-i18n'; /** * Get the title of the note * @param content - content of the note * @returns the title of the note */ -export function getTitle(content: OutputData): string { +export function getTitle(content: OutputData | undefined): string { const limitCharsForNoteTitle = 50; - const firstNoteBlock = content.blocks[0]; - const { t } = useI18n(); + const firstNoteBlock = content?.blocks[0]; - const text: string | undefined = firstNoteBlock.data.text; + const text: string | undefined = firstNoteBlock?.data.text; /** * If the heading is empty, return 'Untitled' */ if (text === undefined || text.trim() === '') { - return t('note.untitled'); + return 'Untitled'; } else { - return text?.slice?.(0, limitCharsForNoteTitle); + return text?.replace(/ /g, ' ')?.slice?.(0, limitCharsForNoteTitle); } }