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

75 lines
1.8 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
<section id="recentlyPlayedWrapper">
2022-04-15 17:00:08 +00:00
<ScreenHeader>
2022-04-15 14:24:30 +00:00
Recently Played
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') }} {{ duration }}</span>
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-06-10 10:47:46 +00:00
<SongList v-if="songs.length" ref="songList" @press:enter="onPressEnter"/>
2022-04-15 14:24:30 +00:00
<ScreenEmptyState v-else>
2022-04-15 14:24:30 +00:00
<template v-slot:icon>
<i class="fa fa-clock-o"></i>
</template>
No songs recently played.
2022-04-21 16:06:45 +00:00
<span class="secondary d-block">Start playing to populate this playlist.</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-04-15 14:24:30 +00:00
import { eventBus, pluralize } from '@/utils'
import { recentlyPlayedStore } from '@/stores'
2022-04-15 17:00:08 +00:00
import { useSongList } from '@/composables'
import { 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
showingControls,
isPhone,
onPressEnter,
playAll,
2022-04-15 17:00:08 +00:00
playSelected,
toggleControls
2022-06-10 10:47:46 +00:00
} = useSongList(toRef(recentlyPlayedStore.state, 'songs'), 'recently-played', { sortable: false })
let initialized = false
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
eventBus.on({
2022-06-10 10:47:46 +00:00
'LOAD_MAIN_CONTENT': async (view: MainViewName) => {
if (view === 'RecentlyPlayed' && !initialized) {
await recentlyPlayedStore.fetch()
initialized = true
}
}
2022-04-15 14:24:30 +00:00
})
</script>
<style lang="scss">
#recentlyPlayedWrapper {
.none {
padding: 16px 24px;
}
}
</style>