2022-04-15 14:24:30 +00:00
|
|
|
<template>
|
|
|
|
<section id="songsWrapper">
|
2022-07-17 08:58:05 +00:00
|
|
|
<ScreenHeader :layout="headerLayout">
|
2022-04-15 14:24:30 +00:00
|
|
|
All Songs
|
2022-12-02 16:17:37 +00:00
|
|
|
<ControlsToggle 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>
|
|
|
|
|
2022-12-02 16:17:37 +00:00
|
|
|
<template v-if="totalSongCount" #meta>
|
2022-07-10 17:15:56 +00:00
|
|
|
<span>{{ pluralize(totalSongCount, 'song') }}</span>
|
|
|
|
<span>{{ totalDuration }}</span>
|
2022-04-15 14:24:30 +00:00
|
|
|
</template>
|
|
|
|
|
2022-12-02 16:17:37 +00:00
|
|
|
<template #controls>
|
2024-01-11 22:14:22 +00:00
|
|
|
<div class="controls">
|
|
|
|
<SongListControls
|
|
|
|
v-if="totalSongCount && (!isPhone || showingControls)"
|
2024-01-18 11:13:05 +00:00
|
|
|
:config="config"
|
2024-01-11 22:14:22 +00:00
|
|
|
@play-all="playAll"
|
|
|
|
@play-selected="playSelected"
|
|
|
|
/>
|
2024-03-18 22:04:01 +00:00
|
|
|
<label v-if="isPlus" class="own-songs-toggle text-secondary">
|
2024-01-12 09:57:18 +00:00
|
|
|
<CheckBox v-model="ownSongsOnly" />
|
|
|
|
<span>Own songs only</span>
|
2024-01-11 22:14:22 +00:00
|
|
|
</label>
|
|
|
|
</div>
|
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-if="showSkeletons" />
|
2024-01-11 23:03:49 +00:00
|
|
|
<template v-else>
|
|
|
|
<SongList
|
2024-03-18 22:04:01 +00:00
|
|
|
v-if="songs?.length > 0"
|
2024-01-11 23:03:49 +00:00
|
|
|
ref="songList"
|
|
|
|
@sort="sort"
|
|
|
|
@scroll-breakpoint="onScrollBreakpoint"
|
|
|
|
@press:enter="onPressEnter"
|
|
|
|
@scrolled-to-end="fetchSongs"
|
|
|
|
/>
|
|
|
|
<ScreenEmptyState v-else>
|
|
|
|
<template #icon>
|
|
|
|
<Icon :icon="faVolumeOff" />
|
|
|
|
</template>
|
|
|
|
Your library is empty.
|
2024-01-11 23:29:00 +00:00
|
|
|
<a
|
|
|
|
v-if="isPlus && ownSongsOnly"
|
2024-03-18 22:04:01 +00:00
|
|
|
class="d-block secondary"
|
|
|
|
role="button"
|
2024-01-11 23:29:00 +00:00
|
|
|
@click.prevent="showSongsFromOthers"
|
|
|
|
>
|
|
|
|
Show public songs from other users?
|
|
|
|
</a>
|
2024-01-11 23:03:49 +00:00
|
|
|
</ScreenEmptyState>
|
|
|
|
</template>
|
2022-04-15 14:24:30 +00:00
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
<script lang="ts" setup>
|
2024-01-11 23:03:49 +00:00
|
|
|
import { faVolumeOff } from '@fortawesome/free-solid-svg-icons'
|
2024-01-11 22:14:22 +00:00
|
|
|
import { computed, ref, toRef, watch } from 'vue'
|
2022-11-18 18:44:20 +00:00
|
|
|
import { logger, pluralize, secondsToHumanReadable } from '@/utils'
|
2022-06-10 10:47:46 +00:00
|
|
|
import { commonStore, queueStore, songStore } from '@/stores'
|
2024-03-15 15:09:50 +00:00
|
|
|
import { playbackService } from '@/services'
|
|
|
|
import { useMessageToaster, useKoelPlus, useRouter, useSongList, useSongListControls, useLocalStorage } from '@/composables'
|
2022-04-21 16:06:45 +00:00
|
|
|
|
2022-07-07 18:05:46 +00:00
|
|
|
import ScreenHeader from '@/components/ui/ScreenHeader.vue'
|
2022-07-30 15:08:20 +00:00
|
|
|
import SongListSkeleton from '@/components/ui/skeletons/SongListSkeleton.vue'
|
2024-01-11 22:14:22 +00:00
|
|
|
import CheckBox from '@/components/ui/CheckBox.vue'
|
2024-01-11 23:03:49 +00:00
|
|
|
import ScreenEmptyState from '@/components/ui/ScreenEmptyState.vue'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-06-10 10:47:46 +00:00
|
|
|
const totalSongCount = toRef(commonStore.state, 'song_count')
|
2022-10-28 13:56:06 +00:00
|
|
|
const totalDuration = computed(() => secondsToHumanReadable(commonStore.state.song_length))
|
2022-06-10 10:47:46 +00:00
|
|
|
|
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,
|
|
|
|
thumbnails,
|
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,
|
2022-07-16 09:52:39 +00:00
|
|
|
onScrollBreakpoint
|
2024-01-22 23:11:13 +00:00
|
|
|
} = useSongList(toRef(songStore.state, 'songs'), { sortable: true })
|
2022-06-10 10:47:46 +00:00
|
|
|
|
2024-01-18 11:13:05 +00:00
|
|
|
const { SongListControls, config } = useSongListControls('Songs')
|
|
|
|
|
2022-11-18 17:45:38 +00:00
|
|
|
const { toastError } = useMessageToaster()
|
2022-11-18 18:56:21 +00:00
|
|
|
const { go, onScreenActivated } = useRouter()
|
2024-01-11 22:14:22 +00:00
|
|
|
const { isPlus } = useKoelPlus()
|
2024-03-15 15:09:50 +00:00
|
|
|
const { get: lsGet, set: lsSet } = useLocalStorage()
|
2022-10-08 10:54:25 +00:00
|
|
|
|
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
|
|
|
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)
|
2022-07-30 15:08:20 +00:00
|
|
|
const showSkeletons = computed(() => loading.value && songs.value.length === 0)
|
2022-06-10 10:47:46 +00:00
|
|
|
|
2024-03-15 15:09:50 +00:00
|
|
|
const ownSongsOnly = ref(isPlus.value ? Boolean(lsGet('own-songs-only')) : false)
|
2024-01-11 22:14:22 +00:00
|
|
|
|
|
|
|
watch(ownSongsOnly, async value => {
|
2024-03-15 15:09:50 +00:00
|
|
|
lsSet('own-songs-only', value)
|
2024-01-11 22:14:22 +00:00
|
|
|
page.value = 1
|
|
|
|
songStore.state.songs = []
|
|
|
|
|
|
|
|
await fetchSongs()
|
|
|
|
})
|
|
|
|
|
2022-06-10 10:47:46 +00:00
|
|
|
const sort = async (field: SongListSortField, order: SortOrder) => {
|
|
|
|
page.value = 1
|
|
|
|
songStore.state.songs = []
|
|
|
|
sortField = field
|
|
|
|
sortOrder = order
|
|
|
|
|
|
|
|
await fetchSongs()
|
|
|
|
}
|
|
|
|
|
2024-01-11 23:29:00 +00:00
|
|
|
const showSongsFromOthers = async () => {
|
|
|
|
ownSongsOnly.value = false
|
|
|
|
await fetchSongs()
|
|
|
|
}
|
|
|
|
|
2022-06-10 10:47:46 +00:00
|
|
|
const fetchSongs = async () => {
|
2022-07-30 15:08:20 +00:00
|
|
|
if (!moreSongsAvailable.value || loading.value) return
|
2022-06-10 10:47:46 +00:00
|
|
|
|
2022-07-30 15:08:20 +00:00
|
|
|
loading.value = true
|
2022-10-27 12:26:58 +00:00
|
|
|
|
|
|
|
try {
|
2024-01-15 22:26:50 +00:00
|
|
|
page.value = await songStore.paginate({
|
|
|
|
sort: sortField,
|
|
|
|
order: sortOrder,
|
|
|
|
page: page.value!,
|
|
|
|
own_songs_only: ownSongsOnly.value
|
|
|
|
})
|
2022-10-27 12:26:58 +00:00
|
|
|
} catch (error) {
|
2022-11-18 17:45:38 +00:00
|
|
|
toastError('Failed to load songs.')
|
2022-10-27 12:26:58 +00:00
|
|
|
logger.error(error)
|
|
|
|
} finally {
|
|
|
|
loading.value = false
|
|
|
|
}
|
2022-06-10 10:47:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const playAll = async (shuffle: boolean) => {
|
|
|
|
if (shuffle) {
|
|
|
|
await queueStore.fetchRandom()
|
|
|
|
} else {
|
|
|
|
await queueStore.fetchInOrder(sortField, sortOrder)
|
|
|
|
}
|
|
|
|
|
2022-11-18 18:44:20 +00:00
|
|
|
go('queue')
|
2022-10-27 12:26:58 +00:00
|
|
|
await playbackService.playFirstInQueue()
|
2022-06-10 10:47:46 +00:00
|
|
|
}
|
|
|
|
|
2022-11-18 18:56:21 +00:00
|
|
|
onScreenActivated('Songs', async () => {
|
2022-09-12 15:33:41 +00:00
|
|
|
if (!initialized) {
|
2022-06-10 10:47:46 +00:00
|
|
|
initialized = true
|
2022-09-12 15:33:41 +00:00
|
|
|
await fetchSongs()
|
2022-06-10 10:47:46 +00:00
|
|
|
}
|
|
|
|
})
|
2022-04-15 14:24:30 +00:00
|
|
|
</script>
|
2024-01-11 22:14:22 +00:00
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.controls {
|
|
|
|
width: 100%;
|
2024-01-12 09:57:18 +00:00
|
|
|
min-height: 32px; // prevent shrinking causing the jumping effect
|
2024-01-11 22:14:22 +00:00
|
|
|
display: flex;
|
|
|
|
justify-content: space-between;
|
|
|
|
align-items: center;
|
2024-01-11 23:11:29 +00:00
|
|
|
gap: 1rem;
|
|
|
|
|
|
|
|
.collapsed & {
|
|
|
|
width: auto;
|
|
|
|
}
|
2024-01-12 09:57:18 +00:00
|
|
|
|
|
|
|
.own-songs-toggle {
|
|
|
|
display: inline-flex;
|
|
|
|
align-items: center;
|
|
|
|
font-size: 1rem;
|
|
|
|
}
|
2024-01-11 22:14:22 +00:00
|
|
|
}
|
|
|
|
</style>
|