Skip to content

Commit 099917d

Browse files
authored
Merge pull request #320 from devnull-1337/fix/note-title-composer
chore(sidebar): use title from api instead of content-based
2 parents 5f27bc9 + 2fd4777 commit 099917d

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

src/application/services/useNote.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -340,29 +340,29 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
340340
}
341341

342342
/**
343-
* Recursively update the note hierarchy content
343+
* Recursively update the note hierarchy title
344344
* @param hierarchy - The note hierarchy to update
345-
* @param content - The new content to update in the hierarchy
345+
* @param title - The new title to update in the hierarchy
346346
*/
347-
function updateNoteHierarchyContent(hierarchy: NoteHierarchy | null, content: NoteContent | null): void {
347+
function updateNoteHierarchyContent(hierarchy: NoteHierarchy | null, title: string): void {
348348
// If hierarchy is null, there's nothing to update
349349
if (!hierarchy) {
350350
return;
351351
}
352352

353353
// If content is null, we can't update the hierarchy content
354-
if (!content) {
354+
if (!title) {
355355
return;
356356
}
357357

358-
// Update the content of the current note in the hierarchy if it matches the currentId
359-
if (hierarchy.id === currentId.value) {
360-
hierarchy.content = content;
358+
// Update the title of the current note in the hierarchy if it matches the currentId
359+
if (hierarchy.noteId === currentId.value) {
360+
hierarchy.noteTitle = title;
361361
}
362362

363363
// Recursively update child notes
364364
if (hierarchy.childNotes) {
365-
hierarchy.childNotes.forEach(child => updateNoteHierarchyContent(child, content));
365+
hierarchy.childNotes.forEach(child => updateNoteHierarchyContent(child, title));
366366
}
367367
}
368368

@@ -399,7 +399,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
399399
url: route.path,
400400
});
401401
}
402-
updateNoteHierarchyContent(noteHierarchy.value, lastUpdateContent.value);
402+
updateNoteHierarchyContent(noteHierarchy.value, currentNoteTitle);
403403
});
404404

405405
return {

src/domain/entities/NoteHierarchy.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type NoteContent, type NoteId } from './Note';
1+
import { type NoteId } from './Note';
22

33
/**
44
* Note Tree entity
@@ -8,12 +8,12 @@ export interface NoteHierarchy {
88
/**
99
* public note id
1010
*/
11-
id: NoteId;
11+
noteId: NoteId;
1212

1313
/**
14-
* note content
14+
* note title
1515
*/
16-
content: NoteContent | null;
16+
noteTitle: string;
1717

1818
/**
1919
* child notes

src/presentation/pages/Note.vue

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
: t('note.lastEdit') + ' ' + 'a few seconds ago'
1717
}}
1818
</div>
19+
<!-- @todo when user clicks on + button to add new note the user should see the previous note heirarchy -->
1920
<Button
2021
v-if="canEdit"
2122
secondary
@@ -76,7 +77,6 @@ import { useNoteEditor } from '@/application/services/useNoteEditor';
7677
import NoteHeader from '@/presentation/components/note-header/NoteHeader.vue';
7778
import BreadCrumbs from '@/presentation/components/breadcrumbs/BreadCrumbs.vue';
7879
import { NoteHierarchy } from '@/domain/entities/NoteHierarchy';
79-
import { getTitle } from '@/infrastructure/utils/note';
8080
import { getTimeFromNow } from '@/infrastructure/utils/date.ts';
8181
8282
const { t } = useI18n();
@@ -192,15 +192,13 @@ function transformNoteHierarchy(noteHierarchyObj: NoteHierarchy | null, currentN
192192
};
193193
}
194194
195-
const title = noteHierarchyObj.content ? getTitle(noteHierarchyObj.content) : 'Untitled';
196-
197195
// Transform the current note into a VerticalMenuItem
198196
return {
199-
title: title,
200-
isActive: route.path === `/note/${noteHierarchyObj.id}`,
197+
title: noteHierarchyObj?.noteTitle || 'Untitled',
198+
isActive: route.path === `/note/${noteHierarchyObj.noteId}`,
201199
items: noteHierarchyObj.childNotes ? noteHierarchyObj.childNotes.map(child => transformNoteHierarchy(child, currentNoteTitle)) : undefined,
202200
onActivate: () => {
203-
void router.push(`/note/${noteHierarchyObj.id}`);
201+
void router.push(`/note/${noteHierarchyObj.noteId}`);
204202
},
205203
};
206204
}

0 commit comments

Comments
 (0)