Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(&nbsp): a bug of header contains the &nbsp fixed #271

Merged
merged 3 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions src/application/services/useNote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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);
});

/**
Expand Down
12 changes: 5 additions & 7 deletions src/infrastructure/utils/note.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}

Expand Down
Loading