2022-12-07 13:31:38 +00:00
|
|
|
<template>
|
2024-05-08 09:11:32 +00:00
|
|
|
<nav
|
2024-05-19 05:49:42 +00:00
|
|
|
ref="root"
|
2024-05-08 09:11:32 +00:00
|
|
|
:class="{ collapsed: !expanded, 'tmp-showing': tmpShowing, showing: mobileShowing }"
|
|
|
|
class="flex flex-col fixed md:relative w-full md:w-k-sidebar-width z-10"
|
|
|
|
@mouseenter="onMouseEnter"
|
|
|
|
@mouseleave="onMouseLeave"
|
|
|
|
>
|
2024-05-19 05:49:42 +00:00
|
|
|
<section class="home-search-block p-6 flex gap-2">
|
|
|
|
<a
|
|
|
|
class="bg-black/20 flex items-center px-3.5 rounded-md !text-k-text-secondary hover:!text-k-text-primary"
|
|
|
|
href="#/home"
|
|
|
|
>
|
|
|
|
<Icon :icon="faHome" fixed-width />
|
|
|
|
</a>
|
2024-05-08 09:11:32 +00:00
|
|
|
<SearchForm />
|
|
|
|
</section>
|
2022-12-07 13:31:38 +00:00
|
|
|
|
2024-05-08 09:11:32 +00:00
|
|
|
<section v-koel-overflow-fade class="pt-2 pb-10 overflow-y-auto space-y-8">
|
|
|
|
<SidebarYourMusicSection />
|
|
|
|
<SidebarPlaylistsSection />
|
|
|
|
<SidebarManageSection v-if="showManageSection" />
|
|
|
|
</section>
|
2024-01-08 22:52:25 +00:00
|
|
|
|
2024-05-08 09:11:32 +00:00
|
|
|
<section v-if="!isPlus && isAdmin" class="p-6">
|
|
|
|
<BtnUpgradeToPlus />
|
|
|
|
</section>
|
2024-03-15 15:09:50 +00:00
|
|
|
|
2024-05-08 09:11:32 +00:00
|
|
|
<SidebarToggleButton v-model="expanded" />
|
|
|
|
</nav>
|
2022-12-07 13:31:38 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2024-05-19 05:49:42 +00:00
|
|
|
import { faHome } from '@fortawesome/free-solid-svg-icons'
|
2024-04-04 22:20:42 +00:00
|
|
|
import { computed, ref, watch } from 'vue'
|
2024-05-19 05:49:42 +00:00
|
|
|
import { onClickOutside } from '@vueuse/core'
|
2022-12-07 13:31:38 +00:00
|
|
|
import { eventBus } from '@/utils'
|
2024-04-23 21:01:27 +00:00
|
|
|
import { useAuthorization, useKoelPlus, useLocalStorage, useRouter, useUpload } from '@/composables'
|
2024-04-04 22:20:42 +00:00
|
|
|
|
|
|
|
import SidebarPlaylistsSection from './SidebarPlaylistsSection.vue'
|
2022-12-07 13:31:38 +00:00
|
|
|
import SearchForm from '@/components/ui/SearchForm.vue'
|
2024-01-13 17:57:24 +00:00
|
|
|
import BtnUpgradeToPlus from '@/components/koel-plus/BtnUpgradeToPlus.vue'
|
2024-05-19 05:49:42 +00:00
|
|
|
import SidebarYourMusicSection from './SidebarYourLibrarySection.vue'
|
2024-04-04 22:20:42 +00:00
|
|
|
import SidebarManageSection from './SidebarManageSection.vue'
|
|
|
|
import SidebarToggleButton from '@/components/layout/main-wrapper/sidebar/SidebarToggleButton.vue'
|
2022-12-07 13:31:38 +00:00
|
|
|
|
|
|
|
const { onRouteChanged } = useRouter()
|
|
|
|
const { isAdmin } = useAuthorization()
|
2024-01-04 11:35:36 +00:00
|
|
|
const { allowsUpload } = useUpload()
|
2024-01-08 22:52:25 +00:00
|
|
|
const { isPlus } = useKoelPlus()
|
2024-03-15 15:09:50 +00:00
|
|
|
const { get: lsGet, set: lsSet } = useLocalStorage()
|
2022-12-07 13:31:38 +00:00
|
|
|
|
2024-05-19 05:49:42 +00:00
|
|
|
const root = ref<HTMLElement>()
|
2022-12-07 13:31:38 +00:00
|
|
|
const mobileShowing = ref(false)
|
2024-04-04 22:20:42 +00:00
|
|
|
const expanded = ref(!lsGet('sidebar-collapsed', false))
|
2024-05-19 05:49:42 +00:00
|
|
|
|
2024-04-04 22:20:42 +00:00
|
|
|
watch(expanded, value => lsSet('sidebar-collapsed', !value))
|
2022-12-07 13:31:38 +00:00
|
|
|
|
2024-01-04 11:35:36 +00:00
|
|
|
const showManageSection = computed(() => isAdmin.value || allowsUpload.value)
|
2022-12-07 13:31:38 +00:00
|
|
|
|
2024-03-15 15:09:50 +00:00
|
|
|
let tmpShowingHandler: number | undefined
|
|
|
|
const tmpShowing = ref(false)
|
|
|
|
|
|
|
|
const onMouseEnter = () => {
|
2024-04-04 22:20:42 +00:00
|
|
|
if (expanded.value) return;
|
2024-03-15 15:09:50 +00:00
|
|
|
|
|
|
|
tmpShowingHandler = window.setTimeout(() => {
|
2024-04-04 22:20:42 +00:00
|
|
|
if (expanded.value) return
|
2024-03-15 15:09:50 +00:00
|
|
|
tmpShowing.value = true
|
|
|
|
}, 500)
|
|
|
|
}
|
|
|
|
|
|
|
|
const onMouseLeave = (e: MouseEvent) => {
|
|
|
|
if (!e.relatedTarget) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tmpShowingHandler) {
|
|
|
|
clearTimeout(tmpShowingHandler)
|
|
|
|
tmpShowingHandler = undefined
|
|
|
|
}
|
|
|
|
|
|
|
|
tmpShowing.value = false
|
|
|
|
}
|
2022-12-07 13:31:38 +00:00
|
|
|
|
2024-05-19 05:49:42 +00:00
|
|
|
// Not using the <OnClickOutside> component because it'd mess up the overflow/scrolling behavior
|
|
|
|
onClickOutside(root, () => (mobileShowing.value = false))
|
2022-12-07 13:31:38 +00:00
|
|
|
onRouteChanged(_ => (mobileShowing.value = false))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Listen to toggle sidebar event to show or hide the sidebar.
|
|
|
|
* This should only be triggered on a mobile device.
|
|
|
|
*/
|
|
|
|
eventBus.on('TOGGLE_SIDEBAR', () => (mobileShowing.value = !mobileShowing.value))
|
|
|
|
</script>
|
|
|
|
|
2024-04-04 20:13:35 +00:00
|
|
|
<style lang="postcss" scoped>
|
2024-04-04 22:20:42 +00:00
|
|
|
@import '@/../css/partials/mixins.pcss';
|
|
|
|
|
2022-12-07 13:31:38 +00:00
|
|
|
nav {
|
2024-04-04 22:20:42 +00:00
|
|
|
@apply bg-k-bg-secondary;
|
2022-12-07 13:31:38 +00:00
|
|
|
-ms-overflow-style: -ms-autohiding-scrollbar;
|
|
|
|
box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.1);
|
2024-03-15 15:09:50 +00:00
|
|
|
|
|
|
|
&.collapsed {
|
2024-04-04 22:20:42 +00:00
|
|
|
@apply w-[24px] transition-[width] duration-200;
|
2024-03-15 15:09:50 +00:00
|
|
|
|
|
|
|
> *:not(.btn-toggle) {
|
2024-04-04 22:20:42 +00:00
|
|
|
@apply hidden;
|
2024-03-15 15:09:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
&.tmp-showing {
|
2024-04-04 22:20:42 +00:00
|
|
|
@apply absolute h-screen z-50 bg-k-bg-primary w-k-sidebar-width shadow-2xl;
|
2024-03-15 15:09:50 +00:00
|
|
|
|
|
|
|
> *:not(.btn-toggle) {
|
2024-04-04 22:20:42 +00:00
|
|
|
@apply block;
|
2024-03-15 15:09:50 +00:00
|
|
|
}
|
2024-05-19 05:49:42 +00:00
|
|
|
|
|
|
|
> .home-search-block {
|
|
|
|
@apply flex;
|
|
|
|
}
|
2024-03-15 15:09:50 +00:00
|
|
|
}
|
|
|
|
}
|
2022-12-07 13:31:38 +00:00
|
|
|
|
|
|
|
@media screen and (max-width: 768px) {
|
2024-04-04 22:20:42 +00:00
|
|
|
@mixin themed-background;
|
2024-04-19 18:10:55 +00:00
|
|
|
z-index: 999;
|
2024-04-04 20:13:35 +00:00
|
|
|
|
2022-12-07 13:31:38 +00:00
|
|
|
transform: translateX(-100vw);
|
|
|
|
transition: transform .2s ease-in-out;
|
|
|
|
height: calc(100vh - var(--header-height));
|
|
|
|
|
|
|
|
&.showing {
|
|
|
|
transform: translateX(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|