Move filter by followers functionality to filter dropdown

This commit is contained in:
Matt Rider 2019-08-02 13:02:12 +02:00
parent fe91582b3e
commit afb9dbe241
5 changed files with 92 additions and 49 deletions

View File

@ -1,26 +1,6 @@
<template> <template>
<ds-card class="filter-menu-card"> <ds-card v-show="hashtag" class="filter-menu-card">
<ds-flex> <div>
<ds-flex-item class="filter-menu-title">
<ds-heading size="h3">{{ $t('filter-menu.title') }}</ds-heading>
</ds-flex-item>
<ds-flex-item>
<div class="filter-menu-buttons">
<ds-button
v-tooltip="{
content: this.$t('contribution.filterFollow'),
placement: 'left',
delay: { show: 500 },
}"
name="filter-by-followed-authors-only"
icon="user-plus"
:primary="!!filterAuthorIsFollowedById"
@click="toggleOnlyFollowed"
/>
</div>
</ds-flex-item>
</ds-flex>
<div v-if="hashtag">
<ds-space margin-bottom="x-small" /> <ds-space margin-bottom="x-small" />
<ds-flex> <ds-flex>
<ds-flex-item> <ds-flex-item>
@ -56,23 +36,7 @@ export default {
filter: {}, filter: {},
} }
}, },
computed: {
filterAuthorIsFollowedById() {
const { author = {} } = this.filter
/* eslint-disable camelcase */
const { followedBy_some = {} } = author
const { id } = followedBy_some
/* eslint-enable */
return id
},
},
methods: { methods: {
toggleOnlyFollowed() {
this.filter = this.filterAuthorIsFollowedById
? {}
: { author: { followedBy_some: { id: this.user.id } } }
this.$emit('changeFilterBubble', this.filter)
},
clearSearch() { clearSearch() {
this.$emit('clearSearch') this.$emit('clearSearch')
}, },

View File

@ -5,7 +5,7 @@
<ds-icon style="margin: 7px 0px 0px 2px" size="xx-small" name="angle-down" /> <ds-icon style="margin: 7px 0px 0px 2px" size="xx-small" name="angle-down" />
</a> </a>
<template slot="popover"> <template slot="popover">
<filter-posts-menu-items :chunk="chunk" @filterPosts="filterPosts" /> <filter-posts-menu-items :chunk="chunk" @filterPosts="filterPosts" :user="currentUser" />
</template> </template>
</dropdown> </dropdown>
</template> </template>
@ -13,7 +13,7 @@
import _ from 'lodash' import _ from 'lodash'
import Dropdown from '~/components/Dropdown' import Dropdown from '~/components/Dropdown'
import { filterPosts } from '~/graphql/PostQuery.js' import { filterPosts } from '~/graphql/PostQuery.js'
import { mapMutations } from 'vuex' import { mapGetters, mapMutations } from 'vuex'
import FilterPostsMenuItems from '~/components/FilterPosts/FilterPostsMenuItems' import FilterPostsMenuItems from '~/components/FilterPosts/FilterPostsMenuItems'
export default { export default {
@ -32,6 +32,9 @@ export default {
} }
}, },
computed: { computed: {
...mapGetters({
currentUser: 'auth/user',
}),
chunk() { chunk() {
return _.chunk(this.categories, 2) return _.chunk(this.categories, 2)
}, },
@ -40,8 +43,8 @@ export default {
...mapMutations({ ...mapMutations({
setPosts: 'posts/SET_POSTS', setPosts: 'posts/SET_POSTS',
}), }),
filterPosts(categoryIds) { filterPosts(filter) {
const filter = categoryIds.length ? { categories_some: { id_in: categoryIds } } : {} // const filter = categoryIds.length ? { categories_some: { id_in: categoryIds } } : {}
this.$apollo this.$apollo
.query({ .query({
query: filterPosts(this.$i18n), query: filterPosts(this.$i18n),

View File

@ -2,7 +2,7 @@
<ds-container> <ds-container>
<ds-space /> <ds-space />
<ds-flex id="filter-posts-header"> <ds-flex id="filter-posts-header">
<ds-heading tag="h4">{{ $t('filter-posts.header') }}</ds-heading> <ds-heading tag="h4">{{ $t('filter-posts.categories.header') }}</ds-heading>
<ds-space margin-bottom="large" /> <ds-space margin-bottom="large" />
</ds-flex> </ds-flex>
<ds-flex> <ds-flex>
@ -19,7 +19,7 @@
:primary="allCategories" :primary="allCategories"
/> />
<ds-flex-item> <ds-flex-item>
<label class="category-labels">{{ $t('filter-posts.all') }}</label> <label class="category-labels">{{ $t('filter-posts.categories.all') }}</label>
</ds-flex-item> </ds-flex-item>
<ds-space /> <ds-space />
</ds-flex-item> </ds-flex-item>
@ -55,17 +55,55 @@
</ds-flex> </ds-flex>
</ds-flex-item> </ds-flex-item>
</ds-flex> </ds-flex>
<ds-space />
<ds-flex id="filter-posts-by-followers-header">
<ds-heading tag="h4">
{{
filteredByFollowers ? $t('filter-posts.followers.header') : $t('filter-posts.all.header')
}}
</ds-heading>
<ds-space margin-bottom="large" />
</ds-flex>
<ds-flex>
<ds-flex-item
:width="{ base: '100%', sm: '100%', md: '100%', lg: '5%' }"
class="categories-menu-item"
>
<ds-flex>
<ds-flex-item width="10%" />
<ds-flex-item width="100%">
<div class="filter-menu-buttons">
<ds-button
v-tooltip="{
content: this.$t('contribution.filterFollow'),
placement: 'left',
delay: { show: 500 },
}"
name="filter-by-followed-authors-only"
icon="user-plus"
:primary="!filteredByFollowers"
@click="toggleOnlyFollowed"
/>
</div>
<ds-space margin-bottom="large" />
</ds-flex-item>
</ds-flex>
</ds-flex-item>
</ds-flex>
</ds-container> </ds-container>
</template> </template>
<script> <script>
export default { export default {
props: { props: {
user: { type: Object, required: true },
chunk: { type: Array, default: () => [] }, chunk: { type: Array, default: () => [] },
}, },
data() { data() {
return { return {
selectedCategoryIds: [], selectedCategoryIds: [],
allCategories: true, allCategories: true,
filter: {},
filteredByFollowers: false,
} }
}, },
methods: { methods: {
@ -89,7 +127,25 @@ export default {
} }
this.allCategories = false this.allCategories = false
} }
this.$emit('filterPosts', this.selectedCategoryIds) if (!this.selectedCategoryIds.length && this.filteredByFollowers) {
delete this.filter.categories_some
} else if (this.filter.author) {
this.filter.categories_some = { id_in: this.selectedCategoryIds }
} else {
this.filter = { categories_some: { followedBy_some: { id: this.user.id } } }
}
this.$emit('filterPosts', this.filter)
},
toggleOnlyFollowed() {
this.filteredByFollowers = !this.filteredByFollowers
if (!this.selectedCategoryIds.length && !this.filteredByFollowers) {
this.filter = {}
} else if (this.filter.categories_some) {
this.filter.author = { followedBy_some: { id: this.user.id } }
} else {
this.filter = { author: { followedBy_some: { id: this.user.id } } }
}
this.$emit('filterPosts', this.filter)
}, },
}, },
} }
@ -99,6 +155,10 @@ export default {
display: block; display: block;
} }
#filter-posts-by-followers-header {
display: block;
}
.categories-menu-item { .categories-menu-item {
text-align: center; text-align: center;
} }

View File

@ -5,8 +5,16 @@
"clearSearch": "Suche löschen" "clearSearch": "Suche löschen"
}, },
"filter-posts": { "filter-posts": {
"header": "Themenkategorien", "categories": {
"all": "Alle" "header": "Themenkategorien",
"all": "Alle"
},
"all": {
"header": "Alle Beiträge des Benutzers"
},
"followers": {
"header": "Die Beiträge meiner Anhänger"
}
}, },
"site": { "site": {
"made": "Mit &#10084; gemacht", "made": "Mit &#10084; gemacht",

View File

@ -5,8 +5,16 @@
"clearSearch": "Clear search" "clearSearch": "Clear search"
}, },
"filter-posts": { "filter-posts": {
"header": "Categories of Content", "categories": {
"all": "All" "header": "Categories of Content",
"all": "All"
},
"all": {
"header": "All user's contributions"
},
"followers": {
"header": "My followers contributions"
}
}, },
"site": { "site": {
"made": "Made with &#10084;", "made": "Made with &#10084;",