Skip to content

Fix: Display current note in BreadCrumbs component #324

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
14 changes: 6 additions & 8 deletions src/application/services/useNote.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -188,9 +187,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
* @param id - note id
*/
async function getNoteHierarchy(id: NoteId): Promise<void> {
let response = await noteService.getNoteHierarchy(id);

noteHierarchy.value = response;
noteHierarchy.value = await noteService.getNoteHierarchy(id);
}

/**
Expand Down Expand Up @@ -263,6 +260,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
*/
const noteCreated = await noteService.createNote(content, specifiedNoteTools, parentId);

noteParents.value = (await noteService.getNoteById(noteCreated.id)).parents;
/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add comment explaining this statement, please

* Replace the current route with note id
*/
Expand Down
24 changes: 21 additions & 3 deletions src/presentation/components/breadcrumbs/BreadCrumbs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<RouterLink
v-for="(parent, index) in displayedParents"
:key="index"
:to="{ path: parent.id ? `/note/${parent.id}` : '' }"
:to="`/note/${parent.id}`"
Copy link
Preview

Copilot AI May 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The updated :to directive always generates a URL using /note/${parent.id}. If parent.id is falsy (e.g., undefined), this may produce an unintended route like '/note/undefined'. Consider retaining a conditional check or default value to handle falsy parent.id values.

Suggested change
:to="`/note/${parent.id}`"
:to="`/note/${parent.id || 'unknown'}`"

Copilot uses AI. Check for mistakes.

class="breadcrumb"
>
{{ parent.content ? getTitle(parent.content) : '...' }}
{{ parentTitle(parent.content) }}
<Icon
v-if="index < displayedParents.length - 1"
name="ChevronRight"
Expand All @@ -20,9 +20,10 @@ import { RouterLink } from 'vue-router';
import { computed } from 'vue';
import { Note } from '@/domain/entities/Note.ts';
import { Icon } from '@codexteam/ui/vue';
import { OutputData } from '@editorjs/editorjs';

const props = defineProps<{
noteParents: Note[];
noteParents: (Note | { id: string; content: string })[];
}>();
/**
* Note parents hierarchy
Expand All @@ -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);
}
</script>

<style scoped>
Expand Down
6 changes: 5 additions & 1 deletion src/presentation/pages/Note.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
>
<template #left>
<BreadCrumbs
:note-parents="noteParents"
:note-parents="
note && noteId ?
[...noteParents, { id: noteId, content: noteTitle }] :
noteParents
"
/>
</template>
<template #right>
Expand Down
Loading