π 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
Sidebar to composable
Smaug6739223f4e140fe1
diff --git a/dashboard/components/MediumView.vue b/dashboard/components/MediumView.vueindex e12097db..50e9c523 100644--- a/dashboard/components/MediumView.vue+++ b/dashboard/components/MediumView.vue@@ -5,8 +5,7 @@</template><script setup lang="ts">-import { isOpened, paneWidth } from './sidebar/helpers';-+const { isOpened, paneWidth } = useSidebar();const mediumContainer = ref<HTMLElement | null>(null);const isMobile = () => process.client ? window.innerWidth <= 768 : false;if (!isMobile()) {diff --git a/dashboard/components/Navbar.vue b/dashboard/components/Navbar.vueindex f44ac265..7ec691fb 100644--- a/dashboard/components/Navbar.vue+++ b/dashboard/components/Navbar.vue@@ -1,8 +1,8 @@<template><header><span>- <svg v-if="hasSidebar" @click="isOpened = !isOpened" class="open-sidebar" xmlns="http://www.w3.org/2000/svg"- height="24" viewBox="0 -960 960 960" width="24">+ <svg v-if="hasSidebar" @click="toggleSidebar" class="open-sidebar" xmlns="http://www.w3.org/2000/svg" height="24"+ viewBox="0 -960 960 960" width="24"><path d="M120-240v-80h720v80H120Zm0-200v-80h720v80H120Zm0-200v-80h720v80H120Z" /></svg></span>@@ -64,6 +64,5 @@ ul {}</style><script lang="ts" setup>-import { hasSidebar, isOpened } from "@/components/sidebar/helpers";-+const { toggleSidebar, hasSidebar } = useSidebar();</script>\ No newline at end of filediff --git a/dashboard/components/sidebar/IconClose.vue b/dashboard/components/sidebar/IconClose.vueindex f74d2bfb..b6d52682 100644--- a/dashboard/components/sidebar/IconClose.vue+++ b/dashboard/components/sidebar/IconClose.vue@@ -1,10 +1,10 @@<template>- <svg class="btn" @click="isOpened = !isOpened" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">+ <svg class="btn" @click="toggleSidebar" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill-rule="evenodd" clip-rule="evenodd"d="M4 5C3.44772 5 3 5.44772 3 6C3 6.55228 3.44772 7 4 7H20C20.5523 7 21 6.55228 21 6C21 5.44772 20.5523 5 20 5H4ZM7 12C7 11.4477 7.44772 11 8 11H20C20.5523 11 21 11.4477 21 12C21 12.5523 20.5523 13 20 13H8C7.44772 13 7 12.5523 7 12ZM13 18C13 17.4477 13.4477 17 14 17H20C20.5523 17 21 17.4477 21 18C21 18.5523 20.5523 19 20 19H14C13.4477 19 13 18.5523 13 18Z" /></svg></template><script setup lang="ts">-import { isOpened } from './helpers';+const { toggleSidebar } = useSidebar();</script>\ No newline at end of filediff --git a/dashboard/components/sidebar/Resizable.vue b/dashboard/components/sidebar/Resizable.vueindex 0b7d6920..8d0bd4ae 100644--- a/dashboard/components/sidebar/Resizable.vue+++ b/dashboard/components/sidebar/Resizable.vue@@ -11,7 +11,7 @@</template><script setup lang="ts">-import { isOpened, paneWidth } from "./helpers";+const { isOpened, paneWidth } = useSidebar();const isResizing = ref(false)const startX = ref(0)diff --git a/dashboard/components/sidebar/Sidebar.vue b/dashboard/components/sidebar/Sidebar.vueindex 201a79b3..cf381823 100644--- a/dashboard/components/sidebar/Sidebar.vue+++ b/dashboard/components/sidebar/Sidebar.vue@@ -9,7 +9,7 @@</section><SidebarDropdown :categories="categoriesStore.getParents" v-model="category_dropdown_filter" /><section>- <CollapseItem v-for="( item, index ) in items " :key="index" :item="item" />+ <CollapseItem v-for="( item, index ) in items " :key="index" :item="item" /></section></div></Resizable>@@ -21,7 +21,9 @@ import Resizable from './Resizable.vue';import IconClose from './IconClose.vue';import IconApp from './IconApp.vue';import { useCategoriesStore, useDocumentsStore, type Document } from '~/store';-import { isOpened, type Item, defaultItems, hasSidebar } from "./helpers";+import { type Item, defaultItems } from "./helpers";++const { isOpened, hasSidebar } = useSidebar();const isMobile = () => process.client ? window.innerWidth <= 768 : false;const handleClickOutside = (e: MouseEvent) => {diff --git a/dashboard/components/sidebar/helpers.ts b/dashboard/components/sidebar/helpers.tsindex e61ee9db..bd74ca76 100644--- a/dashboard/components/sidebar/helpers.ts+++ b/dashboard/components/sidebar/helpers.ts@@ -1,8 +1,3 @@-import { ref } from 'vue';--export const isOpened = ref(false);-export const hasSidebar = ref(false);-export const paneWidth = ref(340); // initial width of pane 1export interface Item {id: string;title: string;diff --git a/dashboard/composables/Sidebar.ts b/dashboard/composables/Sidebar.tsnew file mode 100644index 00000000..b47baa12--- /dev/null+++ b/dashboard/composables/Sidebar.ts@@ -0,0 +1,18 @@+import { ref } from 'vue';++export const isOpened = ref(false);+export const hasSidebar = ref(false);+export const paneWidth = ref(340); // initial width of pane 1++export function useSidebar() {+ const toggleSidebar = () => {+ isOpened.value = !isOpened.value;+ };++ return {+ toggleSidebar,+ isOpened,+ hasSidebar,+ paneWidth,+ };+}