koel/resources/assets/js/components/layout/main-wrapper/Sidebar.vue

239 lines
5.9 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
2022-04-24 08:29:14 +00:00
<nav id="sidebar" :class="{ showing }" class="side side-nav">
2022-04-15 14:24:30 +00:00
<section class="music">
<h1>Your Music</h1>
<ul class="menu">
<li>
<a :class="['home', activeScreen === 'Home' ? 'active' : '']" href="#!/home">
2022-07-15 07:23:55 +00:00
<icon :icon="faHome" fixed-width/>
Home
</a>
2022-04-15 14:24:30 +00:00
</li>
<li
:class="droppableToQueue && 'droppable'"
@dragleave="onQueueDragLeave"
@dragover="onQueueDragOver"
@drop="onQueueDrop"
>
<a :class="['queue', activeScreen === 'Queue' ? 'active' : '']" href="#!/queue">
2022-07-15 07:23:55 +00:00
<icon :icon="faListOl" fixed-width/>
2022-04-24 08:29:14 +00:00
Current Queue
</a>
2022-04-15 14:24:30 +00:00
</li>
<li>
<a :class="['songs', activeScreen === 'Songs' ? 'active' : '']" href="#!/songs">
2022-07-15 07:23:55 +00:00
<icon :icon="faMusic" fixed-width/>
All Songs
</a>
2022-04-15 14:24:30 +00:00
</li>
<li>
<a :class="['albums', activeScreen === 'Albums' ? 'active' : '']" href="#!/albums">
2022-07-15 07:23:55 +00:00
<icon :icon="faCompactDisc" fixed-width/>
Albums
</a>
2022-04-15 14:24:30 +00:00
</li>
<li>
<a :class="['artists', activeScreen === 'Artists' ? 'active' : '']" href="#!/artists">
2022-07-15 07:23:55 +00:00
<icon :icon="faMicrophone" fixed-width/>
Artists
</a>
2022-04-15 14:24:30 +00:00
</li>
2022-04-24 08:29:14 +00:00
<li v-if="useYouTube">
<a :class="['youtube', activeScreen === 'YouTube' ? 'active' : '']" href="#!/youtube">
2022-07-15 07:23:55 +00:00
<icon :icon="faYoutube" fixed-width/>
YouTube Video
</a>
2022-04-15 14:24:30 +00:00
</li>
</ul>
</section>
<PlaylistList/>
2022-04-15 14:24:30 +00:00
<section v-if="isAdmin" class="manage">
2022-04-15 14:24:30 +00:00
<h1>Manage</h1>
<ul class="menu">
<li>
<a :class="['settings', activeScreen === 'Settings' ? 'active' : '']" href="#!/settings">
2022-07-15 07:23:55 +00:00
<icon :icon="faTools" fixed-width/>
Settings
</a>
2022-04-15 14:24:30 +00:00
</li>
<li>
<a :class="['upload', activeScreen === 'Upload' ? 'active' : '']" href="#!/upload">
2022-07-15 07:23:55 +00:00
<icon :icon="faUpload" fixed-width/>
Upload
</a>
2022-04-15 14:24:30 +00:00
</li>
<li>
<a :class="['users', activeScreen === 'Users' ? 'active' : '']" href="#!/users">
2022-07-15 07:23:55 +00:00
<icon :icon="faUsers" fixed-width/>
Users
</a>
2022-04-15 14:24:30 +00:00
</li>
</ul>
</section>
</nav>
</template>
2022-04-15 17:00:08 +00:00
<script lang="ts" setup>
2022-04-15 14:24:30 +00:00
import isMobile from 'ismobilejs'
2022-07-15 07:23:55 +00:00
import {
faCompactDisc,
faHome,
faListOl,
faMicrophone,
faMusic,
faTools,
faUpload,
faUsers
} from '@fortawesome/free-solid-svg-icons'
import { faYoutube } from '@fortawesome/free-brands-svg-icons'
import { ref } from 'vue'
import { eventBus, requireInjection } from '@/utils'
2022-06-10 10:47:46 +00:00
import { queueStore } from '@/stores'
import { useAuthorization, useDroppable, useThirdPartyServices } from '@/composables'
import { RouterKey } from '@/symbols'
2022-04-15 14:24:30 +00:00
import PlaylistList from '@/components/playlist/PlaylistSidebarList.vue'
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const showing = ref(!isMobile.phone)
const activeScreen = ref<ScreenName>()
const droppableToQueue = ref(false)
const { acceptsDrop, resolveDroppedSongs } = useDroppable(['songs', 'album', 'artist', 'playlist'])
const { useYouTube } = useThirdPartyServices()
const { isAdmin } = useAuthorization()
2022-04-15 14:24:30 +00:00
const onQueueDragOver = (event: DragEvent) => {
if (!acceptsDrop(event)) return false
event.preventDefault()
event.dataTransfer!.dropEffect = 'move'
droppableToQueue.value = true
}
const onQueueDragLeave = () => (droppableToQueue.value = false)
const onQueueDrop = async (event: DragEvent) => {
droppableToQueue.value = false
if (!acceptsDrop(event)) return false
event.preventDefault()
const songs = await resolveDroppedSongs(event) || []
2022-04-15 17:00:08 +00:00
songs.length && queueStore.queue(songs)
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
return false
}
2022-04-15 14:24:30 +00:00
const router = requireInjection(RouterKey)
router.onRouteChanged(route => {
// On mobile, hide the sidebar whenever a screen is activated.
if (isMobile.phone) {
showing.value = false
}
activeScreen.value = route.screen
})
eventBus.on({
/**
* Listen to toggle sidebar event to show or hide the sidebar.
2022-08-01 08:58:25 +00:00
* This should only be triggered on a mobile device.
*/
TOGGLE_SIDEBAR: () => (showing.value = !showing.value)
2022-04-15 14:24:30 +00:00
})
</script>
<style lang="scss" scoped>
nav {
2022-04-15 14:24:30 +00:00
flex: 0 0 256px;
background-color: var(--color-bg-secondary);
padding: 2.05rem 0;
overflow: auto;
overflow-x: hidden;
-ms-overflow-style: -ms-autohiding-scrollbar;
> * + * {
margin-top: 2.25rem;
}
@media (hover: none) {
// Enable scroll with momentum on touch devices
overflow-y: scroll;
-webkit-overflow-scrolling: touch;
}
.droppable {
box-shadow: inset 0 0 0 1px var(--color-accent);
border-radius: 4px;
cursor: copy;
2022-04-15 14:24:30 +00:00
}
2022-08-01 08:58:25 +00:00
.queue > span {
display: flex;
align-items: baseline;
justify-content: space-between;
flex: 1;
}
::v-deep(h1) {
text-transform: uppercase;
letter-spacing: 1px;
padding: 0 16px;
margin-bottom: 12px;
}
::v-deep(a) {
display: flex;
align-items: center;
gap: .7rem;
height: 36px;
line-height: 36px;
padding: 0 16px 0 12px;
border-left: 4px solid transparent;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
&.active, &:hover {
border-left-color: var(--color-highlight);
color: var(--color-text-primary);
background: rgba(255, 255, 255, .05);
box-shadow: 0 1px 0 rgba(0, 0, 0, .1);
2022-04-15 14:24:30 +00:00
}
&:active {
opacity: .5;
2022-04-15 14:24:30 +00:00
}
&:hover {
border-left-color: var(--color-highlight);
}
}
::v-deep(li li a) { // submenu items
padding-left: 24px;
2022-04-15 14:24:30 +00:00
}
2022-04-15 17:00:08 +00:00
@media only screen and (max-width: 667px) {
2022-04-15 14:24:30 +00:00
@include themed-background();
position: fixed;
height: calc(100vh - var(--header-height) + var(--footer-height));
width: 100%;
z-index: 99;
top: var(--header-height);
left: -100%;
transition: left .3s ease-in;
&.showing {
left: 0;
}
}
}
</style>