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

99 lines
2.5 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
<section id="favoritesWrapper">
2022-04-15 17:00:08 +00:00
<ScreenHeader>
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
<template v-slot:meta>
2022-04-23 21:24:02 +00:00
<span v-if="songs.length">
{{ pluralize(songs.length, 'song') }}
2022-04-15 14:24:30 +00:00
2022-04-23 21:24:02 +00:00
{{ duration }}
<template v-if="allowDownload">
2022-04-15 14:24:30 +00:00
2022-04-21 16:06:45 +00:00
<a class="download" href role="button" title="Download all songs in playlist" @click.prevent="download">
2022-04-15 14:24:30 +00:00
Download All
</a>
</template>
</span>
</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
<SongList
2022-06-10 10:47:46 +00:00
v-show="songs.length"
ref="songList"
@press:delete="removeSelected"
@press:enter="onPressEnter"
2022-06-10 10:47:46 +00:00
@sort="sort"
/>
2022-04-15 14:24:30 +00:00
2022-06-10 10:47:46 +00:00
<ScreenEmptyState v-show="!songs.length">
2022-04-15 14:24:30 +00:00
<template v-slot:icon>
<i class="fa fa-frown-o"></i>
</template>
No favorites yet.
<span class="secondary d-block">
2022-04-21 16:06:45 +00:00
Click the&nbsp;
<i class="fa fa-heart-o"></i>&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-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'
import { nextTick, 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-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-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,
onPressEnter,
2022-04-15 17:00:08 +00:00
playAll,
playSelected,
2022-06-10 10:47:46 +00:00
toggleControls,
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
const fetchSongs = async () => {
await favoriteStore.fetch()
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>