Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/application/i18n/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
"availabilityTitle": "Availability",
"availabilityCaption": "Should the Note be available by its URL for people who knows it?",
"availabilityRowTitle": "Note is published",
"noteHierarchyTitle": "Note hierarchy",
"noteHierarchyCaption": "Show the note hierarchy on the left menu?",
"noteHierarchyRowTitle": "Show note hierarchy",
"inviteCollaboratorTitle": "Invite a collaborator",
"inviteCollaboratorCaption": "Send this link to someone you want to add as an editor or reader.",
"revokeHashButton": "Revoke",
Expand Down
42 changes: 29 additions & 13 deletions src/application/services/useNote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ interface UseNoteComposableState {
* Note hierarchy
*/
noteHierarchy: Ref<NoteHierarchy | null>;

/**
* Load note by id
* @param id - Note identifier
*/
load: (id: NoteId) => Promise<void>;

/**
* Load note hierarchy separately when needed
* @param id - Note identifier
*/
loadHierarchy: (id: NoteId) => Promise<void>;
}

interface UseNoteComposableOptions {
Expand Down Expand Up @@ -206,7 +218,6 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
noteTools.value = response.tools;
parentNote.value = response.parentNote;
noteParents.value = response.parents;
void getNoteHierarchy(id);
} catch (error) {
deleteOpenedPageByUrl(route.path);
if (error instanceof DomainError) {
Expand All @@ -217,6 +228,14 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
}
}

/**
* Load note hierarchy separately when needed
* @param id - Note identifier
*/
async function loadHierarchy(id: NoteId): Promise<void> {
await getNoteHierarchy(id);
}

/**
* Returns list of tools used in the note
* @param content - content of the note
Expand Down Expand Up @@ -279,11 +298,6 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
title: noteTitle.value,
url: route.path,
});

/**
* Get note Hierarchy when new Note is created
*/
void getNoteHierarchy(noteCreated.id);
} else {
await noteService.updateNoteContentAndTools(currentId.value, content, specifiedNoteTools);
}
Expand Down Expand Up @@ -313,13 +327,6 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
parentNote.value = undefined;
}

/**
* Get note by custom hostname
*/
const resolveHostname = async (): Promise<void> => {
note.value = (await noteService.getNoteByHostname(location.hostname)).note;
};

onMounted(() => {
/**
* If we have id, load note and note hierarchy
Expand All @@ -329,6 +336,13 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
}
});

/**
* Get note by custom hostname
*/
const resolveHostname = async (): Promise<void> => {
note.value = (await noteService.getNoteByHostname(location.hostname)).note;
};

/**
* Reset note to the initial state
*/
Expand Down Expand Up @@ -414,5 +428,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
noteParents,
parentNote,
noteHierarchy,
load,
loadHierarchy,
};
}
24 changes: 24 additions & 0 deletions src/application/services/useNoteSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ interface UseNoteSettingsComposableState {
*/
updateIsPublic: (id: NoteId, newIsPublicValue: boolean) => Promise<void>;

/**
* Update field showNoteHierarchy in note settings
* @param id - Note id
* @param newShowNoteHierarchyValue - new showNoteHierarchy
*/
updateShowNoteHierarchy: (id: NoteId, newShowNoteHierarchyValue: boolean) => Promise<void>;

/**
* Revoke invitation hash
* @param id - note id
Expand Down Expand Up @@ -116,6 +123,22 @@ export default function (): UseNoteSettingsComposableState {
}
}

/**
* Update field showNoteHierarchy in note settings
* @param id - Note id
* @param newShowNoteHierarchyValue - new showNoteHierarchy
*/
async function updateShowNoteHierarchy(id: NoteId, newShowNoteHierarchyValue: boolean): Promise<void> {
const { showNoteHierarchy } = await noteSettingsService.patchNoteSettingsByNoteId(id, { showNoteHierarchy: newShowNoteHierarchyValue });

/**
* If note settings were not loaded till this moment for some reason, do nothing
*/
if (noteSettings.value) {
noteSettings.value.showNoteHierarchy = showNoteHierarchy;
}
}

/**
* Revoke invitation hash
* @param id - Note id
Expand Down Expand Up @@ -198,5 +221,6 @@ export default function (): UseNoteSettingsComposableState {
revokeHash,
changeRole,
deleteNoteById,
updateShowNoteHierarchy,
};
}
5 changes: 5 additions & 0 deletions src/domain/entities/NoteSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ export default interface NoteSettings {
* Note cover image id
*/
cover: string;

/**
* Show note heirarchy
*/
showNoteHierarchy: boolean;
}
40 changes: 23 additions & 17 deletions src/presentation/pages/Note.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@
<PageBlock>
<template #left>
<VerticalMenu
v-if="noteSettings && noteSettings.showNoteHierarchy && verticalMenuItems.length > 0"
class="menu"
:items="[verticalMenuItems]"
:items="verticalMenuItems"
/>
</template>
<template #default>
Expand Down Expand Up @@ -99,10 +100,13 @@ const props = defineProps<{

const noteId = toRef(props, 'id');

const { note, noteTools, save, noteTitle, canEdit, noteParents, noteHierarchy } = useNote({
const { note, noteTools, save, noteTitle, canEdit, noteParents, noteHierarchy, loadHierarchy } = useNote({
id: noteId,
});

// Note settings composable - used directly in the page
const { noteSettings, load: loadNoteSettings, updateCover } = useNoteSettings();

/**
* Create new child note
*/
Expand All @@ -123,8 +127,6 @@ function redirectToNoteSettings(): void {
router.push(`/note/${props.id}/settings`);
}

const { updateCover } = useNoteSettings();

const { isEditorReady, editorConfig } = useNoteEditor({
noteTools,
isDraftResolver: () => noteId.value === null,
Expand Down Expand Up @@ -183,18 +185,10 @@ async function noteChanged(data: NoteContent): Promise<void> {
* @returns menuItem - VerticalMenuItem
*/

function transformNoteHierarchy(noteHierarchyObj: NoteHierarchy | null, currentNoteTitle: string): VerticalMenuItem {
if (!noteHierarchyObj) {
return {
title: 'Untitled',
isActive: true,
items: undefined,
};
}

function transformNoteHierarchy(noteHierarchyObj: NoteHierarchy, currentNoteTitle: string): VerticalMenuItem {
// Transform the current note into a VerticalMenuItem
return {
title: noteHierarchyObj?.noteTitle || 'Untitled',
title: noteHierarchyObj.noteTitle || 'Untitled',
isActive: route.path === `/note/${noteHierarchyObj.noteId}`,
items: noteHierarchyObj.childNotes ? noteHierarchyObj.childNotes.map(child => transformNoteHierarchy(child, currentNoteTitle)) : undefined,
onActivate: () => {
Expand All @@ -203,18 +197,30 @@ function transformNoteHierarchy(noteHierarchyObj: NoteHierarchy | null, currentN
};
}

const verticalMenuItems = computed<VerticalMenuItem>(() => {
return transformNoteHierarchy(noteHierarchy.value, noteTitle.value);
const verticalMenuItems = computed<VerticalMenuItem[]>(() => {
if (!noteHierarchy.value) {
return [];
}

return [transformNoteHierarchy(noteHierarchy.value, noteTitle.value)];
});

watch(
() => props.id,
() => {
async () => {
/** If new child note is created, refresh editor with empty data */
if (props.id === null) {
useHead({
title: t('note.new'),
});
} else {
// Load note settings first
await loadNoteSettings(props.id);

// Load hierarchy only if settings allow it
if (noteSettings.value?.showNoteHierarchy === true) {
await loadHierarchy(props.id);
}
}
},
{ immediate: true }
Expand Down
27 changes: 26 additions & 1 deletion src/presentation/pages/NoteSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@
</Row>
</Section>

<Section
:title="t('noteSettings.noteHierarchyTitle')"
:caption="t('noteSettings.noteHierarchyCaption')"
>
<Row :title="t('noteSettings.noteHierarchyRowTitle')">
<template #right>
<Switch
v-model="showNoteHierarchy"
@click="changeShowNoteHierarchy"
/>
</template>
</Row>
</Section>

<Fieldset
:title="t('noteSettings.teamFormFieldSetTitle')"
>
Expand Down Expand Up @@ -123,7 +137,7 @@ const props = defineProps<{

const { patchOpenedPageByUrl } = useNavbar();
const route = useRoute();
const { noteSettings, load: loadSettings, updateIsPublic, deleteNoteById, parentNote, setParent } = useNoteSettings();
const { noteSettings, load: loadSettings, updateIsPublic, deleteNoteById, parentNote, setParent, updateShowNoteHierarchy } = useNoteSettings();
const { noteTitle, unlinkParent } = useNote({
id: props.id,
});
Expand Down Expand Up @@ -177,13 +191,24 @@ const isPublic = computed(() => {
return noteSettings.value?.isPublic;
});

/**
* Current value of showNoteHierarchy field
*/
const showNoteHierarchy = computed(() => {
return noteSettings.value?.showNoteHierarchy;
});

/**
* Change isPublic property
*/
async function changeAccess() {
updateIsPublic(props.id, !noteSettings.value!.isPublic);
}

async function changeShowNoteHierarchy() {
updateShowNoteHierarchy(props.id, !noteSettings.value!.showNoteHierarchy);
}

/**
* Construct the parent note URL. If the parent note is not set, return an empty string
*
Expand Down
Loading