2022-04-15 14:24:30 +00:00
|
|
|
<template>
|
|
|
|
<section id="songsWrapper">
|
2022-04-15 17:00:08 +00:00
|
|
|
<ScreenHeader>
|
2022-04-15 14:24:30 +00:00
|
|
|
All Songs
|
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-06-10 10:47:46 +00:00
|
|
|
<span v-if="totalSongCount">{{ pluralize(totalSongCount, 'song') }} • {{ totalDuration }}</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)"
|
2022-04-15 14:24:30 +00:00
|
|
|
@playAll="playAll"
|
|
|
|
@playSelected="playSelected"
|
|
|
|
/>
|
|
|
|
</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 ref="songList" @press:enter="onPressEnter" @scrolled-to-end="fetchSongs" @sort="sort"/>
|
2022-04-15 14:24:30 +00:00
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
<script lang="ts" setup>
|
2022-07-07 18:05:46 +00:00
|
|
|
import { computed, ref, toRef } from 'vue'
|
2022-06-10 10:47:46 +00:00
|
|
|
import { eventBus, pluralize, secondsToHis } from '@/utils'
|
|
|
|
import { commonStore, queueStore, songStore } from '@/stores'
|
|
|
|
import { playbackService } from '@/services'
|
2022-04-15 17:00:08 +00:00
|
|
|
import { useSongList } from '@/composables'
|
2022-06-10 10:47:46 +00:00
|
|
|
import router from '@/router'
|
2022-04-21 16:06:45 +00:00
|
|
|
|
2022-07-07 18:05:46 +00:00
|
|
|
import ScreenHeader from '@/components/ui/ScreenHeader.vue'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-06-10 10:47:46 +00:00
|
|
|
const totalSongCount = toRef(commonStore.state, 'song_count')
|
|
|
|
const totalDuration = computed(() => secondsToHis(commonStore.state.song_length))
|
|
|
|
|
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,
|
2022-04-21 18:12:11 +00:00
|
|
|
onPressEnter,
|
2022-04-15 17:00:08 +00:00
|
|
|
playSelected,
|
|
|
|
toggleControls
|
2022-06-10 10:47:46 +00:00
|
|
|
} = useSongList(toRef(songStore.state, 'songs'), 'all-songs')
|
|
|
|
|
|
|
|
let initialized = false
|
|
|
|
let loading = false
|
|
|
|
let sortField: SongListSortField = 'title' // @todo get from query string
|
|
|
|
let sortOrder: SortOrder = 'asc'
|
|
|
|
|
|
|
|
const page = ref<number | null>(1)
|
|
|
|
const moreSongsAvailable = computed(() => page.value !== null)
|
|
|
|
|
|
|
|
const sort = async (field: SongListSortField, order: SortOrder) => {
|
|
|
|
page.value = 1
|
|
|
|
songStore.state.songs = []
|
|
|
|
sortField = field
|
|
|
|
sortOrder = order
|
|
|
|
|
|
|
|
await fetchSongs()
|
|
|
|
}
|
|
|
|
|
|
|
|
const fetchSongs = async () => {
|
|
|
|
if (!moreSongsAvailable.value || loading) return
|
|
|
|
|
|
|
|
loading = true
|
|
|
|
page.value = await songStore.fetch(sortField, sortOrder, page.value!)
|
|
|
|
loading = false
|
|
|
|
}
|
|
|
|
|
|
|
|
const playAll = async (shuffle: boolean) => {
|
|
|
|
if (shuffle) {
|
|
|
|
await queueStore.fetchRandom()
|
|
|
|
} else {
|
|
|
|
await queueStore.fetchInOrder(sortField, sortOrder)
|
|
|
|
}
|
|
|
|
|
|
|
|
await playbackService.playFirstInQueue()
|
|
|
|
await router.go('/queue')
|
|
|
|
}
|
|
|
|
|
|
|
|
eventBus.on('LOAD_MAIN_CONTENT', async (view: MainViewName) => {
|
|
|
|
if (view === 'Songs' && !initialized) {
|
|
|
|
await fetchSongs()
|
|
|
|
initialized = true
|
|
|
|
}
|
|
|
|
})
|
2022-04-15 14:24:30 +00:00
|
|
|
</script>
|