feat(front): use pagination component and title prop in channels widget
This commit is contained in:
parent
81ef66fafc
commit
744f613df4
|
@ -3,15 +3,15 @@ import type { BackendError, BackendResponse, Channel } from '~/types'
|
||||||
|
|
||||||
import { ref, onMounted, watch, reactive } from 'vue'
|
import { ref, onMounted, watch, reactive } from 'vue'
|
||||||
import { clone } from 'lodash-es'
|
import { clone } from 'lodash-es'
|
||||||
import { useI18n } from 'vue-i18n'
|
|
||||||
|
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
|
||||||
|
import usePage from '~/composables/navigation/usePage'
|
||||||
|
|
||||||
import ChannelCard from '~/components/audio/ChannelCard.vue'
|
import ChannelCard from '~/components/audio/ChannelCard.vue'
|
||||||
import Layout from '~/components/ui/Layout.vue'
|
|
||||||
import Loader from '~/components/ui/Loader.vue'
|
import Loader from '~/components/ui/Loader.vue'
|
||||||
import Button from '~/components/ui/Button.vue'
|
import Section from '~/components/ui/Section.vue'
|
||||||
import Spacer from '../ui/Spacer.vue'
|
import Pagination from '~/components/ui/Pagination.vue'
|
||||||
|
|
||||||
interface Events {
|
interface Events {
|
||||||
(e: 'fetched', channels: BackendResponse<Channel>): void
|
(e: 'fetched', channels: BackendResponse<Channel>): void
|
||||||
|
@ -19,19 +19,19 @@ interface Events {
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
filters: object
|
filters: object
|
||||||
limit?: number
|
limit?: number,
|
||||||
|
title?: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
const { t } = useI18n()
|
|
||||||
|
|
||||||
const emit = defineEmits<Events>()
|
const emit = defineEmits<Events>()
|
||||||
const props = withDefaults(defineProps<Props>(), {
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
limit: 5
|
limit: 5,
|
||||||
})
|
})
|
||||||
|
|
||||||
const channels = reactive([] as Channel[])
|
const channels = reactive([] as Channel[])
|
||||||
const errors = ref([] as string[])
|
const errors = ref([] as string[])
|
||||||
const nextPage = ref()
|
const nextPage = ref()
|
||||||
|
const page = usePage()
|
||||||
const count = ref(0)
|
const count = ref(0)
|
||||||
|
|
||||||
const isLoading = ref(false)
|
const isLoading = ref(false)
|
||||||
|
@ -41,8 +41,8 @@ const fetchData = async (url = 'channels/') => {
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
...clone(props.filters),
|
...clone(props.filters),
|
||||||
page_size: props.limit,
|
page: page.value,
|
||||||
include_channels: true
|
page_size: props.limit
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -62,41 +62,30 @@ onMounted(() => {
|
||||||
fetchData()
|
fetchData()
|
||||||
})
|
})
|
||||||
|
|
||||||
watch(() => props.filters, () => {
|
watch(() => [props.filters, page], () => {
|
||||||
fetchData()
|
fetchData()
|
||||||
}, { deep: true })
|
}, { deep: true })
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="channel-widget">
|
<Section aling-left :h2="title" class="channel-widget">
|
||||||
<h2
|
|
||||||
v-if="!!$slots.title"
|
|
||||||
>
|
|
||||||
<slot name="title" />
|
|
||||||
</h2>
|
|
||||||
<slot />
|
<slot />
|
||||||
<Layout flex>
|
<Loader v-if="isLoading" />
|
||||||
<Loader v-if="isLoading" />
|
<channel-card
|
||||||
<channel-card
|
v-for="object in channels"
|
||||||
v-for="object in channels"
|
:key="object.uuid"
|
||||||
:key="object.uuid"
|
:object="object"
|
||||||
:object="object"
|
/>
|
||||||
/>
|
</Section>
|
||||||
</Layout>
|
<template v-if="!isLoading && channels.length === 0">
|
||||||
<template v-if="nextPage">
|
<empty-state
|
||||||
<Spacer />
|
:refresh="true"
|
||||||
<Button
|
@refresh="fetchData('channels/')"
|
||||||
v-if="nextPage"
|
/>
|
||||||
@click="fetchData(nextPage)"
|
</template>
|
||||||
>
|
<Pagination
|
||||||
{{ t('components.audio.ChannelsWidget.button.showMore') }}
|
v-if="channels && count > limit"
|
||||||
</Button>
|
v-model:page="page"
|
||||||
</template>
|
:pages="Math.ceil((count || 0) / limit)"
|
||||||
<template v-if="!isLoading && channels.length === 0">
|
/>
|
||||||
<empty-state
|
|
||||||
:refresh="true"
|
|
||||||
@refresh="fetchData('channels/')"
|
|
||||||
/>
|
|
||||||
</template>
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -81,10 +81,8 @@ fetchData()
|
||||||
:show-modification-date="true"
|
:show-modification-date="true"
|
||||||
:filters="{ordering: '-creation_date'}"
|
:filters="{ordering: '-creation_date'}"
|
||||||
:limit="12"
|
:limit="12"
|
||||||
|
:title="t('components.library.Home.header.newChannels')"
|
||||||
>
|
>
|
||||||
<template #title>
|
|
||||||
{{ t('components.library.Home.header.newChannels') }}
|
|
||||||
</template>
|
|
||||||
</channels-widget>
|
</channels-widget>
|
||||||
|
|
||||||
<track-widget
|
<track-widget
|
||||||
|
|
|
@ -122,7 +122,7 @@ const showCreateModal = ref(false)
|
||||||
/>
|
/>
|
||||||
<channels-widget
|
<channels-widget
|
||||||
:key="widgetKey"
|
:key="widgetKey"
|
||||||
:limit="50"
|
:limit="4"
|
||||||
:show-modification-date="true"
|
:show-modification-date="true"
|
||||||
:filters="{q: query, subscribed: 'true'}"
|
:filters="{q: query, subscribed: 'true'}"
|
||||||
/>
|
/>
|
||||||
|
@ -143,7 +143,7 @@ const showCreateModal = ref(false)
|
||||||
/>
|
/>
|
||||||
<channels-widget
|
<channels-widget
|
||||||
:show-modification-date="true"
|
:show-modification-date="true"
|
||||||
:limit="12"
|
:limit="24"
|
||||||
:filters="{ordering: '-creation_date'}"
|
:filters="{ordering: '-creation_date'}"
|
||||||
>
|
>
|
||||||
</channels-widget>
|
</channels-widget>
|
||||||
|
|
Loading…
Reference in New Issue