repod/src/components/Top.vue

94 lines
1.6 KiB
Vue
Raw Normal View History

2023-07-02 22:12:40 +00:00
<template>
<fragment>
2023-07-03 06:42:00 +00:00
<p class="more">
2023-07-03 15:30:09 +00:00
<span>{{ t('Discover') }}</span>
2023-07-03 06:42:00 +00:00
<NcButton v-if="showMore" @click="more">
2023-07-03 15:30:09 +00:00
{{ t('More') }}
2023-07-03 06:42:00 +00:00
</NcButton>
</p>
2023-07-02 22:12:40 +00:00
<p>
<NcLoadingIcon v-if="loading" />
<ul v-if="!loading" class="tops">
<li v-for="top in tops.feed.results" :key="top.id">
<img :src="top.artworkUrl100" :alt="top.artistName" :title="top.artistName">
</li>
</ul>
2023-07-03 15:30:09 +00:00
<span class="caption">{{ t('Suggests by iTunes') }}</span>
2023-07-02 22:12:40 +00:00
</p>
</fragment>
</template>
<script>
import { NcButton, NcLoadingIcon } from '@nextcloud/vue'
import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'
import { showError } from '@nextcloud/dialogs'
export default {
name: 'Top',
components: {
NcButton,
NcLoadingIcon,
},
data() {
return {
tops: [],
loading: true,
showMore: true,
}
},
async mounted() {
await this.fetch(10)
},
methods: {
async more() {
this.showMore = false
await this.fetch(50)
},
async fetch(limit) {
this.loading = true
try {
const top = await axios.get(generateUrl('/apps/repod/top/{limit}', { limit }))
this.tops = top.data
} catch (e) {
console.error(e)
2023-07-03 15:30:09 +00:00
showError(t('Could not fetch tops'))
2023-07-02 22:12:40 +00:00
}
this.loading = false
},
},
}
</script>
<style scoped>
.tops {
display: flex;
flex-wrap: wrap;
gap: 2rem 5%;
justify-content: center;
}
.tops li {
flex-basis: 15%;
}
.tops li img {
height: 100%;
width: 100%;
}
2023-07-03 06:42:00 +00:00
.more {
display: flex;
justify-content: space-between;
align-items: center;
}
.caption {
float: right;
font-size: small;
margin: .5rem;
}
2023-07-02 22:12:40 +00:00
</style>