Move 'setUnsetPostTypeFilter' to the store

This commit is contained in:
Wolfgang Huß 2023-06-01 19:27:13 +02:00
parent 52839f4b22
commit 7687d6f28c
3 changed files with 28 additions and 90 deletions

View File

@ -11,7 +11,7 @@
:label="$t('filter-menu.all')"
:filled="noneSetInPostTypeFilter"
:title="$t('filter-menu.all')"
@click="setUnsetPostTypeFilter('All')"
@click="toggleSetUnsetPostTypeFilter('All')"
/>
</li>
<li class="item article-item">
@ -20,7 +20,7 @@
:label="$t('filter-menu.article')"
:filled="articleSetInPostTypeFilter"
:title="$t('filter-menu.article')"
@click="setUnsetPostTypeFilter('Article')"
@click="toggleSetUnsetPostTypeFilter('Article')"
/>
</li>
<li class="item event-item">
@ -29,7 +29,7 @@
:label="$t('filter-menu.event')"
:filled="eventSetInPostTypeFilter"
:title="$t('filter-menu.event')"
@click="setUnsetPostTypeFilter('Event')"
@click="toggleSetUnsetPostTypeFilter('Event')"
/>
</li>
</template>

View File

@ -1,15 +1,6 @@
import { mapGetters, mapMutations } from 'vuex'
export default {
data() {
return {
filterPostTypes: ['Article', 'Event'],
orderByTypes: {
creationDate: ['createdAt_asc', 'createdAt_desc'],
startDate: ['eventStart_asc', 'eventStart_desc'],
},
}
},
computed: {
...mapGetters({
currentUser: 'auth/user',
@ -26,67 +17,15 @@ export default {
...mapMutations({
toggleFilterPostType: 'posts/TOGGLE_POST_TYPE',
toggleUnsetAllPostTypeFilters: 'posts/TOGGLE_UNSET_ALL_POST_TYPES_FILTERS',
toggleSetUnsetPostTypeFilter: 'posts/TOGGLE_SET_UNSET_POST_TYPE_FILTER',
toggleEventsEnded: 'posts/TOGGLE_EVENTS_ENDED',
toggleOrder: 'posts/TOGGLE_ORDER',
}),
// Wolle
// unsetAllPostTypeFilters() {
// const beforeEventSetInPostTypeFilter = this.eventSetInPostTypeFilter
// this.filterPostTypes.forEach((postType) => {
// if (this.filteredPostTypes.includes(postType)) this.toggleFilterPostType(postType)
// })
// this.adjustEventsEnded(beforeEventSetInPostTypeFilter)
// this.adjustOrder()
// },
setUnsetPostTypeFilter(setPostType) {
const beforeEventSetInPostTypeFilter = this.eventSetInPostTypeFilter
if (this.noneSetInPostTypeFilter) {
if (setPostType !== 'All') this.toggleFilterPostType(setPostType)
} else {
if (setPostType !== 'All') {
if (this.filteredPostTypes.includes(setPostType)) {
this.toggleUnsetAllPostTypeFilters()
} else {
// if 'setPostType' is not set then set it and unset all others
this.toggleFilterPostType(setPostType)
this.filterPostTypes.forEach((postType) => {
if (postType !== setPostType && this.filteredPostTypes.includes(postType))
this.toggleFilterPostType(postType)
})
}
} else {
this.toggleUnsetAllPostTypeFilters()
}
}
this.adjustEventsEnded(beforeEventSetInPostTypeFilter)
this.adjustOrder()
},
setEventsEnded(newEventsEnded) {
this.toggleEventsEnded(newEventsEnded)
},
setOrder(newOrder) {
this.toggleOrder(newOrder)
},
// Wolle
adjustEventsEnded(beforeEventSetInPostTypeFilter) {
if (this.eventSetInPostTypeFilter !== beforeEventSetInPostTypeFilter) {
if (this.eventSetInPostTypeFilter) {
this.setEventsEnded('eventStart_gte')
} else {
this.setEventsEnded('')
}
}
},
adjustOrder() {
if (this.orderedByCreationDate) {
if (!this.orderByTypes.creationDate.includes(this.orderBy)) {
this.setOrder('createdAt_desc')
}
} else {
if (!this.orderByTypes.startDate.includes(this.orderBy)) {
this.setOrder('eventStart_asc')
}
}
},
},
}

View File

@ -28,8 +28,6 @@ const TOGGLE_POST_TYPE = (state, postType) => {
if (isEmpty(get(filter, 'postType_in'))) delete filter.postType_in
state.filter = filter
}
// Wolle
const TOGGLE_UNSET_ALL_POST_TYPES_FILTERS = (state) => {
const beforeEventSetInPostTypeFilter = eventSetInPostTypeFilter(state)
filterPostTypes.forEach((postType) => {
@ -38,29 +36,29 @@ const TOGGLE_UNSET_ALL_POST_TYPES_FILTERS = (state) => {
adjustEventsEnded(state, beforeEventSetInPostTypeFilter)
adjustOrder(state)
}
// const setUnsetPostTypeFilter = (state, setPostType) => {
// const beforeEventSetInPostTypeFilter = this.eventSetInPostTypeFilter
// if (this.noneSetInPostTypeFilter) {
// if (setPostType !== 'All') this.toggleFilterPostType(setPostType)
// } else {
// if (setPostType !== 'All') {
// if (this.filteredPostTypes.includes(setPostType)) {
// TOGGLE_UNSET_ALL_POST_TYPES_FILTERS(state)
// } else {
// // if 'setPostType' is not set then set it and unset all others
// this.toggleFilterPostType(setPostType)
// this.filterPostTypes.forEach((postType) => {
// if (postType !== setPostType && this.filteredPostTypes.includes(postType))
// this.toggleFilterPostType(postType)
// })
// }
// } else {
// TOGGLE_UNSET_ALL_POST_TYPES_FILTERS(state)
// }
// }
// this.adjustEventsEnded(beforeEventSetInPostTypeFilter)
// this.adjustOrder()
// }
const TOGGLE_SET_UNSET_POST_TYPE_FILTER = (state, setPostType) => {
const beforeEventSetInPostTypeFilter = eventSetInPostTypeFilter(state)
if (noneSetInPostTypeFilter(state)) {
if (setPostType !== 'All') TOGGLE_POST_TYPE(state, setPostType)
} else {
if (setPostType !== 'All') {
if (filteredPostTypes(state).includes(setPostType)) {
TOGGLE_UNSET_ALL_POST_TYPES_FILTERS(state)
} else {
// if 'setPostType' is not set then set it and unset all others
TOGGLE_POST_TYPE(state, setPostType)
filterPostTypes.forEach((postType) => {
if (postType !== setPostType && filteredPostTypes(state).includes(postType))
TOGGLE_POST_TYPE(state, postType)
})
}
} else {
TOGGLE_UNSET_ALL_POST_TYPES_FILTERS(state)
}
}
adjustEventsEnded(state, beforeEventSetInPostTypeFilter)
adjustOrder(state)
}
const TOGGLE_EVENTS_ENDED = (state, value) => {
state.eventsEnded = value
}
@ -168,6 +166,7 @@ export const mutations = {
},
TOGGLE_POST_TYPE,
TOGGLE_UNSET_ALL_POST_TYPES_FILTERS,
TOGGLE_SET_UNSET_POST_TYPE_FILTER,
TOGGLE_EVENTS_ENDED,
TOGGLE_ORDER,
}