Skip to content

Commit 85a424d

Browse files
committed
Note hierarchy appreance
1 parent 099917d commit 85a424d

6 files changed

Lines changed: 107 additions & 8 deletions

File tree

src/application/i18n/messages/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
"availabilityTitle": "Availability",
5050
"availabilityCaption": "Should the Note be available by its URL for people who knows it?",
5151
"availabilityRowTitle": "Note is published",
52+
"noteHierarchyTitle": "Note hierarchy",
53+
"noteHierarchyCaption": "Show the note hierarchy on the left menu?",
54+
"noteHierarchyRowTitle": "Show note hierarchy",
5255
"inviteCollaboratorTitle": "Invite a collaborator",
5356
"inviteCollaboratorCaption": "Send this link to someone you want to add as an editor or reader.",
5457
"revokeHashButton": "Revoke",

src/application/services/useNote.ts

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import DomainError from '@/domain/entities/errors/Base';
99
import useNavbar from './useNavbar';
1010
import { getTitle } from '@/infrastructure/utils/note';
1111
import type { NoteHierarchy } from '@/domain/entities/NoteHierarchy';
12+
import useNoteSettings from '@/application/services/useNoteSettings';
13+
import type NoteSettings from '@/domain/entities/NoteSettings';
1214

1315
/**
1416
* Creates base structure for the empty note:
@@ -96,6 +98,18 @@ interface UseNoteComposableState {
9698
* Note hierarchy
9799
*/
98100
noteHierarchy: Ref<NoteHierarchy | null>;
101+
102+
/**
103+
* Note settings composable
104+
*/
105+
noteSettings: Ref<NoteSettings | null>;
106+
/**
107+
* Updates the cover image of the note.
108+
* @param id - The identifier of the note whose cover should be updated.
109+
* @param data - The new cover image as binary data (Blob).
110+
* @returns A Promise that resolves when the cover has been updated.
111+
*/
112+
updateCover: (id: string, data: Blob) => Promise<void>;
99113
}
100114

101115
interface UseNoteComposableOptions {
@@ -116,6 +130,11 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
116130
*/
117131
const currentId = computed(() => toValue(options.id));
118132

133+
/**
134+
* Note settings composable
135+
*/
136+
const { noteSettings, load: loadNoteSettings, updateCover } = useNoteSettings();
137+
119138
/**
120139
* Currently opened note
121140
*
@@ -320,12 +339,35 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
320339
note.value = (await noteService.getNoteByHostname(location.hostname)).note;
321340
};
322341

323-
onMounted(() => {
342+
onMounted(async () => {
324343
/**
325-
* If we have id, load note and note hierarchy
344+
* If we have id, load note settings first, then note and note hierarchy if needed
326345
*/
327346
if (currentId.value !== null) {
328-
void load(currentId.value);
347+
await loadNoteSettings(currentId.value);
348+
// Only load note and hierarchy if showNoteHierarchy is true
349+
if (noteSettings.value?.showNoteHierarchy === true) {
350+
void load(currentId.value);
351+
} else {
352+
// Load note without hierarchy
353+
try {
354+
const response = await noteService.getNoteById(currentId.value);
355+
356+
note.value = response.note;
357+
canEdit.value = response.accessRights.canEdit;
358+
noteTools.value = response.tools;
359+
parentNote.value = response.parentNote;
360+
noteParents.value = response.parents;
361+
// Do not call getNoteHierarchy
362+
} catch (error) {
363+
deleteOpenedPageByUrl(route.path);
364+
if (error instanceof DomainError) {
365+
void router.push(`/error/${error.statusCode}`);
366+
} else {
367+
void router.push('/error/500');
368+
}
369+
}
370+
}
329371
}
330372
});
331373

@@ -414,5 +456,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
414456
noteParents,
415457
parentNote,
416458
noteHierarchy,
459+
noteSettings,
460+
updateCover,
417461
};
418462
}

src/application/services/useNoteSettings.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ interface UseNoteSettingsComposableState {
3333
*/
3434
updateIsPublic: (id: NoteId, newIsPublicValue: boolean) => Promise<void>;
3535

36+
/**
37+
* Update field showNoteHierarchy in note settings
38+
* @param id - Note id
39+
* @param newShowNoteHierarchyValue - new showNoteHierarchy
40+
*/
41+
updateShowNoteHierarchy: (id: NoteId, newShowNoteHierarchyValue: boolean) => Promise<void>;
42+
3643
/**
3744
* Revoke invitation hash
3845
* @param id - note id
@@ -116,6 +123,22 @@ export default function (): UseNoteSettingsComposableState {
116123
}
117124
}
118125

126+
/**
127+
* Update field showNoteHierarchy in note settings
128+
* @param id - Note id
129+
* @param newShowNoteHierarchyValue - new showNoteHierarchy
130+
*/
131+
async function updateShowNoteHierarchy(id: NoteId, newShowNoteHierarchyValue: boolean): Promise<void> {
132+
const { showNoteHierarchy } = await noteSettingsService.patchNoteSettingsByNoteId(id, { showNoteHierarchy: newShowNoteHierarchyValue });
133+
134+
/**
135+
* If note settings were not loaded till this moment for some reason, do nothing
136+
*/
137+
if (noteSettings.value) {
138+
noteSettings.value.showNoteHierarchy = showNoteHierarchy;
139+
}
140+
}
141+
119142
/**
120143
* Revoke invitation hash
121144
* @param id - Note id
@@ -198,5 +221,6 @@ export default function (): UseNoteSettingsComposableState {
198221
revokeHash,
199222
changeRole,
200223
deleteNoteById,
224+
updateShowNoteHierarchy,
201225
};
202226
}

src/domain/entities/NoteSettings.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,9 @@ export default interface NoteSettings {
3838
* Note cover image id
3939
*/
4040
cover: string;
41+
42+
/**
43+
* Show note heirarchy
44+
*/
45+
showNoteHierarchy: boolean;
4146
}

src/presentation/pages/Note.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
<PageBlock>
4747
<template #left>
4848
<VerticalMenu
49+
v-if="noteSettings && noteSettings.showNoteHierarchy"
4950
class="menu"
5051
:items="[verticalMenuItems]"
5152
/>
@@ -72,7 +73,6 @@ import { NoteContent } from '@/domain/entities/Note';
7273
import { useHead } from 'unhead';
7374
import { useI18n } from 'vue-i18n';
7475
import { makeElementScreenshot } from '@/infrastructure/utils/screenshot';
75-
import useNoteSettings from '@/application/services/useNoteSettings';
7676
import { useNoteEditor } from '@/application/services/useNoteEditor';
7777
import NoteHeader from '@/presentation/components/note-header/NoteHeader.vue';
7878
import BreadCrumbs from '@/presentation/components/breadcrumbs/BreadCrumbs.vue';
@@ -99,7 +99,7 @@ const props = defineProps<{
9999
100100
const noteId = toRef(props, 'id');
101101
102-
const { note, noteTools, save, noteTitle, canEdit, noteParents, noteHierarchy } = useNote({
102+
const { note, noteTools, save, noteTitle, canEdit, noteParents, noteHierarchy, noteSettings, updateCover } = useNote({
103103
id: noteId,
104104
});
105105
@@ -123,8 +123,6 @@ function redirectToNoteSettings(): void {
123123
router.push(`/note/${props.id}/settings`);
124124
}
125125
126-
const { updateCover } = useNoteSettings();
127-
128126
const { isEditorReady, editorConfig } = useNoteEditor({
129127
noteTools,
130128
isDraftResolver: () => noteId.value === null,

src/presentation/pages/NoteSettings.vue

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,20 @@
6363
</Row>
6464
</Section>
6565

66+
<Section
67+
:title="t('noteSettings.noteHierarchyTitle')"
68+
:caption="t('noteSettings.noteHierarchyCaption')"
69+
>
70+
<Row :title="t('noteSettings.noteHierarchyRowTitle')">
71+
<template #right>
72+
<Switch
73+
v-model="showNoteHierarchy"
74+
@click="changeShowNoteHierarchy"
75+
/>
76+
</template>
77+
</Row>
78+
</Section>
79+
6680
<Fieldset
6781
:title="t('noteSettings.teamFormFieldSetTitle')"
6882
>
@@ -123,7 +137,7 @@ const props = defineProps<{
123137
124138
const { patchOpenedPageByUrl } = useNavbar();
125139
const route = useRoute();
126-
const { noteSettings, load: loadSettings, updateIsPublic, deleteNoteById, parentNote, setParent } = useNoteSettings();
140+
const { noteSettings, load: loadSettings, updateIsPublic, deleteNoteById, parentNote, setParent, updateShowNoteHierarchy } = useNoteSettings();
127141
const { noteTitle, unlinkParent } = useNote({
128142
id: props.id,
129143
});
@@ -177,13 +191,24 @@ const isPublic = computed(() => {
177191
return noteSettings.value?.isPublic;
178192
});
179193
194+
/**
195+
* Current value of showNoteHierarchy field
196+
*/
197+
const showNoteHierarchy = computed(() => {
198+
return noteSettings.value?.showNoteHierarchy;
199+
});
200+
180201
/**
181202
* Change isPublic property
182203
*/
183204
async function changeAccess() {
184205
updateIsPublic(props.id, !noteSettings.value!.isPublic);
185206
}
186207
208+
async function changeShowNoteHierarchy() {
209+
updateShowNoteHierarchy(props.id, !noteSettings.value!.showNoteHierarchy);
210+
}
211+
187212
/**
188213
* Construct the parent note URL. If the parent note is not set, return an empty string
189214
*

0 commit comments

Comments
 (0)