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

108 lines
3.3 KiB
Vue
Raw Normal View History

2024-05-19 05:49:42 +00:00
<template>
<ScreenBase>
<template #header>
<ScreenHeader layout="collapsed">
Podcasts
<template #controls>
<div class="flex gap-2" v-if="!loading">
2024-06-13 14:46:13 +00:00
<PodcastListSorter :field="sortParams.field" :order="sortParams.order" @sort="sort" />
2024-05-19 05:49:42 +00:00
<ListFilter @change="onFilterChanged" />
<BtnGroup uppercase>
<Btn @click.prevent="requestAddPodcastForm" highlight>
<Icon :icon="faAdd" fixed-width />
</Btn>
</BtnGroup>
</div>
</template>
</ScreenHeader>
</template>
<ScreenEmptyState v-if="noPodcasts">
<template #icon>
<Icon :icon="faPodcast" />
</template>
No podcasts found.
<span class="secondary d-block">Add a podcast to get started.</span>
</ScreenEmptyState>
<div v-else v-koel-overflow-fade class="-m-6 p-6 overflow-auto space-y-3 min-h-full">
<template v-if="loading">
<PodcastItemSkeleton v-for="i in 5" :key="i" />
</template>
<template v-else>
<PodcastItem v-for="podcast in podcasts" :podcast="podcast" :key="podcast.id" />
</template>
</div>
</ScreenBase>
</template>
<script setup lang="ts">
import { faAdd, faPodcast } from '@fortawesome/free-solid-svg-icons'
import { orderBy } from 'lodash'
2024-06-13 14:46:13 +00:00
import { computed, reactive, ref } from 'vue'
2024-05-19 05:49:42 +00:00
import { eventBus } from '@/utils'
import { useErrorHandler, useFuzzySearch, useRouter } from '@/composables'
2024-05-19 05:49:42 +00:00
import { podcastStore } from '@/stores'
import Btn from '@/components/ui/form/Btn.vue'
import BtnGroup from '@/components/ui/form/BtnGroup.vue'
import ListFilter from '@/components/song/SongListFilter.vue'
2024-06-13 14:46:13 +00:00
import PodcastItem from '@/components/podcast/PodcastItem.vue'
2024-05-19 05:49:42 +00:00
import PodcastItemSkeleton from '@/components/ui/skeletons/PodcastItemSkeleton.vue'
2024-06-13 14:46:13 +00:00
import PodcastListSorter from '@/components/podcast/PodcastListSorter.vue'
import ScreenBase from '@/components/screens/ScreenBase.vue'
import ScreenEmptyState from '@/components/ui/ScreenEmptyState.vue'
import ScreenHeader from '@/components/ui/ScreenHeader.vue'
2024-05-19 05:49:42 +00:00
const { onScreenActivated } = useRouter()
const fuzzy = useFuzzySearch<Podcast>([], ['title', 'description', 'author'])
2024-05-19 05:49:42 +00:00
let initialized = false
const loading = ref(false)
const keywords = ref('')
2024-06-13 14:46:13 +00:00
const sortParams = reactive<{ field: PodcastListSortField, order: SortOrder }>({
field: 'last_played_at',
order: 'desc'
})
2024-05-19 05:49:42 +00:00
const noPodcasts = computed(() => !loading.value && podcasts.value.length === 0)
const init = async () => {
if (loading.value) return
loading.value = true
try {
fuzzy.setDocuments(await podcastStore.fetchAll())
2024-05-19 05:49:42 +00:00
} catch (error: any) {
useErrorHandler().handleHttpError(error)
} finally {
loading.value = false
}
}
const podcasts = computed(() => orderBy(
keywords.value ? fuzzy.search(keywords.value) : podcastStore.state.podcasts,
sortParams.field,
sortParams.order
))
2024-05-19 05:49:42 +00:00
const onFilterChanged = (q: string) => (keywords.value = q)
const requestAddPodcastForm = () => eventBus.emit('MODAL_SHOW_ADD_PODCAST_FORM')
const sort = (field: PodcastListSortField) => {
2024-06-13 14:46:13 +00:00
sortParams.field = field
sortParams.order = sortParams.order === 'asc' ? 'desc' : 'asc'
}
2024-05-19 05:49:42 +00:00
onScreenActivated('Podcasts', async () => {
if (!initialized) {
initialized = true
await init()
}
})
</script>