Skip to content

Commit

Permalink
Implement or move sort by date filter in filter menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Tirokk committed Apr 12, 2021
1 parent 90b9ffb commit 16d8a42
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 93 deletions.
2 changes: 2 additions & 0 deletions webapp/components/Dropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default {
data() {
return {
isPopoverOpen: false,
developperNoAutoClosing: true, // Wolle // stops automatic closing of menu for developper purposes: default is 'false'
}
},
computed: {
Expand Down Expand Up @@ -113,6 +114,7 @@ export default {
}
},
popoveMouseLeave() {
if (this.developperNoAutoClosing) return
if (this.disabled) {
return
}
Expand Down
56 changes: 56 additions & 0 deletions webapp/components/FilterMenu/DateSortFilter.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<template>
<filter-menu-section :divider="false" class="date-sort-filter">
<template #filter-list>
<!-- Wolle 👇🏼 translations & click
<labeled-button
icon="user-plus"
:label="$t('filter-menu.following')"
:filled="filteredByUsersFollowed"
:title="$t('contribution.filterFollow')"
@click="toggleFilteredByFollowed(currentUser.id)"
/> -->
<li class="item">
<labeled-button
icon="sort-amount-asc"
:label="'Newest first'"
:filled="orderBy === 'createdAt_desc'"
:title="'Sort posts by the newest first'"
@click="toggleOrder('createdAt_desc')"
/>
</li>
<li class="item">
<labeled-button
icon="sort-amount-desc"
:label="'Oldest first'"
:filled="orderBy === 'createdAt_asc'"
:title="'Sort posts by the oldest first'"
@click="toggleOrder('createdAt_asc')"
/>
</li>
</template>
</filter-menu-section>
</template>

<script>
import { mapGetters, mapMutations } from 'vuex'
import FilterMenuSection from '~/components/FilterMenu/FilterMenuSection'
import LabeledButton from '~/components/_new/generic/LabeledButton/LabeledButton'
export default {
name: 'DateSortFilter',
components: {
FilterMenuSection,
LabeledButton,
},
computed: {
...mapGetters({
orderBy: 'posts/orderBy',
}),
},
methods: {
...mapMutations({
toggleOrder: 'posts/TOGGLE_ORDER',
}),
},
}
</script>
6 changes: 6 additions & 0 deletions webapp/components/FilterMenu/FilterMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<h2 class="title">{{ $t('filter-menu.filter-by') }}</h2>
<following-filter />
</div>
<div class="filter-menu-options">
<h2 class="title">{{ 'Sorted by …' }}</h2> <!-- Wolle -->
<date-sort-filter />
</div>
</template>
</dropdown>
</template>
Expand All @@ -23,11 +27,13 @@
import Dropdown from '~/components/Dropdown'
import { mapGetters } from 'vuex'
import FollowingFilter from './FollowingFilter'
import DateSortFilter from './DateSortFilter'
export default {
components: {
Dropdown,
FollowingFilter,
DateSortFilter,
},
props: {
placement: { type: String },
Expand Down
13 changes: 8 additions & 5 deletions webapp/components/FilterMenu/FilterMenuSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ export default {
}
> .sidebar {
flex-basis: 12%;
display: flex;
flex-wrap: wrap;
flex-basis: 80%;
flex-grow: 1;
max-width: $size-width-filter-sidebar;
}
Expand All @@ -55,21 +58,21 @@ export default {
flex-grow: 1;
> .item {
width: 12.5%;
width: 50%;
padding: 0 $space-x-small;
margin-bottom: $space-small;
text-align: center;
@media only screen and (max-width: 800px) {
width: 16%;
width: 50%;
}
@media only screen and (max-width: 630px) {
width: 25%;
width: 40%;
}
@media only screen and (max-width: 440px) {
width: 50%;
width: 30%;
}
}
}
Expand Down
37 changes: 19 additions & 18 deletions webapp/pages/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,21 @@ describe('PostIndex', () => {
store = new Vuex.Store({
getters: {
'posts/filter': () => ({}),
'posts/orderOptions': () => () => [
{
key: 'store.posts.orderBy.oldest.label',
label: 'store.posts.orderBy.oldest.label',
icon: 'sort-amount-asc',
value: 'createdAt_asc',
},
{
key: 'store.posts.orderBy.newest.label',
label: 'store.posts.orderBy.newest.label',
icon: 'sort-amount-desc',
value: 'createdAt_desc',
},
],
// Wolle
// 'posts/orderOptions': () => () => [
// {
// key: 'store.posts.orderBy.oldest.label',
// label: 'store.posts.orderBy.oldest.label',
// icon: 'sort-amount-asc',
// value: 'createdAt_asc',
// },
// {
// key: 'store.posts.orderBy.newest.label',
// label: 'store.posts.orderBy.newest.label',
// icon: 'sort-amount-desc',
// value: 'createdAt_desc',
// },
// ],
'posts/selectedOrder': () => () => 'createdAt_desc',
'posts/orderIcon': () => 'sort-amount-desc',
'posts/orderBy': () => 'createdAt_desc',
Expand Down Expand Up @@ -119,10 +120,10 @@ describe('PostIndex', () => {
})
})

it('calls store when using order by menu', () => {
wrapper.findAll('li').at(0).trigger('click')
expect(mutations['posts/SELECT_ORDER']).toHaveBeenCalledWith({}, 'createdAt_asc')
})
// Wolle it('calls store when using order by menu', () => {
// wrapper.findAll('li').at(0).trigger('click')
// expect(mutations['posts/SELECT_ORDER']).toHaveBeenCalledWith({}, 'createdAt_asc')
// })
})
})
})
41 changes: 21 additions & 20 deletions webapp/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ import HcEmpty from '~/components/Empty/Empty'
import PostTeaser from '~/components/PostTeaser/PostTeaser.vue'
import MasonryGrid from '~/components/MasonryGrid/MasonryGrid.vue'
import MasonryGridItem from '~/components/MasonryGrid/MasonryGridItem.vue'
import { mapGetters, mapMutations } from 'vuex'
// Wolle import { mapGetters, mapMutations } from 'vuex'
import { mapGetters } from 'vuex'
import { filterPosts } from '~/graphql/PostQuery.js'
import UpdateQuery from '~/components/utils/UpdateQuery'
import links from '~/constants/links.js'
Expand Down Expand Up @@ -129,24 +130,24 @@ export default {
computed: {
...mapGetters({
postsFilter: 'posts/filter',
orderOptions: 'posts/orderOptions',
// Wolle care for the store !!! orderOptions: 'posts/orderOptions',
orderBy: 'posts/orderBy',
selectedOrder: 'posts/selectedOrder',
sortingIcon: 'posts/orderIcon',
// Wolle selectedOrder: 'posts/selectedOrder',
// Wolle sortingIcon: 'posts/orderIcon',
}),
selected: {
get() {
return this.selectedOrder(this)
},
set({ value }) {
this.offset = 0
this.posts = []
this.selectOrder(value)
},
},
sortingOptions() {
return this.orderOptions(this)
},
// Wolle selected: {
// get() {
// return this.selectedOrder(this)
// },
// set({ value }) {
// this.offset = 0
// this.posts = []
// this.selectOrder(value)
// },
// },
// Wolle sortingOptions() {
// return this.orderOptions(this)
// },
finalFilters() {
let filter = this.postsFilter
if (this.hashtag) {
Expand All @@ -163,9 +164,9 @@ export default {
},
watchQuery: ['hashtag'],
methods: {
...mapMutations({
selectOrder: 'posts/SELECT_ORDER',
}),
// Wolle ...mapMutations({
// selectOrder: 'posts/SELECT_ORDER',
// }),
clearSearch() {
this.$router.push({ path: '/' })
this.hashtag = null
Expand Down
49 changes: 26 additions & 23 deletions webapp/store/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,26 @@ import clone from 'lodash/clone'

const defaultFilter = {}

const orderOptions = {
createdAt_asc: {
value: 'createdAt_asc',
key: 'store.posts.orderBy.oldest.label',
icon: 'sort-amount-asc',
},
createdAt_desc: {
value: 'createdAt_desc',
key: 'store.posts.orderBy.newest.label',
icon: 'sort-amount-desc',
},
}
// Wolle const orderOptions = {
// createdAt_asc: {
// value: 'createdAt_asc',
// key: 'store.posts.orderBy.oldest.label',
// icon: 'sort-amount-asc',
// },
// createdAt_desc: {
// value: 'createdAt_desc',
// key: 'store.posts.orderBy.newest.label',
// icon: 'sort-amount-desc',
// },
// }

export const state = () => {
return {
filter: {
...defaultFilter,
},
order: orderOptions.createdAt_desc,
// Wolle order: orderOptions.createdAt_desc,
order: 'createdAt_desc',
}
}

Expand Down Expand Up @@ -76,8 +77,9 @@ export const mutations = {
if (isEmpty(get(filter, 'emotions_some.emotion_in'))) delete filter.emotions_some
state.filter = filter
},
SELECT_ORDER(state, value) {
state.order = orderOptions[value]
TOGGLE_ORDER(state, value) {
// Wolle state.order = orderOptions[value]
state.order = value
},
}

Expand All @@ -100,21 +102,22 @@ export const getters = {
filteredByEmotions(state) {
return get(state.filter, 'emotions_some.emotion_in') || []
},
orderOptions: (state) => ({ $t }) =>
Object.values(orderOptions).map((option) => {
return {
...option,
label: $t(option.key),
}
}),
// Wolle orderOptions: (state) => ({ $t }) =>
// Object.values(orderOptions).map((option) => {
// return {
// ...option,
// label: $t(option.key),
// }
// }),
selectedOrder: (state) => ({ $t }) => {
return {
...state.order,
label: $t(state.order.key),
}
},
orderBy(state) {
return state.order.value
// return state.order.value
return state.order
},
orderIcon(state) {
return state.order.icon
Expand Down
Loading

0 comments on commit 16d8a42

Please sign in to comment.