-
Notifications
You must be signed in to change notification settings - Fork 6
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
base: main
Are you sure you want to change the base?
Changes from all commits
73f4b36
6ba36ac
d9988fb
7baf8f1
931460d
441586d
04e849f
e78539c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,11 @@ interface UseNoteComposableState { | |
*/ | ||
unlinkParent: () => Promise<void>; | ||
|
||
/** | ||
* Returns an array of note parents for the current note. | ||
*/ | ||
noteParents: Ref<Note[]>; | ||
|
||
/** | ||
* Defines if user can edit note | ||
*/ | ||
|
@@ -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 | ||
*/ | ||
const noteParents = ref<Note[]>([]); | ||
|
||
/** | ||
* Load note by id | ||
* @param id - Note identifier got from composable argument | ||
|
@@ -172,6 +184,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt | |
canEdit.value = response.accessRights.canEdit; | ||
noteTools.value = response.tools; | ||
parentNote.value = response.parentNote; | ||
noteParents.value = response.parents; | ||
} | ||
|
||
/** | ||
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
* @returns An array of Note objects representing the formatted note parents. | ||
* @throws {Error} If the note id is not defined. | ||
*/ | ||
function formatNoteParents(): Note[] { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
if (currentId.value === null) { | ||
return []; | ||
} | ||
let presentationFormat: Note[] = []; | ||
|
||
if (noteParents.value.length === 0) { | ||
presentationFormat.push({ | ||
id: currentId.value, | ||
content: note.value?.content as NoteContent, | ||
}); | ||
Comment on lines
+293
to
+296
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.value; | ||
if (noteParents.value.find(noteItem => noteItem.id === currentId.value) === undefined) { | ||
presentationFormat.push({ | ||
id: currentId.value, | ||
content: note.value?.content as NoteContent, | ||
}); | ||
} | ||
} | ||
|
||
return presentationFormat; | ||
} | ||
|
||
/** | ||
* Get note by custom hostname | ||
*/ | ||
|
@@ -315,6 +357,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt | |
}); | ||
|
||
watch(noteTitle, (currentNoteTitle) => { | ||
noteParents.value = formatNoteParents(); | ||
patchOpenedPageByUrl( | ||
route.path, | ||
{ | ||
|
@@ -332,6 +375,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt | |
resolveToolsByContent, | ||
save, | ||
unlinkParent, | ||
noteParents, | ||
parentNote, | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 |
---|---|---|
|
@@ -4,11 +4,17 @@ | |
:style="{ '--opacity': id && note ? 1 : 0 }" | ||
> | ||
<template #left> | ||
{{ | ||
note && 'updatedAt' in note && note.updatedAt | ||
? t('note.lastEdit') + ' ' + getTimeFromNow(note.updatedAt) | ||
: t('note.lastEdit') + ' ' + 'a few seconds ago' | ||
}} | ||
<div> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. div seems redundant |
||
<RouterLink | ||
v-for="(parent, index) in displayedParents" | ||
:key="index" | ||
:to="{ path: `/note/${parent.id ? parent.id : noteId}` }" | ||
@click.prevent="handleParentClick($event, parent)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
> | ||
{{ getTitle(parent.content) }} | ||
<span v-if="index < displayedParents.length - 1"> > </span> | ||
</RouterLink> | ||
</div> | ||
</template> | ||
<template #right> | ||
<Button | ||
|
@@ -48,18 +54,19 @@ | |
</template> | ||
|
||
<script lang="ts" setup> | ||
import { ref, toRef, watch } from 'vue'; | ||
import { computed, ref, toRef, watch } from 'vue'; | ||
import { OutputData } from '@editorjs/editorjs'; | ||
import { Button, Editor } from 'codex-ui/vue'; | ||
import useNote from '@/application/services/useNote'; | ||
import { useRouter } from 'vue-router'; | ||
import { NoteContent } from '@/domain/entities/Note'; | ||
import { RouterLink, useRouter } from 'vue-router'; | ||
import { Note, NoteContent } from '@/domain/entities/Note'; | ||
import { useHead } from 'unhead'; | ||
import { useI18n } from 'vue-i18n'; | ||
import { getTimeFromNow } from '@/infrastructure/utils/date'; | ||
import { makeElementScreenshot } from '@/infrastructure/utils/screenshot'; | ||
import useNoteSettings from '@/application/services/useNoteSettings'; | ||
import { useNoteEditor } from '@/application/services/useNoteEditor'; | ||
import NoteHeader from '@/presentation/components/note-header/NoteHeader.vue'; | ||
import { getTitle } from '@/infrastructure/utils/note'; | ||
|
||
const { t } = useI18n(); | ||
|
||
|
@@ -79,7 +86,7 @@ const props = defineProps<{ | |
|
||
const noteId = toRef(props, 'id'); | ||
|
||
const { note, noteTools, save, noteTitle, canEdit } = useNote({ | ||
const { note, noteTools, save, noteTitle, canEdit, noteParents } = useNote({ | ||
id: noteId, | ||
}); | ||
|
||
|
@@ -103,6 +110,51 @@ function redirectToNoteSettings(): void { | |
router.push(`/note/${props.id}/settings`); | ||
} | ||
|
||
/** | ||
* Navigate to a specific note | ||
* | ||
* @param {number} parentId - The ID of the parent note to navigate to | ||
*/ | ||
function navigateToParent(parentId: string): void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems redundant |
||
router.push(`/note/${parentId}`); | ||
} | ||
|
||
/** | ||
* Handle parent click | ||
* | ||
* @param {Event} event - The click event | ||
* @param {object} parent - The parent object | ||
* @param {string} parent.id - The ID of the parent note | ||
*/ | ||
function handleParentClick(event: Event, parent: Note): void { | ||
if (getTitle(parent.content) !== '...') { | ||
navigateToParent(parent.id); | ||
} else { | ||
event.preventDefault(); | ||
} | ||
} | ||
|
||
/** | ||
* Displayed parents | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bad description |
||
*/ | ||
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; | ||
}); | ||
Comment on lines
+140
to
+156
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think this is discussable, @neSpecc what do you think about this? |
||
|
||
const { updateCover } = useNoteSettings(); | ||
|
||
const { isEditorReady, editorConfig } = useNoteEditor({ | ||
|
There was a problem hiding this comment.
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 doWe 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 somewhereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still actual