2022-04-15 14:24:30 +00:00
|
|
|
<template>
|
2022-04-21 16:06:45 +00:00
|
|
|
<section id="playlistWrapper" v-if="playlist">
|
2022-04-15 17:00:08 +00:00
|
|
|
<ScreenHeader>
|
2022-07-12 16:49:15 +00:00
|
|
|
{{ playlist.name }}
|
2022-06-10 10:47:46 +00:00
|
|
|
<ControlsToggle v-if="songs.length" :showing-controls="showingControls" @toggleControls="toggleControls"/>
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-07-10 17:15:56 +00:00
|
|
|
<template v-slot:meta v-if="songs.length">
|
|
|
|
<span>{{ pluralize(songs.length, 'song') }}</span>
|
|
|
|
<span>{{ duration }}</span>
|
|
|
|
<a
|
|
|
|
v-if="allowDownload"
|
|
|
|
href
|
|
|
|
role="button"
|
|
|
|
title="Download all songs in playlist"
|
|
|
|
@click.prevent="download"
|
|
|
|
>
|
|
|
|
Download All
|
|
|
|
</a>
|
2022-04-15 14:24:30 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<template v-slot:controls>
|
2022-04-15 17:00:08 +00:00
|
|
|
<SongListControls
|
2022-06-10 10:47:46 +00:00
|
|
|
v-if="!isPhone || showingControls"
|
2022-04-15 14:24:30 +00:00
|
|
|
@playAll="playAll"
|
|
|
|
@playSelected="playSelected"
|
|
|
|
@deletePlaylist="destroy"
|
2022-06-10 10:47:46 +00:00
|
|
|
:config="controlsConfig"
|
2022-04-15 14:24:30 +00:00
|
|
|
/>
|
|
|
|
</template>
|
2022-04-15 17:00:08 +00:00
|
|
|
</ScreenHeader>
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-06-10 10:47:46 +00:00
|
|
|
<SongList
|
|
|
|
v-if="songs.length"
|
|
|
|
ref="songList"
|
|
|
|
@press:delete="removeSelected"
|
|
|
|
@press:enter="onPressEnter"
|
|
|
|
@sort="sort"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<ScreenEmptyState v-if="!songs.length && !loading">
|
|
|
|
<template v-slot:icon>
|
2022-07-15 07:23:55 +00:00
|
|
|
<icon :icon="faFile"/>
|
2022-06-10 10:47:46 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<template v-if="playlist?.is_smart">
|
|
|
|
No songs match the playlist's
|
|
|
|
<a @click.prevent="editSmartPlaylist">criteria</a>.
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
The playlist is currently empty.
|
|
|
|
<span class="d-block secondary">
|
2022-07-05 15:09:20 +00:00
|
|
|
Drag songs into its name in the sidebar or use the "Add To…" button to fill it up.
|
2022-06-10 10:47:46 +00:00
|
|
|
</span>
|
|
|
|
</template>
|
|
|
|
</ScreenEmptyState>
|
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 { faFile } from '@fortawesome/free-regular-svg-icons'
|
2022-04-29 18:26:07 +00:00
|
|
|
import { difference } from 'lodash'
|
2022-07-07 18:05:46 +00:00
|
|
|
import { ref, toRef } from 'vue'
|
2022-04-24 17:58:12 +00:00
|
|
|
import { alerts, eventBus, pluralize } from '@/utils'
|
2022-06-10 10:47:46 +00:00
|
|
|
import { commonStore, playlistStore, songStore } from '@/stores'
|
2022-04-24 08:50:45 +00:00
|
|
|
import { downloadService } from '@/services'
|
2022-04-15 17:00:08 +00:00
|
|
|
import { useSongList } from '@/composables'
|
|
|
|
|
2022-07-07 18:05:46 +00:00
|
|
|
import ScreenHeader from '@/components/ui/ScreenHeader.vue'
|
|
|
|
import ScreenEmptyState from '@/components/ui/ScreenEmptyState.vue'
|
2022-04-15 17:00:08 +00:00
|
|
|
|
2022-04-21 16:06:45 +00:00
|
|
|
const playlist = ref<Playlist>()
|
2022-06-10 10:47:46 +00:00
|
|
|
const loading = ref(false)
|
|
|
|
|
|
|
|
const controlsConfig: Partial<SongListControlsConfig> = { deletePlaylist: true }
|
2022-04-21 16:06:45 +00:00
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
const {
|
|
|
|
SongList,
|
|
|
|
SongListControls,
|
2022-06-10 10:47:46 +00:00
|
|
|
ControlsToggle,
|
2022-04-21 16:06:45 +00:00
|
|
|
songs,
|
2022-04-15 17:00:08 +00:00
|
|
|
songList,
|
2022-04-23 21:24:02 +00:00
|
|
|
duration,
|
2022-04-15 17:00:08 +00:00
|
|
|
selectedSongs,
|
|
|
|
showingControls,
|
|
|
|
isPhone,
|
2022-04-21 18:12:11 +00:00
|
|
|
onPressEnter,
|
2022-04-15 17:00:08 +00:00
|
|
|
playAll,
|
|
|
|
playSelected,
|
2022-06-10 10:47:46 +00:00
|
|
|
toggleControls,
|
|
|
|
sort
|
2022-07-12 16:49:15 +00:00
|
|
|
} = useSongList(ref<Song[]>([]), 'playlist')
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-06-10 10:47:46 +00:00
|
|
|
const allowDownload = toRef(commonStore.state, 'allow_download')
|
2022-04-15 17:00:08 +00:00
|
|
|
|
|
|
|
const destroy = () => eventBus.emit('PLAYLIST_DELETE', playlist.value)
|
2022-04-21 16:06:45 +00:00
|
|
|
const download = () => downloadService.fromPlaylist(playlist.value!)
|
2022-04-15 17:00:08 +00:00
|
|
|
const editSmartPlaylist = () => eventBus.emit('MODAL_SHOW_EDIT_SMART_PLAYLIST_FORM', playlist.value)
|
|
|
|
|
2022-04-21 18:12:11 +00:00
|
|
|
const removeSelected = () => {
|
2022-07-04 10:39:02 +00:00
|
|
|
if (!selectedSongs.value.length || playlist.value.is_smart) return
|
2022-04-21 18:12:11 +00:00
|
|
|
|
|
|
|
playlistStore.removeSongs(playlist.value!, selectedSongs.value)
|
|
|
|
songs.value = difference(songs.value, selectedSongs.value)
|
2022-04-24 17:58:12 +00:00
|
|
|
alerts.success(`Removed ${pluralize(selectedSongs.value.length, 'song')} from "${playlist.value!.name}."`)
|
2022-04-21 18:12:11 +00:00
|
|
|
}
|
|
|
|
|
2022-06-10 10:47:46 +00:00
|
|
|
const fetchSongs = async () => {
|
|
|
|
loading.value = true
|
2022-07-12 16:49:15 +00:00
|
|
|
songs.value = await songStore.fetchForPlaylist(playlist.value!)
|
2022-06-10 10:47:46 +00:00
|
|
|
loading.value = false
|
2022-07-05 15:09:20 +00:00
|
|
|
sort()
|
2022-04-15 17:00:08 +00:00
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-23 23:11:21 +00:00
|
|
|
eventBus.on({
|
2022-07-12 16:49:15 +00:00
|
|
|
'LOAD_MAIN_CONTENT': async (view: MainViewName, p: any) => {
|
|
|
|
if (view === 'Playlist') {
|
|
|
|
playlist.value = p as Playlist
|
|
|
|
await fetchSongs()
|
2022-04-23 23:11:21 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-07-12 16:49:15 +00:00
|
|
|
'SMART_PLAYLIST_UPDATED': async (updated: Playlist) => updated === playlist.value && await fetchSongs()
|
2022-04-15 17:00:08 +00:00
|
|
|
}
|
2022-04-23 23:11:21 +00:00
|
|
|
)
|
2022-04-15 14:24:30 +00:00
|
|
|
</script>
|