From ab84d9df15b00eb60df4eb6c2f39df34320a1f38 Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Mon, 10 Jul 2023 00:25:32 +0200 Subject: [PATCH] Rework subscriptionlistitem component --- src/components/SubscriptionListItem.vue | 54 +++++++++++++++++++++++++ src/modules/subscriptions.js | 36 ++--------------- src/views/Index.vue | 23 ++++------- 3 files changed, 65 insertions(+), 48 deletions(-) create mode 100644 src/components/SubscriptionListItem.vue diff --git a/src/components/SubscriptionListItem.vue b/src/components/SubscriptionListItem.vue new file mode 100644 index 0000000..3be7459 --- /dev/null +++ b/src/components/SubscriptionListItem.vue @@ -0,0 +1,54 @@ + + + diff --git a/src/modules/subscriptions.js b/src/modules/subscriptions.js index 0fcaced..aea5e1d 100644 --- a/src/modules/subscriptions.js +++ b/src/modules/subscriptions.js @@ -6,45 +6,15 @@ export const subscriptions = { state: { subscriptions: [], }, - getters: { - sortedSubscriptions: (state) => state.subscriptions.concat().sort((a, b) => { - if (a.title && b.title) return a.title.localeCompare(b.title) - return a.id - b.id - }), - }, mutations: { - reset: (state) => { - state.subscriptions = [] - }, - add: (state, subscription) => { - const subscriptionId = state.subscriptions.findIndex(sub => sub.url === subscription.url) - - if (subscriptionId === -1) { - state.subscriptions.push(subscription) - } else { - state.subscriptions[subscriptionId] = subscription - } + set: (state, subscriptions) => { + state.subscriptions = subscriptions }, }, actions: { 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', { - id: subscriptionId, - url: metrics.data.subscriptions[subscriptionId].url, - loading: true, - }) - } - for (const subscription of context.state.subscriptions) { - 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) - } - } + context.commit('set', metrics.data.subscriptions.map(sub => sub.url)) }, }, } diff --git a/src/views/Index.vue b/src/views/Index.vue index 08af296..f3228d7 100644 --- a/src/views/Index.vue +++ b/src/views/Index.vue @@ -11,17 +11,9 @@ @@ -36,11 +28,11 @@ import { NcAppContent, NcAppContentList, NcAppNavigation, - NcAppNavigationItem, NcAppNavigationNew, NcLoadingIcon, } from '@nextcloud/vue' import Plus from 'vue-material-design-icons/Plus.vue' +import SubscriptionListItem from '../components/SubscriptionListItem.vue' import { showError } from '@nextcloud/dialogs' export default { @@ -49,10 +41,10 @@ export default { NcAppContent, NcAppContentList, NcAppNavigation, - NcAppNavigationItem, NcAppNavigationNew, NcLoadingIcon, Plus, + SubscriptionListItem, }, data() { return { @@ -61,7 +53,7 @@ export default { }, computed: { subscriptions() { - return this.$store.getters['subscriptions/sortedSubscriptions'] + return this.$store.state.subscriptions.subscriptions }, }, async mounted() { @@ -70,8 +62,9 @@ export default { } catch (e) { console.error(e) showError(t('Could not fetch subscriptions')) + } finally { + this.loading = false } - this.loading = false }, }