From eb1196c841bfad61a893f8124a3303a235a2966c Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Thu, 22 Aug 2024 17:35:05 +0200 Subject: [PATCH] feat: :construction: wip on showing favorites --- src/components/Home/Episode.vue | 0 src/components/Home/Item.vue | 33 ++++++++++++++++++ src/components/Sidebar/Item.vue | 9 ++--- src/components/Sidebar/Subscriptions.vue | 15 +++++++-- src/store/subscriptions.js | 26 ++++++++++---- src/views/Home.vue | 43 +++++++++++++++++++----- 6 files changed, 106 insertions(+), 20 deletions(-) create mode 100644 src/components/Home/Episode.vue create mode 100644 src/components/Home/Item.vue diff --git a/src/components/Home/Episode.vue b/src/components/Home/Episode.vue new file mode 100644 index 0000000..e69de29 diff --git a/src/components/Home/Item.vue b/src/components/Home/Item.vue new file mode 100644 index 0000000..482e3ee --- /dev/null +++ b/src/components/Home/Item.vue @@ -0,0 +1,33 @@ + + + diff --git a/src/components/Sidebar/Item.vue b/src/components/Sidebar/Item.vue index f51c108..e1677f0 100644 --- a/src/components/Sidebar/Item.vue +++ b/src/components/Sidebar/Item.vue @@ -75,12 +75,12 @@ export default { feed: null, }), computed: { - ...mapState(useSubscriptions, ['favorites']), + ...mapState(useSubscriptions, ['favs']), hash() { return toUrl(this.url) }, isFavorite() { - return this.favorites.includes(this.url) + return this.favs.map((fav) => fav.url).includes(this.url) }, }, async mounted() { @@ -94,6 +94,7 @@ export default { ), ) this.feed = podcastData.data.data + this.editFavoriteData(this.url, podcastData.data.data) } catch (e) { this.failed = true console.error(e) @@ -102,7 +103,7 @@ export default { } }, methods: { - ...mapActions(useSubscriptions, ['fetch', 'addFavorite', 'removeFavorite']), + ...mapActions(useSubscriptions, ['fetch', 'addFavorite', 'editFavoriteData', 'removeFavorite']), async deleteSubscription() { if ( confirm( @@ -127,7 +128,7 @@ export default { }, switchFavorite(value) { if (value) { - if (this.favorites.length >= 10) { + if (this.favs.length >= 10) { showError(t('repod', 'You can only have 10 favorites')) return } diff --git a/src/components/Sidebar/Subscriptions.vue b/src/components/Sidebar/Subscriptions.vue index 182a826..747b708 100644 --- a/src/components/Sidebar/Subscriptions.vue +++ b/src/components/Sidebar/Subscriptions.vue @@ -11,7 +11,18 @@ - + + @@ -52,7 +63,7 @@ export default { loading: true, }), computed: { - ...mapState(useSubscriptions, ['subs']), + ...mapState(useSubscriptions, ['subs', 'favs']), }, async mounted() { try { diff --git a/src/store/subscriptions.js b/src/store/subscriptions.js index 757c6f2..231c42e 100644 --- a/src/store/subscriptions.js +++ b/src/store/subscriptions.js @@ -6,7 +6,7 @@ import { generateUrl } from '@nextcloud/router' export const useSubscriptions = defineStore('subscriptions', { state: () => ({ subs: [], - favorites: [], + favs: [], }), actions: { async fetch() { @@ -19,16 +19,30 @@ export const useSubscriptions = defineStore('subscriptions', { this.subs = subs.map((sub) => sub.url) try { - this.favorites = JSON.parse(getCookie('repod.favorites')) || [] + const favs = JSON.parse(getCookie('repod.favorites')) || [] + this.favs = favs.map((url) => ({ url })) } catch {} }, addFavorite(url) { - this.favorites.push(url) - setCookie('repod.favorites', JSON.stringify(this.favorites), 365) + this.favs.push({ url }) + setCookie( + 'repod.favorites', + JSON.stringify(this.favs.map((fav) => fav.url)), + 365, + ) + }, + editFavoriteData(url, data) { + this.favs = this.favs.map((fav) => + fav.url === url ? { ...fav, ...data } : fav, + ) }, removeFavorite(url) { - this.favorites = this.favorites.filter((favorite) => favorite !== url) - setCookie('repod.favorites', JSON.stringify(this.favorites), 365) + this.favs = this.favs.filter((fav) => fav.url !== url) + setCookie( + 'repod.favorites', + JSON.stringify(this.favs.map((fav) => fav.url)), + 365, + ) }, }, }) diff --git a/src/views/Home.vue b/src/views/Home.vue index ff4dd43..55caa5b 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -1,23 +1,50 @@ + +