2022-04-15 14:24:30 +00:00
|
|
|
<template>
|
|
|
|
<section id="playlists">
|
|
|
|
<h1>Playlists
|
|
|
|
<i
|
|
|
|
:class="{ creating }"
|
2022-04-20 12:38:38 +00:00
|
|
|
@click.prevent.stop="toggleContextMenu"
|
2022-04-15 14:24:30 +00:00
|
|
|
class="fa fa-plus-circle create"
|
|
|
|
role="button"
|
|
|
|
title="Create a new playlist"
|
|
|
|
data-testid="sidebar-create-playlist-btn"
|
|
|
|
></i>
|
|
|
|
</h1>
|
|
|
|
|
|
|
|
<form v-if="creating" @submit.prevent="createPlaylist" name="create-simple-playlist-form" class="create">
|
|
|
|
<input
|
|
|
|
@keyup.esc.prevent="creating = false"
|
|
|
|
placeholder="↵ to save"
|
|
|
|
name="name"
|
|
|
|
required
|
|
|
|
type="text"
|
|
|
|
v-koel-focus
|
|
|
|
v-model="newName"
|
|
|
|
>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<ul>
|
2022-04-15 17:00:08 +00:00
|
|
|
<PlaylistItem type="favorites" :playlist="{ name: 'Favorites', songs: favoriteState.songs }"/>
|
|
|
|
<PlaylistItem type="recently-played" :playlist="{ name: 'Recently Played', songs: [] }"/>
|
|
|
|
<PlaylistItem
|
2022-04-15 14:24:30 +00:00
|
|
|
:playlist="playlist"
|
|
|
|
:key="playlist.id"
|
|
|
|
type="playlist"
|
|
|
|
v-for="playlist in playlistState.playlists"
|
|
|
|
/>
|
|
|
|
</ul>
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
<ContextMenu ref="contextMenu" @createPlaylist="creating = true"/>
|
2022-04-15 14:24:30 +00:00
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { defineAsyncComponent, nextTick, reactive, ref } from 'vue'
|
|
|
|
import { favoriteStore, playlistStore } from '@/stores'
|
2022-04-15 14:24:30 +00:00
|
|
|
import router from '@/router'
|
|
|
|
|
2022-04-20 10:35:36 +00:00
|
|
|
const PlaylistItem = defineAsyncComponent(() => import('@/components/playlist/PlaylistSidebarItem.vue'))
|
2022-04-20 12:38:38 +00:00
|
|
|
const ContextMenu = defineAsyncComponent(() => import('@/components/playlist/CreateNewPlaylistContextMenu.vue'))
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-20 12:38:38 +00:00
|
|
|
const contextMenu = ref<InstanceType<typeof ContextMenu>>()
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
const playlistState = reactive(playlistStore.state)
|
|
|
|
const favoriteState = reactive(favoriteStore.state)
|
|
|
|
const creating = ref(false)
|
|
|
|
const newName = ref('')
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
const createPlaylist = async () => {
|
|
|
|
creating.value = false
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
const playlist = await playlistStore.store(newName.value)
|
|
|
|
newName.value = ''
|
|
|
|
// Activate the new playlist right away
|
|
|
|
await nextTick()
|
|
|
|
router.go(`playlist/${playlist.id}`)
|
|
|
|
}
|
|
|
|
|
|
|
|
const toggleContextMenu = async (event: MouseEvent) => {
|
|
|
|
await nextTick()
|
2022-04-20 12:38:38 +00:00
|
|
|
if (creating.value) {
|
2022-04-15 17:00:08 +00:00
|
|
|
creating.value = false
|
|
|
|
} else {
|
|
|
|
contextMenu.value?.open(event.pageY, event.pageX)
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
2022-04-15 17:00:08 +00:00
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
#playlists {
|
|
|
|
.control.create {
|
|
|
|
margin: -8px -10px -10px;
|
|
|
|
font-size: 16px;
|
|
|
|
transition: .3s;
|
|
|
|
padding: 10px;
|
|
|
|
|
|
|
|
&.creating {
|
|
|
|
transform: rotate(135deg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
form.create {
|
|
|
|
padding: 8px 16px;
|
|
|
|
|
|
|
|
input[type="text"] {
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|