Skip to content
18 changes: 9 additions & 9 deletions src/application/services/useNote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,29 +340,29 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
}

/**
* Recursively update the note hierarchy content
* Recursively update the note hierarchy title
* @param hierarchy - The note hierarchy to update
* @param content - The new content to update in the hierarchy
* @param title - The new title to update in the hierarchy
*/
function updateNoteHierarchyContent(hierarchy: NoteHierarchy | null, content: NoteContent | null): void {
function updateNoteHierarchyContent(hierarchy: NoteHierarchy | null, title: string): void {
// If hierarchy is null, there's nothing to update
if (!hierarchy) {
return;
}

// If content is null, we can't update the hierarchy content
if (!content) {
if (!title) {
return;
}

// Update the content of the current note in the hierarchy if it matches the currentId
if (hierarchy.id === currentId.value) {
hierarchy.content = content;
// Update the title of the current note in the hierarchy if it matches the currentId
if (hierarchy.noteId === currentId.value) {
hierarchy.noteTitle = title;
}

// Recursively update child notes
if (hierarchy.childNotes) {
hierarchy.childNotes.forEach(child => updateNoteHierarchyContent(child, content));
hierarchy.childNotes.forEach(child => updateNoteHierarchyContent(child, title));
}
}

Expand Down Expand Up @@ -399,7 +399,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
url: route.path,
});
}
updateNoteHierarchyContent(noteHierarchy.value, lastUpdateContent.value);
updateNoteHierarchyContent(noteHierarchy.value, currentNoteTitle);
});

return {
Expand Down
8 changes: 4 additions & 4 deletions src/domain/entities/NoteHierarchy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type NoteContent, type NoteId } from './Note';
import { type NoteId } from './Note';

/**
* Note Tree entity
Expand All @@ -8,12 +8,12 @@ export interface NoteHierarchy {
/**
* public note id
*/
id: NoteId;
noteId: NoteId;

/**
* note content
* note title
*/
content: NoteContent | null;
noteTitle: string;

/**
* child notes
Expand Down
10 changes: 4 additions & 6 deletions src/presentation/pages/Note.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
: t('note.lastEdit') + ' ' + 'a few seconds ago'
}}
</div>
<!-- @todo when user clicks on + button to add new note the user should see the previous note heirarchy -->
<Button
v-if="canEdit"
secondary
Expand Down Expand Up @@ -76,7 +77,6 @@ import { useNoteEditor } from '@/application/services/useNoteEditor';
import NoteHeader from '@/presentation/components/note-header/NoteHeader.vue';
import BreadCrumbs from '@/presentation/components/breadcrumbs/BreadCrumbs.vue';
import { NoteHierarchy } from '@/domain/entities/NoteHierarchy';
import { getTitle } from '@/infrastructure/utils/note';
import { getTimeFromNow } from '@/infrastructure/utils/date.ts';

const { t } = useI18n();
Expand Down Expand Up @@ -192,15 +192,13 @@ function transformNoteHierarchy(noteHierarchyObj: NoteHierarchy | null, currentN
};
}

const title = noteHierarchyObj.content ? getTitle(noteHierarchyObj.content) : 'Untitled';

// Transform the current note into a VerticalMenuItem
return {
title: title,
isActive: route.path === `/note/${noteHierarchyObj.id}`,
title: noteHierarchyObj?.noteTitle || 'Untitled',
isActive: route.path === `/note/${noteHierarchyObj.noteId}`,
items: noteHierarchyObj.childNotes ? noteHierarchyObj.childNotes.map(child => transformNoteHierarchy(child, currentNoteTitle)) : undefined,
onActivate: () => {
void router.push(`/note/${noteHierarchyObj.id}`);
void router.push(`/note/${noteHierarchyObj.noteId}`);
},
};
}
Expand Down
Loading