2022-04-15 14:24:30 +00:00
|
|
|
<template>
|
|
|
|
<section id="playlists">
|
2022-07-15 07:23:55 +00:00
|
|
|
<h1>
|
|
|
|
<span>Playlists</span>
|
|
|
|
<icon
|
2022-04-15 14:24:30 +00:00
|
|
|
:class="{ creating }"
|
2022-07-15 07:23:55 +00:00
|
|
|
:icon="faCirclePlus"
|
|
|
|
class="control create"
|
2022-05-08 18:18:27 +00:00
|
|
|
data-testid="sidebar-create-playlist-btn"
|
2022-04-15 14:24:30 +00:00
|
|
|
role="button"
|
|
|
|
title="Create a new playlist"
|
2022-05-29 21:08:51 +00:00
|
|
|
@click.stop.prevent="toggleContextMenu"
|
2022-07-15 07:23:55 +00:00
|
|
|
/>
|
2022-04-15 14:24:30 +00:00
|
|
|
</h1>
|
|
|
|
|
|
|
|
<form v-if="creating" @submit.prevent="createPlaylist" name="create-simple-playlist-form" class="create">
|
|
|
|
<input
|
2022-05-08 18:18:27 +00:00
|
|
|
v-model="newName"
|
|
|
|
v-koel-focus
|
2022-04-15 14:24:30 +00:00
|
|
|
name="name"
|
2022-05-08 18:18:27 +00:00
|
|
|
placeholder="↵ to save"
|
2022-04-15 14:24:30 +00:00
|
|
|
required
|
|
|
|
type="text"
|
2022-05-08 18:18:27 +00:00
|
|
|
@keyup.esc.prevent="creating = false"
|
2022-04-15 14:24:30 +00:00
|
|
|
>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<ul>
|
2022-05-09 08:14:56 +00:00
|
|
|
<PlaylistSidebarItem :playlist="{ name: 'Favorites', songs: favorites }" type="favorites"/>
|
|
|
|
<PlaylistSidebarItem :playlist="{ name: 'Recently Played', songs: [] }" type="recently-played"/>
|
|
|
|
<PlaylistSidebarItem
|
2022-05-08 18:18:27 +00:00
|
|
|
v-for="playlist in playlists"
|
2022-04-15 14:24:30 +00:00
|
|
|
:key="playlist.id"
|
2022-05-08 18:18:27 +00:00
|
|
|
:playlist="playlist"
|
2022-04-15 14:24:30 +00:00
|
|
|
type="playlist"
|
|
|
|
/>
|
|
|
|
</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>
|
2022-07-15 07:23:55 +00:00
|
|
|
import { faCirclePlus } from '@fortawesome/free-solid-svg-icons'
|
2022-07-07 18:05:46 +00:00
|
|
|
import { nextTick, ref, toRef } from 'vue'
|
2022-04-15 17:00:08 +00:00
|
|
|
import { favoriteStore, playlistStore } from '@/stores'
|
2022-04-15 14:24:30 +00:00
|
|
|
import router from '@/router'
|
2022-04-24 17:58:12 +00:00
|
|
|
import { alerts } from '@/utils'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-07-07 18:05:46 +00:00
|
|
|
import PlaylistSidebarItem from '@/components/playlist/PlaylistSidebarItem.vue'
|
|
|
|
import ContextMenu from '@/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-20 12:41:50 +00:00
|
|
|
const playlists = toRef(playlistStore.state, 'playlists')
|
2022-04-24 17:58:12 +00:00
|
|
|
const favorites = toRef(favoriteStore.state, 'songs')
|
2022-04-15 17:00:08 +00:00
|
|
|
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 = ''
|
2022-04-24 17:58:12 +00:00
|
|
|
|
|
|
|
alerts.success(`Playlist "${playlist.name}" created.`)
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
// 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 {
|
2022-07-15 07:23:55 +00:00
|
|
|
h1 {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
span {
|
|
|
|
flex: 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-15 14:24:30 +00:00
|
|
|
.control.create {
|
|
|
|
transition: .3s;
|
|
|
|
|
|
|
|
&.creating {
|
|
|
|
transform: rotate(135deg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
form.create {
|
|
|
|
padding: 8px 16px;
|
|
|
|
|
|
|
|
input[type="text"] {
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|