2022-06-11 22:00:57 +00:00
|
|
|
<script setup lang="ts">
|
|
|
|
import axios from 'axios'
|
|
|
|
import $ from 'jquery'
|
|
|
|
|
|
|
|
import RadioCard from '~/components/radios/Card.vue'
|
|
|
|
import Pagination from '~/components/vui/Pagination.vue'
|
|
|
|
import useLogger from '~/composables/useLogger'
|
|
|
|
import useSharedLabels from '~/composables/locale/useSharedLabels'
|
|
|
|
import { OrderingField } from '~/store/ui'
|
|
|
|
import { computed, ref, watch } from 'vue'
|
|
|
|
import { useGettext } from 'vue3-gettext'
|
|
|
|
import { useStore } from '~/store'
|
|
|
|
import { onBeforeRouteUpdate, useRouter } from 'vue-router'
|
|
|
|
import useOrdering, { OrderingProps } from '~/composables/useOrdering'
|
|
|
|
|
|
|
|
interface Props extends OrderingProps {
|
|
|
|
defaultPage?: number
|
|
|
|
defaultPaginateBy?: number
|
|
|
|
|
|
|
|
defaultQuery?: string
|
|
|
|
scope?: string
|
|
|
|
}
|
|
|
|
|
|
|
|
const props = withDefaults(defineProps<Props>(), {
|
|
|
|
defaultPage: 1,
|
|
|
|
defaultPaginateBy: 1,
|
|
|
|
defaultQuery: '',
|
|
|
|
scope: 'all'
|
|
|
|
})
|
|
|
|
|
|
|
|
// TODO (wvffle): Make sure everything is it's own type
|
|
|
|
const page = ref(+props.defaultPage)
|
|
|
|
type ResponseType = { count: number, results: any[] }
|
|
|
|
const result = ref<null | ResponseType>(null)
|
|
|
|
const query = ref(props.defaultQuery)
|
|
|
|
|
|
|
|
const orderingOptions: [OrderingField, keyof typeof sharedLabels.filters][] = [
|
|
|
|
['creation_date', 'creation_date'],
|
|
|
|
['name', 'name']
|
|
|
|
]
|
|
|
|
|
|
|
|
const logger = useLogger()
|
|
|
|
const sharedLabels = useSharedLabels()
|
|
|
|
|
2022-06-25 22:06:30 +00:00
|
|
|
const { onOrderingUpdate, orderingString, paginateBy, ordering, orderingDirection } = useOrdering(props.orderingConfigName, props.defaultPaginateBy)
|
2022-06-11 22:00:57 +00:00
|
|
|
|
|
|
|
const router = useRouter()
|
|
|
|
const updateQueryString = () => router.replace({
|
|
|
|
query: {
|
|
|
|
query: query.value,
|
|
|
|
page: page.value,
|
|
|
|
paginateBy: paginateBy.value,
|
|
|
|
ordering: orderingString.value
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
watch(page, updateQueryString)
|
|
|
|
onOrderingUpdate(updateQueryString)
|
|
|
|
|
|
|
|
const isLoading = ref(false)
|
|
|
|
const fetchData = async () => {
|
|
|
|
isLoading.value = true
|
|
|
|
const params = {
|
|
|
|
scope: props.scope,
|
|
|
|
page: page.value,
|
|
|
|
page_size: paginateBy.value,
|
|
|
|
name__icontains: query.value,
|
|
|
|
ordering: orderingString.value
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.time('Fetching radios')
|
|
|
|
try {
|
|
|
|
const response = await axios.get('radios/radios/', {
|
|
|
|
params
|
|
|
|
// TODO (wvffle): Check if params should be serialized. In other similar components (Podcasts, Artists) they are
|
|
|
|
// paramsSerializer: function (params) {
|
|
|
|
// return qs.stringify(params, { indices: false })
|
|
|
|
// }
|
|
|
|
})
|
|
|
|
|
|
|
|
result.value = response.data
|
|
|
|
} catch (error) {
|
|
|
|
// TODO (wvffle): Handle error
|
|
|
|
result.value = null
|
|
|
|
} finally {
|
|
|
|
logger.timeEnd('Fetching radios')
|
|
|
|
isLoading.value = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const store = useStore()
|
|
|
|
const isAuthenticated = computed(() => store.state.auth.authenticated)
|
|
|
|
const hasFavorites = computed(() => store.state.favorites.count > 0)
|
|
|
|
|
|
|
|
onBeforeRouteUpdate(fetchData)
|
|
|
|
fetchData()
|
|
|
|
|
|
|
|
// @ts-expect-error semantic ui
|
|
|
|
onMounted(() => $('.ui.dropdown').dropdown())
|
|
|
|
|
|
|
|
const { $pgettext } = useGettext()
|
|
|
|
const labels = computed(() => ({
|
|
|
|
searchPlaceholder: $pgettext('Content/Search/Input.Placeholder', 'Enter a radio name…'),
|
|
|
|
title: $pgettext('*/*/*', 'Radios')
|
|
|
|
}))
|
|
|
|
</script>
|
|
|
|
|
2018-01-07 21:13:44 +00:00
|
|
|
<template>
|
2018-11-19 22:33:22 +00:00
|
|
|
<main v-title="labels.title">
|
|
|
|
<section class="ui vertical stripe segment">
|
2018-06-30 13:28:47 +00:00
|
|
|
<h2 class="ui header">
|
2021-12-06 10:35:20 +00:00
|
|
|
<translate translate-context="Content/Radio/Title">
|
|
|
|
Browsing radios
|
|
|
|
</translate>
|
2018-06-30 13:28:47 +00:00
|
|
|
</h2>
|
2021-12-06 10:35:20 +00:00
|
|
|
<div class="ui hidden divider" />
|
2018-07-17 11:09:13 +00:00
|
|
|
<div class="ui row">
|
|
|
|
<h3 class="ui header">
|
2021-12-06 10:35:20 +00:00
|
|
|
<translate translate-context="Content/Radio/Title">
|
|
|
|
Instance radios
|
|
|
|
</translate>
|
2018-07-17 11:09:13 +00:00
|
|
|
</h3>
|
|
|
|
<div class="ui cards">
|
2021-12-06 10:35:20 +00:00
|
|
|
<radio-card
|
|
|
|
v-if="isAuthenticated"
|
|
|
|
:type="'actor-content'"
|
|
|
|
:object-id="$store.state.auth.fullUsername"
|
|
|
|
/>
|
|
|
|
<radio-card
|
|
|
|
v-if="isAuthenticated && hasFavorites"
|
|
|
|
:type="'favorites'"
|
|
|
|
/>
|
|
|
|
<radio-card :type="'random'" />
|
|
|
|
<radio-card :type="'recently-added'" />
|
|
|
|
<radio-card
|
|
|
|
v-if="$store.state.auth.authenticated"
|
|
|
|
:type="'less-listened'"
|
|
|
|
/>
|
2018-07-17 11:09:13 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2021-12-06 10:35:20 +00:00
|
|
|
<div class="ui hidden divider" />
|
2018-07-17 11:09:13 +00:00
|
|
|
<h3 class="ui header">
|
2021-12-06 10:35:20 +00:00
|
|
|
<translate translate-context="Content/Radio/Title">
|
|
|
|
User radios
|
|
|
|
</translate>
|
2018-07-17 11:09:13 +00:00
|
|
|
</h3>
|
2021-12-06 10:35:20 +00:00
|
|
|
<router-link
|
2022-03-04 14:37:59 +00:00
|
|
|
v-if="isAuthenticated"
|
2021-12-06 10:35:20 +00:00
|
|
|
class="ui success button"
|
|
|
|
to="/library/radios/build"
|
|
|
|
>
|
|
|
|
<translate translate-context="Content/Radio/Button.Label/Verb">
|
|
|
|
Create your own radio
|
|
|
|
</translate>
|
2018-04-15 10:45:56 +00:00
|
|
|
</router-link>
|
2021-12-06 10:35:20 +00:00
|
|
|
<div class="ui hidden divider" />
|
|
|
|
<form
|
|
|
|
:class="['ui', {'loading': isLoading}, 'form']"
|
2022-06-11 22:00:57 +00:00
|
|
|
@submit.prevent="page = props.defaultPage"
|
2021-12-06 10:35:20 +00:00
|
|
|
>
|
2018-01-07 21:13:44 +00:00
|
|
|
<div class="fields">
|
|
|
|
<div class="field">
|
2020-08-01 09:11:51 +00:00
|
|
|
<label for="radios-search"><translate translate-context="Content/Search/Input.Label/Noun">Search</translate></label>
|
2020-07-06 11:21:07 +00:00
|
|
|
<div class="ui action input">
|
2021-12-06 10:35:20 +00:00
|
|
|
<input
|
|
|
|
id="radios-search"
|
|
|
|
v-model="query"
|
|
|
|
type="text"
|
|
|
|
name="search"
|
|
|
|
:placeholder="labels.searchPlaceholder"
|
|
|
|
>
|
|
|
|
<button
|
|
|
|
class="ui icon button"
|
|
|
|
type="submit"
|
|
|
|
:aria-label="$pgettext('Content/Search/Input.Label/Noun', 'Search')"
|
|
|
|
>
|
|
|
|
<i class="search icon" />
|
2020-07-06 11:21:07 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
2018-01-07 21:13:44 +00:00
|
|
|
</div>
|
|
|
|
<div class="field">
|
2020-08-01 09:11:51 +00:00
|
|
|
<label for="radios-ordering"><translate translate-context="Content/Search/Dropdown.Label/Noun">Ordering</translate></label>
|
2021-12-06 10:35:20 +00:00
|
|
|
<select
|
|
|
|
id="radios-ordering"
|
|
|
|
v-model="ordering"
|
|
|
|
class="ui dropdown"
|
|
|
|
>
|
|
|
|
<option
|
|
|
|
v-for="(option, key) in orderingOptions"
|
|
|
|
:key="key"
|
|
|
|
:value="option[0]"
|
|
|
|
>
|
2018-10-05 17:31:30 +00:00
|
|
|
{{ sharedLabels.filters[option[1]] }}
|
2018-01-07 21:13:44 +00:00
|
|
|
</option>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<div class="field">
|
2020-08-01 09:11:51 +00:00
|
|
|
<label for="radios-ordering-direction"><translate translate-context="Content/Search/Dropdown.Label/Noun">Order</translate></label>
|
2021-12-06 10:35:20 +00:00
|
|
|
<select
|
|
|
|
id="radios-ordering-direction"
|
|
|
|
v-model="orderingDirection"
|
|
|
|
class="ui dropdown"
|
|
|
|
>
|
2018-06-30 13:28:47 +00:00
|
|
|
<option value="+">
|
2021-12-06 10:35:20 +00:00
|
|
|
<translate translate-context="Content/Search/Dropdown">
|
|
|
|
Ascending
|
|
|
|
</translate>
|
2018-06-30 13:28:47 +00:00
|
|
|
</option>
|
|
|
|
<option value="-">
|
2021-12-06 10:35:20 +00:00
|
|
|
<translate translate-context="Content/Search/Dropdown">
|
|
|
|
Descending
|
|
|
|
</translate>
|
2018-06-30 13:28:47 +00:00
|
|
|
</option>
|
2018-01-07 21:13:44 +00:00
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<div class="field">
|
2020-08-01 09:11:51 +00:00
|
|
|
<label for="radios-results"><translate translate-context="Content/Search/Dropdown.Label/Noun">Results per page</translate></label>
|
2021-12-06 10:35:20 +00:00
|
|
|
<select
|
|
|
|
id="radios-results"
|
|
|
|
v-model="paginateBy"
|
|
|
|
class="ui dropdown"
|
|
|
|
>
|
2022-06-11 22:00:57 +00:00
|
|
|
<option :value="12">
|
2021-12-06 10:35:20 +00:00
|
|
|
12
|
|
|
|
</option>
|
2022-06-11 22:00:57 +00:00
|
|
|
<option :value="25">
|
2021-12-06 10:35:20 +00:00
|
|
|
25
|
|
|
|
</option>
|
2022-06-11 22:00:57 +00:00
|
|
|
<option :value="50">
|
2021-12-06 10:35:20 +00:00
|
|
|
50
|
|
|
|
</option>
|
2018-01-07 21:13:44 +00:00
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-07-06 11:21:07 +00:00
|
|
|
</form>
|
2021-12-06 10:35:20 +00:00
|
|
|
<div class="ui hidden divider" />
|
|
|
|
<div
|
|
|
|
v-if="result && !result.results.length > 0"
|
|
|
|
class="ui placeholder segment"
|
|
|
|
>
|
2019-10-17 12:15:33 +00:00
|
|
|
<div class="ui icon header">
|
2021-12-06 10:35:20 +00:00
|
|
|
<i class="feed icon" />
|
2019-10-17 12:15:33 +00:00
|
|
|
<translate translate-context="Content/Radios/Placeholder">
|
|
|
|
No results matching your query
|
|
|
|
</translate>
|
|
|
|
</div>
|
|
|
|
<router-link
|
2021-12-06 10:35:20 +00:00
|
|
|
v-if="$store.state.auth.authenticated"
|
|
|
|
:to="{name: 'library.radios.build'}"
|
|
|
|
class="ui success button labeled icon"
|
|
|
|
>
|
|
|
|
<i class="rss icon" />
|
2019-10-17 12:15:33 +00:00
|
|
|
<translate translate-context="Content/*/Verb">
|
|
|
|
Create a radio
|
|
|
|
</translate>
|
|
|
|
</router-link>
|
|
|
|
</div>
|
2018-02-26 19:10:35 +00:00
|
|
|
<div
|
2020-05-07 16:33:58 +00:00
|
|
|
v-if="result && result.results.length > 0"
|
2021-12-06 10:35:20 +00:00
|
|
|
class="ui cards"
|
|
|
|
>
|
2020-05-07 16:33:58 +00:00
|
|
|
<radio-card
|
|
|
|
v-for="radio in result.results"
|
|
|
|
:key="radio.id"
|
2021-12-06 10:35:20 +00:00
|
|
|
type="custom"
|
|
|
|
:custom-radio="radio"
|
|
|
|
/>
|
2018-01-07 21:13:44 +00:00
|
|
|
</div>
|
|
|
|
<div class="ui center aligned basic segment">
|
|
|
|
<pagination
|
2018-07-11 17:15:03 +00:00
|
|
|
v-if="result && result.count > paginateBy"
|
2022-06-11 22:00:57 +00:00
|
|
|
v-model:current="page"
|
2018-01-07 21:13:44 +00:00
|
|
|
:paginate-by="paginateBy"
|
|
|
|
:total="result.count"
|
2021-12-06 10:35:20 +00:00
|
|
|
/>
|
2018-01-07 21:13:44 +00:00
|
|
|
</div>
|
2018-11-19 22:33:22 +00:00
|
|
|
</section>
|
|
|
|
</main>
|
2018-01-07 21:13:44 +00:00
|
|
|
</template>
|