funkwhale/front/src/components/audio/ChannelEntries.vue

112 wiersze
2.5 KiB
Vue
Czysty Zwykły widok Historia

2022-07-21 01:11:36 +00:00
<script setup lang="ts">
2022-08-30 20:23:17 +00:00
import type { Cover, Track, BackendResponse, BackendError } from '~/types'
2022-07-21 01:11:36 +00:00
import { clone } from 'lodash-es'
import { ref, watch } from 'vue'
import axios from 'axios'
import PodcastTable from '~/components/audio/podcast/Table.vue'
import TrackTable from '~/components/audio/track/Table.vue'
2022-08-30 20:23:17 +00:00
interface Events {
(e: 'fetched', data: BackendResponse<Track[]>): void
}
2022-07-21 01:11:36 +00:00
interface Props {
filters: object
limit?: number
defaultCover: Cover | null
isPodcast: boolean
}
2022-08-30 20:23:17 +00:00
const emit = defineEmits<Events>()
2022-07-21 01:11:36 +00:00
const props = withDefaults(defineProps<Props>(), {
limit: 10,
defaultCover: null
})
const channels = ref([] as Track[])
const nextPage = ref()
const page = ref(1)
const count = ref(0)
const errors = ref([] as string[])
const isLoading = ref(false)
const fetchData = async () => {
isLoading.value = true
const params = {
...clone(props.filters),
page_size: props.limit,
page: page.value,
include_channels: true
}
try {
const response = await axios.get('tracks/', { params })
nextPage.value = response.data.next
channels.value = response.data.results
count.value = response.data.count
emit('fetched', response.data)
} catch (error) {
errors.value = (error as BackendError).backendErrors
}
isLoading.value = false
}
watch(page, fetchData, { immediate: true })
</script>
2020-02-05 14:06:07 +00:00
<template>
<div>
2021-12-06 10:35:20 +00:00
<slot />
<div class="ui hidden divider" />
<div
v-if="isLoading"
class="ui inverted active dimmer"
>
<div class="ui loader" />
2020-02-05 14:06:07 +00:00
</div>
2021-10-21 17:26:18 +00:00
<podcast-table
v-if="isPodcast"
2022-07-21 01:11:36 +00:00
v-model:page="page"
2023-09-01 12:09:58 +00:00
:paginate-by="limit"
2021-10-21 17:26:18 +00:00
:default-cover="defaultCover"
:is-podcast="isPodcast"
:show-art="true"
:show-position="false"
2022-07-21 01:11:36 +00:00
:tracks="channels"
2021-10-21 17:26:18 +00:00
:show-artist="false"
:show-album="false"
:paginate-results="true"
:total="count"
2021-12-06 10:35:20 +00:00
/>
2021-10-21 17:26:18 +00:00
<track-table
v-else
2022-07-21 01:11:36 +00:00
v-model:page="page"
2021-10-21 17:26:18 +00:00
:default-cover="defaultCover"
:is-podcast="isPodcast"
:show-art="true"
:show-position="false"
2022-07-21 01:11:36 +00:00
:tracks="channels"
2021-10-21 17:26:18 +00:00
:show-artist="false"
:show-album="false"
:paginate-results="true"
:total="count"
2021-12-06 10:35:20 +00:00
:paginate-by="limit"
:filters="filters"
2021-12-06 10:35:20 +00:00
/>
2022-07-21 01:11:36 +00:00
<template v-if="!isLoading && channels.length === 0">
2021-12-06 10:35:20 +00:00
<empty-state
:refresh="true"
2022-07-21 01:11:36 +00:00
@refresh="fetchData()"
2021-12-06 10:35:20 +00:00
>
2020-04-22 06:16:12 +00:00
<p>
2022-09-18 23:12:39 +00:00
{{ $t('components.audio.ChannelEntries.help.subscribe') }}
2020-04-22 06:16:12 +00:00
</p>
</empty-state>
2020-02-05 14:06:07 +00:00
</template>
</div>
</template>