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

117 lines
3 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
<section id="favoritesWrapper">
2022-07-17 08:58:05 +00:00
<ScreenHeader :layout="songs.length === 0 ? 'collapsed' : headerLayout">
2022-04-15 14:24:30 +00:00
Songs You Love
2022-06-10 10:47:46 +00:00
<ControlsToggle :showing-controls="showingControls" @toggleControls="toggleControls"/>
2022-04-15 14:24:30 +00:00
2022-07-16 09:52:39 +00:00
<template v-slot:thumbnail>
<ThumbnailStack :thumbnails="thumbnails"/>
</template>
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"
class="download"
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-04-21 16:06:45 +00:00
v-if="songs.length && (!isPhone || showingControls)"
@playAll="playAll"
@playSelected="playSelected"
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-07-30 15:08:20 +00:00
<SongListSkeleton v-if="loading"/>
<SongList
2022-07-12 08:37:11 +00:00
v-if="songs.length"
ref="songList"
2022-07-16 09:52:39 +00:00
@sort="sort"
@press:delete="removeSelected"
@press:enter="onPressEnter"
2022-07-16 09:52:39 +00:00
@scroll-breakpoint="onScrollBreakpoint"
/>
2022-04-15 14:24:30 +00:00
2022-07-12 08:37:11 +00:00
<ScreenEmptyState v-else>
2022-04-15 14:24:30 +00:00
<template v-slot:icon>
2022-07-15 07:23:55 +00:00
<icon :icon="faHeartBroken"/>
2022-04-15 14:24:30 +00:00
</template>
No favorites yet.
<span class="secondary d-block">
2022-04-21 16:06:45 +00:00
Click the&nbsp;
2022-07-15 07:23:55 +00:00
<icon :icon="faHeart"/>&nbsp;
2022-04-15 14:24:30 +00:00
icon to mark a song as favorite.
</span>
</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 { faHeartBroken } from '@fortawesome/free-solid-svg-icons'
import { faHeart } from '@fortawesome/free-regular-svg-icons'
2022-06-10 10:47:46 +00:00
import { eventBus, pluralize } from '@/utils'
import { commonStore, favoriteStore } 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-30 15:08:20 +00:00
import { nextTick, ref, toRef } from 'vue'
2022-04-15 14:24:30 +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'
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const {
SongList,
SongListControls,
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,
2022-06-10 10:47:46 +00:00
toggleControls,
2022-07-16 09:52:39 +00:00
onScrollBreakpoint,
2022-06-10 10:47:46 +00:00
sort
} = useSongList(toRef(favoriteStore.state, 'songs'), 'favorites')
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 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const download = () => downloadService.fromFavorites()
const removeSelected = () => selectedSongs.value.length && favoriteStore.unlike(selectedSongs.value)
2022-06-10 10:47:46 +00:00
let initialized = false
2022-07-30 15:08:20 +00:00
const loading = ref(false)
2022-06-10 10:47:46 +00:00
const fetchSongs = async () => {
2022-07-30 15:08:20 +00:00
loading.value = true
2022-06-10 10:47:46 +00:00
await favoriteStore.fetch()
2022-07-30 15:08:20 +00:00
loading.value = false
2022-06-10 10:47:46 +00:00
await nextTick()
2022-07-05 15:09:20 +00:00
sort()
2022-06-10 10:47:46 +00:00
}
eventBus.on('LOAD_MAIN_CONTENT', async (view: MainViewName) => {
if (view === 'Favorites' && !initialized) {
await fetchSongs()
initialized = true
}
})
2022-04-15 14:24:30 +00:00
</script>