koel/resources/assets/js/components/screens/PlaylistScreen.vue

154 lines
4.7 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
<section v-if="playlist" id="playlistWrapper">
<ScreenHeader :layout="songs.length === 0 ? 'collapsed' : headerLayout" :disabled="loading">
2022-07-12 16:49:15 +00:00
{{ playlist.name }}
2022-12-02 16:17:37 +00:00
<ControlsToggle v-if="songs.length" v-model="showingControls" />
2022-04-15 14:24:30 +00:00
2022-12-02 16:17:37 +00:00
<template #thumbnail>
<ThumbnailStack :thumbnails="thumbnails" />
2022-07-16 09:52:39 +00:00
</template>
2024-01-18 11:13:05 +00:00
<template v-if="songs.length || playlist.collaborators.length" #meta>
<CollaboratorsBadge :playlist="playlist" v-if="playlist.collaborators.length" />
<span>{{ pluralize(songs, 'song') }}</span>
2022-07-10 17:15:56 +00:00
<span>{{ duration }}</span>
<a
v-if="allowDownload"
role="button"
title="Download all songs in playlist"
@click.prevent="download"
>
Download All
</a>
2022-04-15 14:24:30 +00:00
</template>
2022-12-02 16:17:37 +00:00
<template #controls>
2022-04-15 17:00:08 +00:00
<SongListControls
2022-06-10 10:47:46 +00:00
v-if="!isPhone || showingControls"
2022-07-16 09:52:39 +00:00
:config="controlsConfig"
2022-12-02 16:17:37 +00:00
@delete-playlist="destroy"
@filter="applyFilter"
2022-12-02 16:17:37 +00:00
@play-all="playAll"
@play-selected="playSelected"
@refresh="fetchSongs(true)"
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-12-02 16:17:37 +00:00
<SongListSkeleton v-show="loading" />
2022-06-10 10:47:46 +00:00
<SongList
2022-07-30 15:08:20 +00:00
v-if="!loading && songs.length"
2022-06-10 10:47:46 +00:00
ref="songList"
@sort="sort"
2022-06-10 10:47:46 +00:00
@press:delete="removeSelected"
@press:enter="onPressEnter"
2022-07-16 09:52:39 +00:00
@scroll-breakpoint="onScrollBreakpoint"
2022-06-10 10:47:46 +00:00
/>
<ScreenEmptyState v-if="!songs.length && !loading">
2022-12-02 16:17:37 +00:00
<template #icon>
2023-11-10 13:16:06 +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="editPlaylist">criteria</a>.
2022-06-10 10:47:46 +00:00
</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 &quot;Add To&quot; 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-07-22 21:56:13 +00:00
import { differenceBy } from 'lodash'
import { ref, toRef, watch } from 'vue'
2022-11-18 18:44:20 +00:00
import { 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'
2024-01-18 11:13:05 +00:00
import { usePlaylistManagement, useRouter, useSongList, useAuthorization, useSongListControls } from '@/composables'
2022-04-15 17:00:08 +00:00
import ScreenHeader from '@/components/ui/ScreenHeader.vue'
import ScreenEmptyState from '@/components/ui/ScreenEmptyState.vue'
2022-07-30 15:08:20 +00:00
import SongListSkeleton from '@/components/ui/skeletons/SongListSkeleton.vue'
2024-01-18 11:13:05 +00:00
import CollaboratorsBadge from '@/components/playlist/CollaboratorsBadge.vue'
2022-04-15 17:00:08 +00:00
2024-01-18 11:13:05 +00:00
const { currentUser } = useAuthorization()
const { triggerNotFound, getRouteParam, onScreenActivated } = useRouter()
2024-01-18 11:13:05 +00:00
const playlistId = ref<string>()
2022-04-21 16:06:45 +00:00
const playlist = ref<Playlist>()
2022-06-10 10:47:46 +00:00
const loading = ref(false)
2022-04-15 17:00:08 +00:00
const {
SongList,
2022-06-10 10:47:46 +00:00
ControlsToggle,
2022-07-16 09:52:39 +00:00
ThumbnailStack,
headerLayout,
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-07-16 09:52:39 +00:00
thumbnails,
2022-04-15 17:00:08 +00:00
selectedSongs,
showingControls,
isPhone,
onPressEnter,
2022-04-15 17:00:08 +00:00
playAll,
playSelected,
applyFilter,
2022-07-16 09:52:39 +00:00
onScrollBreakpoint,
2024-01-18 11:13:05 +00:00
sort,
config: listConfig
} = useSongList(ref<Song[]>([]))
2022-04-15 14:24:30 +00:00
2024-01-18 11:13:05 +00:00
const { SongListControls, config: controlsConfig } = useSongListControls('Playlist')
const { removeSongsFromPlaylist } = usePlaylistManagement()
2024-01-04 11:35:36 +00:00
const allowDownload = toRef(commonStore.state, 'allows_download')
2022-04-15 17:00:08 +00:00
2022-12-02 16:17:37 +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-12-02 16:17:37 +00:00
const editPlaylist = () => eventBus.emit('MODAL_SHOW_EDIT_PLAYLIST_FORM', playlist.value!)
2022-04-15 17:00:08 +00:00
const removeSelected = async () => await removeSongsFromPlaylist(playlist.value!, selectedSongs.value)
const fetchSongs = async (refresh = false) => {
2023-08-20 22:35:58 +00:00
if (loading.value) return
2022-06-10 10:47:46 +00:00
loading.value = true
songs.value = await songStore.fetchForPlaylist(playlist.value!, refresh)
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
watch(playlistId, async id => {
if (!id) return
playlist.value = playlistStore.byId(id)
2024-01-18 11:13:05 +00:00
// reset this config value to its default to not cause rows to be mal-rendered
listConfig.collaborative = false
if (playlist.value) {
await fetchSongs()
listConfig.collaborative = playlist.value.collaborators.length > 0
controlsConfig.deletePlaylist = playlist.value.user_id === currentUser.value?.id
} else {
await triggerNotFound()
}
})
2024-01-18 11:13:05 +00:00
onScreenActivated('Playlist', () => (playlistId.value = getRouteParam('id')!))
eventBus.on('PLAYLIST_UPDATED', async updated => updated.id === playlistId.value && await fetchSongs())
.on('PLAYLIST_SONGS_REMOVED', async (playlist, removed) => {
if (playlist.id !== playlistId.value) return
songs.value = differenceBy(songs.value, removed, 'id')
})
2022-04-15 14:24:30 +00:00
</script>