mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Merge pull request #699 from Human-Connection/269-filter_by_followed_users
269 filter by followed users
This commit is contained in:
commit
0d340ac190
@ -230,7 +230,7 @@ When('I type in the following text:', text => {
|
|||||||
|
|
||||||
Then('the post shows up on the landing page at position {int}', index => {
|
Then('the post shows up on the landing page at position {int}', index => {
|
||||||
cy.openPage('landing')
|
cy.openPage('landing')
|
||||||
const selector = `:nth-child(${index}) > .ds-card > .ds-card-content`
|
const selector = `.post-card:nth-child(${index}) > .ds-card-content`
|
||||||
cy.get(selector).should('contain', lastPost.title)
|
cy.get(selector).should('contain', lastPost.title)
|
||||||
cy.get(selector).should('contain', lastPost.content)
|
cy.get(selector).should('contain', lastPost.content)
|
||||||
})
|
})
|
||||||
|
|||||||
54
webapp/components/FilterMenu/FilterMenu.spec.js
Normal file
54
webapp/components/FilterMenu/FilterMenu.spec.js
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import { mount, createLocalVue } from '@vue/test-utils'
|
||||||
|
import FilterMenu from './FilterMenu.vue'
|
||||||
|
import Styleguide from '@human-connection/styleguide'
|
||||||
|
|
||||||
|
const localVue = createLocalVue()
|
||||||
|
|
||||||
|
localVue.use(Styleguide)
|
||||||
|
|
||||||
|
describe('FilterMenu.vue', () => {
|
||||||
|
let wrapper
|
||||||
|
let mocks
|
||||||
|
|
||||||
|
const createWrapper = mountMethod => {
|
||||||
|
return mountMethod(FilterMenu, {
|
||||||
|
mocks,
|
||||||
|
localVue,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
mocks = { $t: () => {} }
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('mount', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
wrapper = createWrapper(mount)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('renders a card', () => {
|
||||||
|
expect(wrapper.is('.ds-card')).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('click "filter-by-followed-authors-only" button', () => {
|
||||||
|
it('emits filterBubble object', () => {
|
||||||
|
wrapper.find({ name: 'filter-by-followed-authors-only' }).trigger('click')
|
||||||
|
expect(wrapper.emitted('changeFilterBubble')).toBeTruthy()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('toggles filterBubble.author property', () => {
|
||||||
|
wrapper.find({ name: 'filter-by-followed-authors-only' }).trigger('click')
|
||||||
|
expect(wrapper.emitted('changeFilterBubble')[0]).toEqual([{ author: 'following' }])
|
||||||
|
wrapper.find({ name: 'filter-by-followed-authors-only' }).trigger('click')
|
||||||
|
expect(wrapper.emitted('changeFilterBubble')[1]).toEqual([{ author: 'all' }])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('makes button primary', () => {
|
||||||
|
wrapper.find({ name: 'filter-by-followed-authors-only' }).trigger('click')
|
||||||
|
expect(
|
||||||
|
wrapper.find({ name: 'filter-by-followed-authors-only' }).classes('ds-button-primary'),
|
||||||
|
).toBe(true)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
57
webapp/components/FilterMenu/FilterMenu.vue
Normal file
57
webapp/components/FilterMenu/FilterMenu.vue
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<template>
|
||||||
|
<ds-card>
|
||||||
|
<ds-flex>
|
||||||
|
<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
|
||||||
|
name="filter-by-followed-authors-only"
|
||||||
|
icon="user-plus"
|
||||||
|
:primary="onlyFollowed"
|
||||||
|
@click="toggleOnlyFollowed"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</ds-flex-item>
|
||||||
|
</ds-flex>
|
||||||
|
</ds-card>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
// We have to fix styleguide here. It uses .includes wich will always be
|
||||||
|
// false for arrays of objects.
|
||||||
|
return {
|
||||||
|
filterBubble: {
|
||||||
|
author: 'all',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
onlyFollowed() {
|
||||||
|
return this.filterBubble.author === 'following'
|
||||||
|
},
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
toggleOnlyFollowed() {
|
||||||
|
this.filterBubble.author = this.onlyFollowed ? 'all' : 'following'
|
||||||
|
this.$emit('changeFilterBubble', this.filterBubble)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
.filter-menu-title {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter-menu-buttons {
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@ -1,4 +1,7 @@
|
|||||||
{
|
{
|
||||||
|
"filter-menu": {
|
||||||
|
"title": "Deine Filterblase"
|
||||||
|
},
|
||||||
"login": {
|
"login": {
|
||||||
"copy": "Wenn Du bereits ein Konto bei Human Connection hast, melde Dich bitte hier an.",
|
"copy": "Wenn Du bereits ein Konto bei Human Connection hast, melde Dich bitte hier an.",
|
||||||
"login": "Einloggen",
|
"login": "Einloggen",
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
{
|
{
|
||||||
|
"filter-menu": {
|
||||||
|
"title": "Your filter bubble"
|
||||||
|
},
|
||||||
"login": {
|
"login": {
|
||||||
"copy": "If you already have a human-connection account, login here.",
|
"copy": "If you already have a human-connection account, login here.",
|
||||||
"login": "Login",
|
"login": "Login",
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<ds-flex v-if="Post && Post.length" :width="{ base: '100%' }" gutter="base">
|
<ds-flex :width="{ base: '100%' }" gutter="base">
|
||||||
|
<ds-flex-item>
|
||||||
|
<filter-menu @changeFilterBubble="changeFilterBubble" />
|
||||||
|
</ds-flex-item>
|
||||||
<hc-post-card
|
<hc-post-card
|
||||||
v-for="(post, index) in uniq(Post)"
|
v-for="(post, index) in uniq(Post)"
|
||||||
:key="post.id"
|
:key="post.id"
|
||||||
@ -24,6 +27,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import FilterMenu from '~/components/FilterMenu/FilterMenu.vue'
|
||||||
import gql from 'graphql-tag'
|
import gql from 'graphql-tag'
|
||||||
import uniqBy from 'lodash/uniqBy'
|
import uniqBy from 'lodash/uniqBy'
|
||||||
import HcPostCard from '~/components/PostCard'
|
import HcPostCard from '~/components/PostCard'
|
||||||
@ -31,6 +35,7 @@ import HcLoadMore from '~/components/LoadMore.vue'
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
|
FilterMenu,
|
||||||
HcPostCard,
|
HcPostCard,
|
||||||
HcLoadMore,
|
HcLoadMore,
|
||||||
},
|
},
|
||||||
@ -40,6 +45,7 @@ export default {
|
|||||||
Post: [],
|
Post: [],
|
||||||
page: 1,
|
page: 1,
|
||||||
pageSize: 10,
|
pageSize: 10,
|
||||||
|
filterBubble: { author: 'all' },
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -51,6 +57,10 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
changeFilterBubble(filterBubble) {
|
||||||
|
this.filterBubble = filterBubble
|
||||||
|
this.$apollo.queries.Post.refresh()
|
||||||
|
},
|
||||||
uniq(items, field = 'id') {
|
uniq(items, field = 'id') {
|
||||||
return uniqBy(items, field)
|
return uniqBy(items, field)
|
||||||
},
|
},
|
||||||
@ -66,6 +76,7 @@ export default {
|
|||||||
this.page++
|
this.page++
|
||||||
this.$apollo.queries.Post.fetchMore({
|
this.$apollo.queries.Post.fetchMore({
|
||||||
variables: {
|
variables: {
|
||||||
|
filterBubble: this.filterBubble,
|
||||||
first: this.pageSize,
|
first: this.pageSize,
|
||||||
offset: this.offset,
|
offset: this.offset,
|
||||||
},
|
},
|
||||||
@ -91,8 +102,8 @@ export default {
|
|||||||
Post: {
|
Post: {
|
||||||
query() {
|
query() {
|
||||||
return gql(`
|
return gql(`
|
||||||
query Post($first: Int, $offset: Int) {
|
query Post($filterBubble: FilterBubble, $first: Int, $offset: Int) {
|
||||||
Post(first: $first, offset: $offset) {
|
Post(filterBubble: $filterBubble, first: $first, offset: $offset) {
|
||||||
id
|
id
|
||||||
title
|
title
|
||||||
contentExcerpt
|
contentExcerpt
|
||||||
@ -135,6 +146,7 @@ export default {
|
|||||||
},
|
},
|
||||||
variables() {
|
variables() {
|
||||||
return {
|
return {
|
||||||
|
filterBubble: this.filterBubble,
|
||||||
first: this.pageSize,
|
first: this.pageSize,
|
||||||
offset: 0,
|
offset: 0,
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user