RePod-Nextcloud-App/src/components/SubscriptionListItem.vue

80 lines
1.8 KiB
Vue
Raw Normal View History

2023-07-10 00:25:32 +02:00
<template>
<NcAppNavigationItem :loading="loading"
2023-07-29 17:53:51 +02:00
:title="feed ? feed.title : subscriptionUrl"
:to="`/${subscriptionUrl}`">
2023-07-10 00:25:32 +02:00
<template #icon>
2023-07-29 17:53:51 +02:00
<NcAvatar v-if="feed"
:display-name="feed.author"
:is-no-user="true"
:url="feed.imageUrl" />
2023-07-10 00:25:32 +02:00
<Alert v-if="failed" />
</template>
2023-07-25 22:19:16 +02:00
<template #actions>
<NcActionButton @click="deleteSubscription">
<template #icon>
<Delete :size="20" />
</template>
{{ t('Delete') }}
</NcActionButton>
</template>
2023-07-10 00:25:32 +02:00
</NcAppNavigationItem>
</template>
<script>
2023-07-29 17:53:51 +02:00
import { NcActionButton, NcAppNavigationItem, NcAvatar } from '@nextcloud/vue'
2023-07-10 00:25:32 +02:00
import Alert from 'vue-material-design-icons/Alert.vue'
2023-07-25 22:19:16 +02:00
import Delete from 'vue-material-design-icons/Delete.vue'
2023-07-10 00:25:32 +02:00
import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'
2023-07-25 22:19:16 +02:00
import { showError } from '@nextcloud/dialogs'
2023-07-10 00:25:32 +02:00
export default {
name: 'SubscriptionListItem',
components: {
Alert,
2023-07-25 22:19:16 +02:00
Delete,
NcActionButton,
2023-07-10 00:25:32 +02:00
NcAppNavigationItem,
2023-07-29 17:53:51 +02:00
NcAvatar,
2023-07-10 00:25:32 +02:00
},
props: {
subscriptionUrl: {
type: String,
required: true,
},
},
data() {
return {
failed: false,
loading: true,
2023-07-29 17:53:51 +02:00
feed: null,
2023-07-10 00:25:32 +02:00
}
},
async mounted() {
try {
const podcastData = await axios.get(generateUrl('/apps/gpoddersync/personal_settings/podcast_data?url={url}', { url: this.subscriptionUrl }))
2023-07-29 17:53:51 +02:00
this.feed = podcastData.data.data
2023-07-10 00:25:32 +02:00
} catch (e) {
this.failed = true
console.error(e)
} finally {
this.loading = false
}
},
2023-07-25 22:19:16 +02:00
methods: {
async deleteSubscription() {
try {
2023-07-28 01:52:48 +02:00
this.loading = true
2023-07-25 22:19:16 +02:00
await axios.post(generateUrl('/apps/gpoddersync/subscription_change/create'), { add: [], remove: [this.subscriptionUrl] })
} catch (e) {
console.error(e)
showError(t('Error while removing the feed'))
2023-07-28 01:52:48 +02:00
} finally {
this.loading = false
this.$store.dispatch('subscriptions/fetch')
2023-07-25 22:19:16 +02:00
}
},
},
2023-07-10 00:25:32 +02:00
}
</script>