Skip to content

chore(sidebar): use title from api instead of content-based #320

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 9 commits into
base: main
Choose a base branch
from
18 changes: 9 additions & 9 deletions src/application/services/useNote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,29 +328,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 @@ -387,7 +387,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
8 changes: 3 additions & 5 deletions src/presentation/pages/Note.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ import useNoteSettings from '@/application/services/useNoteSettings';
import { useNoteEditor } from '@/application/services/useNoteEditor';
import NoteHeader from '@/presentation/components/note-header/NoteHeader.vue';
import { NoteHierarchy } from '@/domain/entities/NoteHierarchy';
import { getTitle } from '@/infrastructure/utils/note';

const { t } = useI18n();

Expand Down Expand Up @@ -185,14 +184,13 @@ function transformNoteHierarchy(noteHierarchyObj: NoteHierarchy | null, currentN
};
}

const title = noteHierarchyObj.content ? getTitle(noteHierarchyObj.content) : 'Untitled';
// Transform the current note into a VerticalMenuItem
const menuItem: VerticalMenuItem = {
title: title,
isActive: route.path === `/note/${noteHierarchyObj.id}`,
title: noteHierarchyObj?.noteTitle || 'Untitled',
isActive: route.path === `/note/${noteHierarchyObj.noteId}`,
Comment on lines +190 to +191
Copy link
Collaborator

Choose a reason for hiding this comment

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

when i am clicking + button to create child note, i expect to see the same noteHierarchyObj with new untitled note, but all can see is this
image
you can leave the todo for this

Copy link
Collaborator

Choose a reason for hiding this comment

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

still no todo left

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added now

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