repod/src/components/Discover/TopList.vue

96 lines
1.7 KiB
Vue
Raw Normal View History

2023-07-02 22:12:40 +00:00
<template>
2023-08-24 16:22:40 +00:00
<div>
2024-01-10 16:50:06 +00:00
<div>
<h2>{{ t('repod', 'Hot podcasts') }}</h2>
<Loading v-if="tops.hot.loading" />
<ul v-if="!tops.hot.loading">
<li v-for="top in tops.hot.items" :key="top.link">
<TopItem :author="top.author"
:image-url="top.imageUrl"
:link="top.link"
:title="top.title" />
</li>
</ul>
</div>
<div>
<h2>{{ t('repod', 'New podcasts') }}</h2>
<Loading v-if="tops.new.loading" />
<ul v-if="!tops.new.loading">
<li v-for="top in tops.new.items" :key="top.link">
<TopItem :author="top.author"
:image-url="top.imageUrl"
:link="top.link"
:title="top.title" />
</li>
</ul>
</div>
2023-08-24 16:22:40 +00:00
</div>
2023-07-02 22:12:40 +00:00
</template>
<script>
2023-12-23 21:49:23 +00:00
import Loading from '../Atoms/Loading.vue'
2023-07-25 20:07:35 +00:00
import TopItem from './TopItem.vue'
2023-07-02 22:12:40 +00:00
import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'
import { showError } from '@nextcloud/dialogs'
export default {
2023-07-25 20:07:35 +00:00
name: 'TopList',
2023-07-02 22:12:40 +00:00
components: {
2023-12-23 21:49:23 +00:00
Loading,
2023-07-25 20:07:35 +00:00
TopItem,
2023-07-02 22:12:40 +00:00
},
data() {
return {
2024-01-10 16:50:06 +00:00
tops: {
hot: {
items: [],
loading: true,
},
new: {
items: [],
loading: true,
},
},
2023-07-02 22:12:40 +00:00
}
},
async mounted() {
2024-01-10 16:50:06 +00:00
this.loadList('hot')
this.loadList('new')
},
methods: {
async loadList(type) {
try {
this.tops[type].loading = true
const toplist = await axios.get(generateUrl(`/apps/repod/toplist/${type}`))
this.tops[type].items = toplist.data
} catch (e) {
console.error(e)
showError(t('repod', 'Could not fetch tops'))
} finally {
this.tops[type].loading = false
}
},
2023-07-02 22:12:40 +00:00
},
}
</script>
<style scoped>
2024-01-10 16:50:06 +00:00
h2 {
margin: 1rem 0;
2023-08-24 16:22:40 +00:00
}
li {
2024-01-10 16:54:56 +00:00
flex-basis: 10rem;
2024-01-10 16:50:06 +00:00
flex-shrink: 0;
2023-08-23 15:54:09 +00:00
}
2023-08-24 16:22:40 +00:00
ul {
2023-07-02 22:12:40 +00:00
display: flex;
2024-01-10 16:50:06 +00:00
gap: 2rem;
overflow-x: auto;
overflow-y: hidden;
padding: .5rem;
2023-07-02 22:12:40 +00:00
}
</style>