Skip to content
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

feat: display the note parents structure #275

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

dependentmadani
Copy link
Contributor

Problem:

The issue is that when accessing a note, you would not know the note parent hierarchy, or the note parent of the actual note you are accessing.

Solution:

As describe in issue #256, we will be displaying the parent note structure at the top left of the note, following the tasks required to insure that the display of the note structure would be efficient.

Resolves #256

*
* Actual note by default
*/
const noteParents = ref<Note[]>([]);
Copy link
Contributor

Choose a reason for hiding this comment

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

i think that making noteParents reactive is a bad thing to do
We can update them only by request to api /GET note so i can't see the case, when we update noteParents and imidiately change displayed content somewhere

Copy link
Contributor

Choose a reason for hiding this comment

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

still actual

Comment on lines 280 to 290
if (currentId.value === null) {
throw new Error('note id is not defined');
}
let presentationFormat = '';

for (let value of noteParents.value) {
presentationFormat += getTitle(value.content) + ' > ';
}
presentationFormat += noteTitle.value;

return presentationFormat;
Copy link
Contributor

Choose a reason for hiding this comment

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

parentNote title should be clickable so just merge titles into one string is not a solution.

Also can't see the case with RootNoteTitle > ... > CurrentNote

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we can use anchor tag <a> can solve the merge of titles into one string.

Copy link
Member

Choose a reason for hiding this comment

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

it's better to do it in a component

@@ -265,6 +273,23 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
parentNote.value = undefined;
}

/**
* Format the received note parents into presentation format
Copy link
Member

Choose a reason for hiding this comment

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

Description is not clear

/**
* Returns an array of Note objects representing the formatted note parents.
*/
formatNoteParents: () => Note[];
Copy link
Member

@neSpecc neSpecc Dec 14, 2024

Choose a reason for hiding this comment

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

from the "composable" pattern its better to export "noteParents" object instead

Comment on lines 281 to 285
/**
* Reform the received note parents from api into presentation format.
* @returns An array of Note objects representing the formatted note parents.
* @throws {Error} If the note id is not defined.
*/
Copy link
Member

Choose a reason for hiding this comment

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

I dont really understand what this method is doing. Could you please improve jsdoc to make it more clear? Why API format is not suitable?

v-for="(parent, index) in displayedParents"
:key="parent.id"
>
<a @click="handleParentClick(parent)">{{ newGetTitle(parent.content) }}</a>
Copy link
Member

Choose a reason for hiding this comment

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

use RouterLink instead of a

: t('note.lastEdit') + ' ' + 'a few seconds ago'
}}
<div v-if="noteParents.length">
<span
Copy link
Member

Choose a reason for hiding this comment

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

span seems redunant

* @param {string} parent.id - The ID of the parent note
*/
function handleParentClick(parent: { id: string }): void {
if (parent.id !== 'ellipsis') {
Copy link
Member

Choose a reason for hiding this comment

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

seems like a magic string

* @param {OutputData | { title: string }} content - The content of the note
* @returns {string} - The title of the note
*/
function newGetTitle(content: OutputData | { title: string }): string {
Copy link
Member

Choose a reason for hiding this comment

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

we already have such a method

Comment on lines +293 to +296
presentationFormat.push({
id: currentId.value,
content: note.value?.content as NoteContent,
});
Copy link
Member

Choose a reason for hiding this comment

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

why you are adding current note as a parent? I don't think that it is a good idea

@@ -265,6 +278,35 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
parentNote.value = undefined;
}

/**
* Reform the array of note parents by adding the actual note id and content.
Copy link
Member

Choose a reason for hiding this comment

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

still don't understand the problem. API returns id and content, why do we need to change them?

? t('note.lastEdit') + ' ' + getTimeFromNow(note.updatedAt)
: t('note.lastEdit') + ' ' + 'a few seconds ago'
}}
<div>
Copy link
Member

Choose a reason for hiding this comment

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

div seems redundant

v-for="(parent, index) in displayedParents"
:key="index"
:to="{ path: `/note/${parent.id ? parent.id : noteId}` }"
@click.prevent="handleParentClick($event, parent)"
Copy link
Member

Choose a reason for hiding this comment

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

probably you don't need to handle click manually since you are using router link

*
* @param {number} parentId - The ID of the parent note to navigate to
*/
function navigateToParent(parentId: string): void {
Copy link
Member

Choose a reason for hiding this comment

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

seems redundant

}

/**
* Displayed parents
Copy link
Member

Choose a reason for hiding this comment

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

bad description

*
* Actual note by default
*/
const noteParents = ref<Note[]>([]);
Copy link
Contributor

Choose a reason for hiding this comment

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

still actual

Comment on lines +140 to +156
const displayedParents = computed(() => {
if (noteParents.value.length > 3) {
const newNoteContent = { blocks: [] } as OutputData;

newNoteContent.blocks.push({ type: 'paraghraph',
data: { text: '...' } });

return [
noteParents.value[0],
{ id: '',
content: newNoteContent },
noteParents.value[noteParents.value.length - 1],
];
}

return noteParents.value;
});
Copy link
Contributor

Choose a reason for hiding this comment

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

i would suggest moving all of this logic to different component of Notex (not codex-ui), then we will not overcomplicate Note page

Copy link
Contributor

Choose a reason for hiding this comment

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

i think this is discussable, @neSpecc what do you think about this?

* @returns An array of Note objects representing the formatted note parents.
* @throws {Error} If the note id is not defined.
*/
function formatNoteParents(): Note[] {
Copy link
Contributor

Choose a reason for hiding this comment

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

this method would be used only in component, so we should move this logic to computable displayedParents no need to produce extra entities (such as presentationFormat)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ Feature ] - display parent note structure in note header
3 participants