Add ok
All checks were successful
repod / nextcloud (push) Successful in 1m4s
repod / nodejs (push) Successful in 2m21s

This commit is contained in:
Michel Roux 2023-07-09 00:07:21 +02:00
parent 1a9ae3c5c7
commit 96d300402b
3 changed files with 42 additions and 17 deletions

View File

@ -1,6 +1,8 @@
<template> <template>
<ul> <ul>
<NcAppNavigationNewItem :title="t('Add a RSS link')"> <NcAppNavigationNewItem :loading="loading"
:title="t('Add a RSS link')"
@new-item="addSubscription">
<template #icon> <template #icon>
<Plus :size="20" /> <Plus :size="20" />
</template> </template>
@ -11,6 +13,9 @@
<script> <script>
import { NcAppNavigationNewItem } from '@nextcloud/vue' import { NcAppNavigationNewItem } from '@nextcloud/vue'
import Plus from 'vue-material-design-icons/Plus.vue' import Plus from 'vue-material-design-icons/Plus.vue'
import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'
import { showError } from '@nextcloud/dialogs'
export default { export default {
name: 'AddRss', name: 'AddRss',
@ -18,7 +23,27 @@ export default {
NcAppNavigationNewItem, NcAppNavigationNewItem,
Plus, Plus,
}, },
data() {
return {
loading: false,
feedUrl: '',
}
},
methods: { methods: {
async addSubscription(feedUrl) {
this.loading = true
try {
await axios.post(generateUrl('/apps/gpoddersync/subscription_change/create'), { add: [feedUrl], remove: [] })
} catch (e) {
console.error(e)
showError(t('Error while adding the feed'))
}
this.loading = false
this.$store.dispatch('subscriptions/fetch')
},
}, },
} }
</script> </script>

View File

@ -13,6 +13,9 @@ export const subscriptions = {
}), }),
}, },
mutations: { mutations: {
reset: (state) => {
state.subscriptions = []
},
add: (state, subscription) => { add: (state, subscription) => {
const subscriptionId = state.subscriptions.findIndex(sub => sub.url === subscription.url) const subscriptionId = state.subscriptions.findIndex(sub => sub.url === subscription.url)
@ -22,13 +25,10 @@ export const subscriptions = {
state.subscriptions[subscriptionId] = subscription state.subscriptions[subscriptionId] = subscription
} }
}, },
delete: (state, subscription) => {
const subscriptionId = state.subscriptions.findIndex(sub => sub.url === subscription.url)
delete state.subscriptions[subscriptionId]
},
}, },
actions: { actions: {
fetchAll: async (context) => { fetch: async (context) => {
context.commit('reset')
const metrics = await axios.get(generateUrl('/apps/gpoddersync/personal_settings/metrics')) const metrics = await axios.get(generateUrl('/apps/gpoddersync/personal_settings/metrics'))
for (const subscriptionId in metrics.data.subscriptions) { for (const subscriptionId in metrics.data.subscriptions) {
context.commit('add', { context.commit('add', {
@ -38,15 +38,12 @@ export const subscriptions = {
}) })
} }
for (const subscription of context.state.subscriptions) { for (const subscription of context.state.subscriptions) {
context.dispatch('fetchMeta', subscription) try {
} const podcasts = await axios.get(generateUrl('/apps/gpoddersync/personal_settings/podcast_data?url={url}', { url: subscription.url }))
}, context.commit('add', { ...podcasts.data.data, ...subscription, ...{ loading: false } })
fetchMeta: async (context, subscription) => { } catch (e) {
try { console.error(e)
const podcasts = await axios.get(generateUrl('/apps/gpoddersync/personal_settings/podcast_data?url={url}', { url: subscription.url })) }
context.commit('add', { ...podcasts.data.data, ...subscription, ...{ loading: false } })
} catch (e) {
console.error(e)
} }
}, },
}, },

View File

@ -16,7 +16,10 @@
:loading="subscription.loading" :loading="subscription.loading"
:title="subscription.title ?? subscription.url"> :title="subscription.title ?? subscription.url">
<template #icon> <template #icon>
<img :src="subscription.imageUrl" alt=""> <img :src="subscription.imageUrl"
:alt="subscription.title"
width="20"
height="20">
</template> </template>
</NcAppNavigationItem> </NcAppNavigationItem>
</ul> </ul>
@ -63,7 +66,7 @@ export default {
}, },
async mounted() { async mounted() {
try { try {
await this.$store.dispatch('subscriptions/fetchAll') await this.$store.dispatch('subscriptions/fetch')
} catch (e) { } catch (e) {
console.error(e) console.error(e)
showError(t('Could not fetch subscriptions')) showError(t('Could not fetch subscriptions'))