Skip to content

Commit

Permalink
Merge pull request #271 from codex-team/tabbar-issue
Browse files Browse the repository at this point in the history
fix(&nbsp): a bug of header contains the &nbsp fixed
  • Loading branch information
dependentmadani authored Aug 23, 2024
2 parents 510f4bb + fda44ba commit fe69f21
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
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

0 comments on commit fe69f21

Please sign in to comment.