diff --git a/webapp/components/FilterMenu/PostTypeFilter.vue b/webapp/components/FilterMenu/PostTypeFilter.vue index 85916051c..db391a77a 100644 --- a/webapp/components/FilterMenu/PostTypeFilter.vue +++ b/webapp/components/FilterMenu/PostTypeFilter.vue @@ -11,7 +11,7 @@ :label="$t('filter-menu.all')" :filled="noneSetInPostTypeFilter" :title="$t('filter-menu.all')" - @click="setUnsetPostTypeFilter('All')" + @click="toggleSetUnsetPostTypeFilter('All')" />
  • @@ -20,7 +20,7 @@ :label="$t('filter-menu.article')" :filled="articleSetInPostTypeFilter" :title="$t('filter-menu.article')" - @click="setUnsetPostTypeFilter('Article')" + @click="toggleSetUnsetPostTypeFilter('Article')" />
  • @@ -29,7 +29,7 @@ :label="$t('filter-menu.event')" :filled="eventSetInPostTypeFilter" :title="$t('filter-menu.event')" - @click="setUnsetPostTypeFilter('Event')" + @click="toggleSetUnsetPostTypeFilter('Event')" />
  • diff --git a/webapp/mixins/filterMenuMixin.js b/webapp/mixins/filterMenuMixin.js index d481d374c..40429515d 100644 --- a/webapp/mixins/filterMenuMixin.js +++ b/webapp/mixins/filterMenuMixin.js @@ -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') - } - } - }, }, } diff --git a/webapp/store/posts.js b/webapp/store/posts.js index 5100120d9..4c213af92 100644 --- a/webapp/store/posts.js +++ b/webapp/store/posts.js @@ -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, }