Move all computed in file 'filterMenuMixin.js' to the store

This commit is contained in:
Wolfgang Huß 2023-06-01 18:00:41 +02:00
parent 9fee1b43c8
commit 52c474536f
2 changed files with 25 additions and 15 deletions

View File

@ -14,21 +14,13 @@ export default {
...mapGetters({
currentUser: 'auth/user',
filteredPostTypes: 'posts/filteredPostTypes',
noneSetInPostTypeFilter: 'posts/noneSetInPostTypeFilter',
articleSetInPostTypeFilter: 'posts/articleSetInPostTypeFilter',
eventSetInPostTypeFilter: 'posts/eventSetInPostTypeFilter',
orderedByCreationDate: 'posts/orderedByCreationDate',
eventsEnded: 'posts/eventsEnded',
orderBy: 'posts/orderBy',
}),
noneSetInPostTypeFilter() {
return !this.articleSetInPostTypeFilter && !this.eventSetInPostTypeFilter
},
articleSetInPostTypeFilter() {
return this.filteredPostTypes.includes('Article')
},
eventSetInPostTypeFilter() {
return this.filteredPostTypes.includes('Event')
},
orderedByCreationDate() {
return this.noneSetInPostTypeFilter || this.articleSetInPostTypeFilter
},
},
methods: {
...mapMutations({

View File

@ -7,6 +7,22 @@ import clone from 'lodash/clone'
const defaultFilter = {}
const filteredPostTypes = (state) => {
return get(state.filter, 'postType_in') || []
}
const noneSetInPostTypeFilter = (state) => {
return !articleSetInPostTypeFilter(state) && !eventSetInPostTypeFilter(state)
}
const articleSetInPostTypeFilter = (state) => {
return filteredPostTypes(state).includes('Article')
}
const eventSetInPostTypeFilter = (state) => {
return filteredPostTypes(state).includes('Event')
}
const orderedByCreationDate = (state) => {
return noneSetInPostTypeFilter(state) || articleSetInPostTypeFilter(state)
}
export const state = () => {
return {
filter: {
@ -100,9 +116,7 @@ export const getters = {
filteredCategoryIds(state) {
return get(state.filter, 'categories_some.id_in') || []
},
filteredPostTypes(state) {
return get(state.filter, 'postType_in') || []
},
filteredPostTypes,
filteredLanguageCodes(state) {
return get(state.filter, 'language_in') || []
},
@ -115,6 +129,10 @@ export const getters = {
filteredByEmotions(state) {
return get(state.filter, 'emotions_some.emotion_in') || []
},
noneSetInPostTypeFilter,
articleSetInPostTypeFilter,
eventSetInPostTypeFilter,
orderedByCreationDate,
eventsEnded(state) {
return state.eventsEnded
},