π The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.
Vue dockergolangkanbanknowledge-baseknowledge-managementmarkdownnote-takingnotesnotes-appnotionnuxtnuxtjsoffline-firstoidcpwaselfhostedssovuevuejswiki
Improve sidebar
Veauville Raphaelcfe6bd9be0fc
diff --git a/dashboard/components/sidebar/CollapseItem.vue b/dashboard/components/sidebar/CollapseItem.vueindex 672b3474..0e245083 100644--- a/dashboard/components/sidebar/CollapseItem.vue+++ b/dashboard/components/sidebar/CollapseItem.vue@@ -1,23 +1,63 @@<template>- <Collapse v-if="item.childrens.length">- <template v-slot:header>+ <div v-if="item.childrens.length">+ <div v-if="root" class="collapse-header">+ <SidebarItem :item="item" @click="toggleShow">+ <svg style="margin-left:auto;" :class="{ 'rotated': !show }" xmlns="http://www.w3.org/2000/svg" height="24"+ viewBox="0 -960 960 960" width="24">+ <path d="M480-345 240-585l56-56 184 184 184-184 56 56-240 240Z" />+ </svg>+ </SidebarItem>+ </div>+ <div v-else class="collapse-header"><SidebarItem :item="item" />- </template>- <template v-slot:body>- <template v-for="(child, index) in item.childrens">- <div style="margin-left:25px;">+ </div>+ <div v-if="show" class="collapse-body">+ <div v-for="(child, index) in item.childrens">+ <div style="margin-left:20px;"><CollapseItem v-if="child.childrens?.length" :item="child" :key="index" /><SidebarItem v-else :item="child" /></div>- </template>- </template>- </Collapse>+ </div>+ </div>+ </div><SidebarItem v-else :item="item" /></template><script setup lang="ts">import { type Item } from './helpers';-import Collapse from './Collapse.vue';+import div from './Collapse.vue';import SidebarItem from './SidebarItem.vue';-defineProps<{ item: Item }>();+defineProps<{ item: Item, root?: boolean }>();++const show = ref(true);+const toggleShow = () => show.value = !show.value;</script>++<style lang="scss" scoped>+h2 {+ font-size: 16px;+ font-weight: 600;+ border: none;+ margin: 3px;+ line-height: 24px;+ padding: 0 !important;+}++.collapse-header {+ display: flex;+ align-items: center;+ justify-content: space-between;++ svg {+ height: 20px;++ :hover {+ cursor: pointer;+ }++ &.rotated {+ transform: rotate(-90deg);+ }+ }+}+</style>\ No newline at end of filediff --git a/dashboard/components/sidebar/Resizable.vue b/dashboard/components/sidebar/Resizable.vueindex 8d0bd4ae..f2323338 100644--- a/dashboard/components/sidebar/Resizable.vue+++ b/dashboard/components/sidebar/Resizable.vue@@ -1,6 +1,6 @@<template><nav :class="{ open: isOpened }">- <div :class="['sidebar', isResizing ? 'no-select' : '']">+ <div class="sidebar no-select"><div :style="{ width: panewidthCSS }"><slot></slot>@@ -43,8 +43,6 @@ function stopResize() {}--</script><style scoped lang="scss">diff --git a/dashboard/components/sidebar/Sidebar.vue b/dashboard/components/sidebar/Sidebar.vueindex cf381823..19adf931 100644--- a/dashboard/components/sidebar/Sidebar.vue+++ b/dashboard/components/sidebar/Sidebar.vue@@ -1,6 +1,5 @@<template><Resizable>-<div class="sidebar-content"><section class="header"><IconApp />@@ -8,9 +7,7 @@<IconClose class="btn" /></section><SidebarDropdown :categories="categoriesStore.getParents" v-model="category_dropdown_filter" />- <section>- <CollapseItem v-for="( item, index ) in items " :key="index" :item="item" />- </section>+ <CollapseItem v-for="(item, index ) in items " :key="index" :item="item" :root="true" /></div></Resizable></template>@@ -23,18 +20,16 @@ import IconApp from './IconApp.vue';import { useCategoriesStore, useDocumentsStore, type Document } from '~/store';import { type Item, defaultItems } from "./helpers";+type DocumentTree = Document & { childrens: DocumentTree[] };+const { isOpened, hasSidebar } = useSidebar();+const category_dropdown_filter = ref('');+const categoriesStore = useCategoriesStore();+const documentsStore = useDocumentsStore();const isMobile = () => process.client ? window.innerWidth <= 768 : false;-const handleClickOutside = (e: MouseEvent) => {- if (isOpened.value && e.target && (!(e.target as Element).closest('.sidebar') && !(e.target as Element).closest('.open-sidebar')) && isMobile()) isOpened.value = false;-};--const category_dropdown_filter = ref('');-const categoriesStore = useCategoriesStore();-const documentsStore = useDocumentsStore();const items = computed((): Item[] => [...defaultItems,...formatTree().filter((item) => {@@ -43,13 +38,10 @@ const items = computed((): Item[] => [})]);-type DocumentTree = Document & { childrens: DocumentTree[] };function formatTree(): Item[] {-- const parents = categoriesStore.getParentsconst items: Item[] = [];- parents.forEach((parent) => {+ categoriesStore.getParents.forEach((parent) => {const childrens: Item[] = [];categoriesStore.getChilds(parent.id).forEach((child) => {childrens.push({@@ -113,6 +105,10 @@ function defaultIcon(hasChild: boolean): string {}+const handleClickOutside = (e: MouseEvent) => {+ if (isOpened.value && e.target && (!(e.target as Element).closest('.sidebar') && !(e.target as Element).closest('.open-sidebar')) && isMobile()) isOpened.value = false;+};+onMounted(() => {hasSidebar.value = true;if (!process.client) return;@@ -134,5 +130,31 @@ watch(isOpened, (val) => {</script><style scoped lang="scss">-@import "./__sidebar.scss";+.sidebar-content {+ margin: 0 0 0 10px;+ background: var(--bg-contrast);+ display: flex;+ flex-direction: column;+ height: 100%;+ overflow-y: scroll;+}++.header {+ display: flex;+ justify-content: space-between;+ align-items: center;+ height: 50px;+ margin: 10px 0 15px 0;++ .btn {+ fill: var(--font-color);+ width: 30px;+ cursor: pointer;+ }++ .name {+ font-size: 1.2rem;+ font-weight: 500;+ }+}</style>\ No newline at end of filediff --git a/dashboard/components/sidebar/SidebarItem.vue b/dashboard/components/sidebar/SidebarItem.vueindex b1b716bd..6f6a0422 100644--- a/dashboard/components/sidebar/SidebarItem.vue+++ b/dashboard/components/sidebar/SidebarItem.vue@@ -2,6 +2,7 @@<NuxtLink class="item" :to="item.route" :class="{ active: isActive(item.id) }"><i v-html="item.icon" class="icon"></i><span>{{ item.title }}</span>+ <slot></slot></NuxtLink></template>@@ -19,7 +20,7 @@ const isActive = (id: string) => doc_id.value === id;display: flex;justify-content: flex-start;align-items: center;- min-height: 30px;+ min-height: 28px;padding: 0 2.5px;margin: 2.5px 0;border-radius: 5px;diff --git a/dashboard/components/sidebar/__sidebar.scss b/dashboard/components/sidebar/__sidebar.scssdeleted file mode 100644index 165249b7..00000000--- a/dashboard/components/sidebar/__sidebar.scss+++ /dev/null@@ -1,30 +0,0 @@-// Sidebar-.sidebar-content {- margin: 0 0 0 10px;- background: var(--bg-contrast);- display: flex;- flex-direction: column;- height: 100%;- overflow-y: auto;-}---// Header-.header {- display: flex;- justify-content: space-between;- align-items: center;- height: 50px;- margin: 10px 0 15px 0;-- .btn {- fill: var(--font-color);- width: 30px;- cursor: pointer;- }-- .name {- font-size: 1.2rem;- font-weight: 500;- }-}\ No newline at end of file