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>
<ul>
<NcAppNavigationNewItem :title="t('Add a RSS link')">
<NcAppNavigationNewItem :loading="loading"
:title="t('Add a RSS link')"
@new-item="addSubscription">
<template #icon>
<Plus :size="20" />
</template>
@ -11,6 +13,9 @@
<script>
import { NcAppNavigationNewItem } from '@nextcloud/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 {
name: 'AddRss',
@ -18,7 +23,27 @@ export default {
NcAppNavigationNewItem,
Plus,
},
data() {
return {
loading: false,
feedUrl: '',
}
},
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>

View File

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

View File

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