From 8a3bd6b770084ded3233745a41d9532cb78faa10 Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Thu, 5 Sep 2019 16:00:28 +0200 Subject: [PATCH 01/14] Extract categories filter into own component - Co-authored-by: Brent Vardy - Co-authored-by: Mike Aono - Co-authored-by: Harald --- .../FilterPosts/CategoriesFilters.vue | 101 ++++++++++++++++++ .../FilterPosts/FilterPostsMenuItems.vue | 90 +--------------- 2 files changed, 106 insertions(+), 85 deletions(-) create mode 100644 webapp/components/FilterPosts/CategoriesFilters.vue diff --git a/webapp/components/FilterPosts/CategoriesFilters.vue b/webapp/components/FilterPosts/CategoriesFilters.vue new file mode 100644 index 000000000..59d17cb59 --- /dev/null +++ b/webapp/components/FilterPosts/CategoriesFilters.vue @@ -0,0 +1,101 @@ + + + diff --git a/webapp/components/FilterPosts/FilterPostsMenuItems.vue b/webapp/components/FilterPosts/FilterPostsMenuItems.vue index c761070b7..4c39b3fe7 100644 --- a/webapp/components/FilterPosts/FilterPostsMenuItems.vue +++ b/webapp/components/FilterPosts/FilterPostsMenuItems.vue @@ -1,62 +1,6 @@ @@ -72,4 +100,8 @@ export default { float: left; } } + +.text-center { + text-align: center; +} diff --git a/webapp/pages/index.vue b/webapp/pages/index.vue index 09270f936..03be67575 100644 --- a/webapp/pages/index.vue +++ b/webapp/pages/index.vue @@ -27,12 +27,8 @@ diff --git a/webapp/store/postsFilter.js b/webapp/store/postsFilter.js index 487194bae..0c3cef25d 100644 --- a/webapp/store/postsFilter.js +++ b/webapp/store/postsFilter.js @@ -40,6 +40,19 @@ export const mutations = { if (isEmpty(get(filter, 'categories_some.id_in'))) delete filter.categories_some state.filter = filter }, + TOGGLE_FILTER_BY_EMOTIONS(state, emotion) { + const filter = clone(state.filter) + const emotionName = get(filter, 'emotions_in.emotions') + if (emotionName) { + delete filter.emotions_in + state.filter = filter + } else { + state.filter = { + ...filter, + emotions_in: { emotion: emotion }, + } + } + }, } export const getters = { @@ -55,4 +68,7 @@ export const getters = { filteredByUsersFollowed(state) { return !!get(state.filter, 'author.followedBy_some.id') }, + filteredByEmotions: state => emotion => { + return get(state.filter, 'emotions_in.emotion') === emotion + }, } From 30ea892aa128b2fad1a33498a15385ab5c600080 Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Sat, 7 Sep 2019 12:31:21 +0200 Subject: [PATCH 04/14] Allow filter by multiple emotions, test getters - Co-authored-by: vardyb - Co-aurhored-by: mike aono --- backend/src/schema/types/type/EMOTED.gql | 2 +- .../FilterPosts/FilterPosts.spec.js | 2 +- .../FilterPosts/GeneralFilterMenuItems.vue | 6 ++--- webapp/store/postsFilter.js | 17 ++++--------- webapp/store/postsFilter.spec.js | 24 +++++++++++++++++++ 5 files changed, 34 insertions(+), 17 deletions(-) diff --git a/backend/src/schema/types/type/EMOTED.gql b/backend/src/schema/types/type/EMOTED.gql index c41a75228..cefb26f21 100644 --- a/backend/src/schema/types/type/EMOTED.gql +++ b/backend/src/schema/types/type/EMOTED.gql @@ -16,7 +16,7 @@ input _EMOTEDInput { } input _PostEMOTEDFilter { - emotion: Emotion + emotion_in: [Emotion] createdAt: String updatedAt: String } diff --git a/webapp/components/FilterPosts/FilterPosts.spec.js b/webapp/components/FilterPosts/FilterPosts.spec.js index 75991c4e5..c0ad56843 100644 --- a/webapp/components/FilterPosts/FilterPosts.spec.js +++ b/webapp/components/FilterPosts/FilterPosts.spec.js @@ -61,7 +61,7 @@ describe('FilterPosts.vue', () => { }, 'postsFilter/filteredCategoryIds': jest.fn(() => []), 'postsFilter/filteredByUsersFollowed': jest.fn(), - 'postsFilter/filteredByEmotions': jest.fn(() => jest.fn()), + 'postsFilter/filteredByEmotions': jest.fn(() => []), } const openFilterPosts = () => { const store = new Vuex.Store({ mutations, getters }) diff --git a/webapp/components/FilterPosts/GeneralFilterMenuItems.vue b/webapp/components/FilterPosts/GeneralFilterMenuItems.vue index 8e79ee622..4dd79591a 100644 --- a/webapp/components/FilterPosts/GeneralFilterMenuItems.vue +++ b/webapp/components/FilterPosts/GeneralFilterMenuItems.vue @@ -32,7 +32,7 @@ -
+
xor(emotions, [emotion])) + if (isEmpty(get(filter, 'emotions_some.emotion_in'))) delete filter.emotions_some + state.filter = filter }, } @@ -68,7 +61,7 @@ export const getters = { filteredByUsersFollowed(state) { return !!get(state.filter, 'author.followedBy_some.id') }, - filteredByEmotions: state => emotion => { - return get(state.filter, 'emotions_in.emotion') === emotion + filteredByEmotions(state) { + return get(state.filter, 'emotions_some.emotion_in') || [] }, } diff --git a/webapp/store/postsFilter.spec.js b/webapp/store/postsFilter.spec.js index f06b4a31d..68a3dbd6e 100644 --- a/webapp/store/postsFilter.spec.js +++ b/webapp/store/postsFilter.spec.js @@ -43,6 +43,30 @@ describe('getters', () => { expect(getters.filteredByUsersFollowed(state)).toBe(false) }) }) + + describe('filteredByEmotions', () => { + it('returns an emotions array if filter is set', () => { + state = { filter: { emotions_some: { emotion_in: ['sad'] } } } + expect(getters.filteredByEmotions(state)).toEqual(['sad']) + }) + + it('returns an emotions array even when other filters are set', () => { + state = { + filter: { emotions_some: { emotion_in: ['sad'] }, categories_some: { id_in: [23] } }, + } + expect(getters.filteredByEmotions(state)).toEqual(['sad']) + }) + + it('returns empty array if filter is not set', () => { + state = { filter: {} } + expect(getters.filteredByEmotions(state)).toEqual([]) + }) + + it('returns empty array if another filter is set, but not emotions', () => { + state = { filter: { categories_some: { id_in: [23] } } } + expect(getters.filteredByEmotions(state)).toEqual([]) + }) + }) }) describe('mutations', () => { From a63e132b419b31f0208d67c9a8c547b7c67564fd Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Thu, 5 Sep 2019 16:00:28 +0200 Subject: [PATCH 05/14] Extract categories filter into own component - Co-authored-by: Brent Vardy - Co-authored-by: Mike Aono - Co-authored-by: Harald --- .../FilterPosts/CategoriesFilterMenuItems.vue | 104 +++++++----------- .../FilterPosts/CategoriesFilters.vue | 101 +++++++++++++++++ 2 files changed, 143 insertions(+), 62 deletions(-) create mode 100644 webapp/components/FilterPosts/CategoriesFilters.vue diff --git a/webapp/components/FilterPosts/CategoriesFilterMenuItems.vue b/webapp/components/FilterPosts/CategoriesFilterMenuItems.vue index 7a35bf3cc..7b683276b 100644 --- a/webapp/components/FilterPosts/CategoriesFilterMenuItems.vue +++ b/webapp/components/FilterPosts/CategoriesFilterMenuItems.vue @@ -1,101 +1,81 @@ diff --git a/webapp/components/FilterPosts/CategoriesFilters.vue b/webapp/components/FilterPosts/CategoriesFilters.vue new file mode 100644 index 000000000..59d17cb59 --- /dev/null +++ b/webapp/components/FilterPosts/CategoriesFilters.vue @@ -0,0 +1,101 @@ + + + From 3b5c02e2762127d207c11782a50b62fbd1f46257 Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Fri, 6 Sep 2019 13:37:22 +0200 Subject: [PATCH 06/14] Extract FollowsFilterMenuItems - remove now unnecessary FilterPostsMenuItems --- .../FilterPosts/CategoriesFilterMenuItems.vue | 104 +++++++++++------- .../FilterPosts/CategoriesFilters.vue | 101 ----------------- .../FilterPosts/FollowsFilterMenuItems.vue | 75 +++++++++++++ 3 files changed, 137 insertions(+), 143 deletions(-) delete mode 100644 webapp/components/FilterPosts/CategoriesFilters.vue create mode 100644 webapp/components/FilterPosts/FollowsFilterMenuItems.vue diff --git a/webapp/components/FilterPosts/CategoriesFilterMenuItems.vue b/webapp/components/FilterPosts/CategoriesFilterMenuItems.vue index 7b683276b..15fcba9f0 100644 --- a/webapp/components/FilterPosts/CategoriesFilterMenuItems.vue +++ b/webapp/components/FilterPosts/CategoriesFilterMenuItems.vue @@ -1,81 +1,101 @@ diff --git a/webapp/components/FilterPosts/CategoriesFilters.vue b/webapp/components/FilterPosts/CategoriesFilters.vue deleted file mode 100644 index 59d17cb59..000000000 --- a/webapp/components/FilterPosts/CategoriesFilters.vue +++ /dev/null @@ -1,101 +0,0 @@ - - - diff --git a/webapp/components/FilterPosts/FollowsFilterMenuItems.vue b/webapp/components/FilterPosts/FollowsFilterMenuItems.vue new file mode 100644 index 000000000..6e83f79c7 --- /dev/null +++ b/webapp/components/FilterPosts/FollowsFilterMenuItems.vue @@ -0,0 +1,75 @@ + + + From 079864a7a97abdcaf7934e342de4d92930c1d172 Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Fri, 6 Sep 2019 15:45:56 +0200 Subject: [PATCH 07/14] Add emotions buttons, get it filtering --- .../FilterPosts/CategoriesFilterMenuItems.vue | 2 +- .../FilterPosts/FollowsFilterMenuItems.vue | 75 ------------------- 2 files changed, 1 insertion(+), 76 deletions(-) delete mode 100644 webapp/components/FilterPosts/FollowsFilterMenuItems.vue diff --git a/webapp/components/FilterPosts/CategoriesFilterMenuItems.vue b/webapp/components/FilterPosts/CategoriesFilterMenuItems.vue index 15fcba9f0..eb51153a6 100644 --- a/webapp/components/FilterPosts/CategoriesFilterMenuItems.vue +++ b/webapp/components/FilterPosts/CategoriesFilterMenuItems.vue @@ -1,5 +1,5 @@