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

121 wiersze
2.8 KiB
Vue
Czysty Zwykły widok Historia

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"
:default-cover="defaultCover"
:is-podcast="isPodcast"
:show-art="true"
:show-position="false"
:tracks="objects"
:show-artist="false"
:show-album="false"
:paginate-results="true"
:total="count"
:page="page"
2021-12-06 10:35:20 +00:00
:paginate-by="limit"
@page-changed="updatePage"
/>
2021-10-21 17:26:18 +00:00
<track-table
v-else
:default-cover="defaultCover"
:is-podcast="isPodcast"
:show-art="true"
:show-position="false"
:tracks="objects"
:show-artist="false"
:show-album="false"
:paginate-results="true"
:total="count"
:page="page"
2021-12-06 10:35:20 +00:00
:paginate-by="limit"
:filters="filters"
2021-12-06 10:35:20 +00:00
@page-changed="updatePage"
/>
2020-02-05 14:06:07 +00:00
<template v-if="!isLoading && objects.length === 0">
2021-12-06 10:35:20 +00:00
<empty-state
:refresh="true"
@refresh="fetchData('tracks/')"
>
2020-04-22 06:16:12 +00:00
<p>
2021-12-06 10:35:20 +00:00
<translate translate-context="Content/Channels/*">
You may need to subscribe to this channel to see its content.
</translate>
2020-04-22 06:16:12 +00:00
</p>
</empty-state>
2020-02-05 14:06:07 +00:00
</template>
</div>
</template>
<script>
import { clone } from 'lodash-es'
2020-02-05 14:06:07 +00:00
import axios from 'axios'
2022-04-23 07:37:43 +00:00
import PodcastTable from '~/components/audio/podcast/Table.vue'
import TrackTable from '~/components/audio/track/Table.vue'
2020-02-05 14:06:07 +00:00
export default {
components: {
2021-10-21 17:26:18 +00:00
PodcastTable,
2021-12-06 10:35:20 +00:00
TrackTable
},
props: {
filters: { type: Object, required: true },
limit: { type: Number, default: 10 },
2022-03-22 15:13:19 +00:00
defaultCover: { type: Object, default: () => ({}) },
2021-12-06 10:35:20 +00:00
isPodcast: { type: Boolean, required: true }
2020-02-05 14:06:07 +00:00
},
data () {
return {
objects: [],
count: 0,
isLoading: false,
2021-12-06 10:35:20 +00:00
errors: [],
2020-07-27 09:02:56 +00:00
nextPage: null,
page: 1
2020-02-05 14:06:07 +00:00
}
},
2021-12-06 10:35:20 +00:00
watch: {
page () {
this.fetchData('tracks/')
}
},
2020-02-05 14:06:07 +00:00
created () {
this.fetchData('tracks/')
},
methods: {
2021-10-21 17:26:18 +00:00
async fetchData (url) {
2020-02-05 14:06:07 +00:00
if (!url) {
return
}
this.isLoading = true
2021-12-06 10:35:20 +00:00
const self = this
const params = clone(this.filters)
2020-02-05 14:06:07 +00:00
params.page_size = this.limit
2020-07-27 09:02:56 +00:00
params.page = this.page
2020-02-05 14:06:07 +00:00
params.include_channels = true
2021-10-21 17:26:18 +00:00
try {
2021-12-06 10:35:20 +00:00
const channelsPromise = await axios.get(url, { params: params })
self.nextPage = channelsPromise.data.next
self.objects = channelsPromise.data.results
self.count = channelsPromise.data.count
self.$emit('fetched', channelsPromise.data)
self.isLoading = false
} catch (e) {
2020-02-05 14:06:07 +00:00
self.isLoading = false
2021-12-06 10:35:20 +00:00
self.errors = e.backendErrors
2021-10-21 17:26:18 +00:00
}
2020-02-05 14:06:07 +00:00
},
2021-12-06 10:35:20 +00:00
updatePage: function (page) {
2020-07-27 09:02:56 +00:00
this.page = page
}
2020-02-05 14:06:07 +00:00
}
}
</script>