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
38 changes: 38 additions & 0 deletions src/application/services/useNote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ interface UseNoteComposableState {
*/
unlinkParent: () => Promise<void>;

/**
* Get the format of note parents
*/
formatNoteParents: () => Note[];
e11sy marked this conversation as resolved.
Show resolved Hide resolved
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


/**
* Defines if user can edit note
*/
Expand Down Expand Up @@ -158,6 +163,13 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
*/
const parentNote = ref<Note | undefined>(undefined);

/**
* Note parents of the actual note
*
* Actual note by default
*/
let noteParents: Note[] = [];

/**
* Load note by id
* @param id - Note identifier got from composable argument
Expand All @@ -172,6 +184,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
canEdit.value = response.accessRights.canEdit;
noteTools.value = response.tools;
parentNote.value = response.parentNote;
noteParents = response.parents;
}

/**
Expand Down Expand Up @@ -265,6 +278,29 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
parentNote.value = undefined;
}

/**
* 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?

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)

if (currentId.value === null) {
throw new Error('note id is not defined');
}
let presentationFormat: Note[] = [];

if (noteParents.length === 0) {
presentationFormat.push({
id: currentId.value,
content: note.value?.content as NoteContent,
});
Comment on lines +293 to +296
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

} else {
presentationFormat = noteParents;
}

return presentationFormat;
}

/**
* Get note by custom hostname
*/
Expand Down Expand Up @@ -315,6 +351,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
});

watch(noteTitle, (currentNoteTitle) => {
formatNoteParents();
patchOpenedPageByUrl(
route.path,
{
Expand All @@ -332,6 +369,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
resolveToolsByContent,
save,
unlinkParent,
formatNoteParents,
parentNote,
};
}
5 changes: 5 additions & 0 deletions src/domain/entities/NoteDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ export interface NoteDTO {
* Editor tools
*/
tools: EditorTool[];

/**
* Note parents
*/
parents: Note[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export type GetNoteResponsePayload = {
accessRights: NoteAccessRights;
parentNote: Note | undefined;
tools: EditorTool[];
parents: Note[];
};
Loading