perf: write getters for accessible filtered cookies values
All checks were successful
repod / xml (push) Successful in 1m36s
repod / php (push) Successful in 59s
repod / nodejs (push) Successful in 1m34s
repod / release (push) Has been skipped

This commit is contained in:
Michel Roux 2024-09-02 10:51:48 +02:00
parent 437c7868dd
commit 7b7ceef503
7 changed files with 28 additions and 22 deletions

View File

@ -19,7 +19,7 @@
</template> </template>
<template #actions> <template #actions>
<NcActionButton <NcActionButton
v-if="!subs.includes(feed.link)" v-if="!getSubscriptions.includes(feed.link)"
:aria-label="t('repod', 'Subscribe')" :aria-label="t('repod', 'Subscribe')"
:name="t('repod', 'Subscribe')" :name="t('repod', 'Subscribe')"
:title="t('repod', 'Subscribe')" :title="t('repod', 'Subscribe')"
@ -67,7 +67,7 @@ export default {
loading: false, loading: false,
}), }),
computed: { computed: {
...mapState(useSubscriptions, ['subs']), ...mapState(useSubscriptions, ['getSubscriptions']),
}, },
watch: { watch: {
value() { value() {

View File

@ -23,7 +23,7 @@
<SafeHtml :source="description" /> <SafeHtml :source="description" />
</div> </div>
<NcAppNavigationNew <NcAppNavigationNew
v-if="!subs.includes(url)" v-if="!getSubscriptions.includes(url)"
:text="t('repod', 'Subscribe')" :text="t('repod', 'Subscribe')"
@click="addSubscription"> @click="addSubscription">
<template #icon> <template #icon>
@ -79,7 +79,7 @@ export default {
}, },
}, },
computed: { computed: {
...mapState(useSubscriptions, ['subs']), ...mapState(useSubscriptions, ['getSubscriptions']),
url() { url() {
return decodeUrl(this.$route.params.url) return decodeUrl(this.$route.params.url)
}, },

View File

@ -53,9 +53,9 @@ export default {
loading: true, loading: true,
}), }),
computed: { computed: {
...mapState(useSubscriptions, ['favs']), ...mapState(useSubscriptions, ['getFavorites']),
currentFavoriteData() { currentFavoriteData() {
return this.favs.find((fav) => fav.url === this.url) return this.getFavorites.find((fav) => fav.url === this.url)
}, },
}, },
async mounted() { async mounted() {

View File

@ -75,9 +75,9 @@ export default {
feed: null, feed: null,
}), }),
computed: { computed: {
...mapState(useSubscriptions, ['favs']), ...mapState(useSubscriptions, ['getFavorites']),
isFavorite() { isFavorite() {
return this.favs.map((fav) => fav.url).includes(this.url) return this.getFavorites.map((fav) => fav.url).includes(this.url)
}, },
}, },
async mounted() { async mounted() {
@ -131,7 +131,7 @@ export default {
}, },
switchFavorite(value) { switchFavorite(value) {
if (value) { if (value) {
if (this.favs.length >= 10) { if (this.getFavorites.length >= 10) {
showError(t('repod', 'You can only have 10 favorites')) showError(t('repod', 'You can only have 10 favorites'))
return return
} }

View File

@ -12,15 +12,13 @@
<Loading v-if="loading" /> <Loading v-if="loading" />
<NcAppNavigationList v-if="!loading"> <NcAppNavigationList v-if="!loading">
<Subscription <Subscription
v-for="url of favs v-for="url of getFavorites.map((fav) => fav.url)"
.sort((fav) => fav.lastPub)
.map((fav) => fav.url)
.filter((url) => subs.includes(url))"
:key="url" :key="url"
:url="url" /> :url="url" />
<Subscription <Subscription
v-for="url of subs.filter( v-for="url of getSubscriptions.filter(
(sub) => !favs.map((fav) => fav.url).includes(sub), (sub) =>
!getFavorites.map((fav) => fav.url).includes(sub),
)" )"
:key="url" :key="url"
:url="url" /> :url="url" />
@ -64,7 +62,7 @@ export default {
loading: true, loading: true,
}), }),
computed: { computed: {
...mapState(useSubscriptions, ['subs', 'favs']), ...mapState(useSubscriptions, ['getSubscriptions', 'getFavorites']),
}, },
async mounted() { async mounted() {
try { try {

View File

@ -8,6 +8,16 @@ export const useSubscriptions = defineStore('subscriptions', {
subs: [], subs: [],
favs: [], favs: [],
}), }),
getters: {
getSubscriptions: (state) => {
return state.subs
},
getFavorites: (state) => {
return state.favs
.filter((fav) => state.subs.includes(fav.url))
.sort((fav) => fav.lastPub)
},
},
actions: { actions: {
async fetch() { async fetch() {
const metrics = await axios.get( const metrics = await axios.get(

View File

@ -1,7 +1,7 @@
<template> <template>
<AppContent> <AppContent>
<EmptyContent <EmptyContent
v-if="!favs.length" v-if="!getFavorites.length"
class="empty" class="empty"
:description=" :description="
t('repod', 'Pin some subscriptions to see their latest updates') t('repod', 'Pin some subscriptions to see their latest updates')
@ -11,10 +11,8 @@
<StarOffIcon :size="20" /> <StarOffIcon :size="20" />
</template> </template>
</EmptyContent> </EmptyContent>
<ul v-if="favs.length"> <ul v-if="getFavorites.length">
<li <li v-for="url in getFavorites.map((fav) => fav.url)" :key="url">
v-for="url in favs.sort((fav) => fav.lastPub).map((fav) => fav.url)"
:key="url">
<Favorites :url="url" /> <Favorites :url="url" />
</li> </li>
</ul> </ul>
@ -38,7 +36,7 @@ export default {
StarOffIcon, StarOffIcon,
}, },
computed: { computed: {
...mapState(useSubscriptions, ['favs']), ...mapState(useSubscriptions, ['getFavorites']),
}, },
} }
</script> </script>