From 07c58fc03ed43a926832ba85c9004d0f83eecfd5 Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Fri, 6 Sep 2019 15:45:56 +0200 Subject: [PATCH] Add emotions buttons, get it filtering --- backend/src/schema/types/type/EMOTED.gql | 32 ++-- backend/src/schema/types/type/Post.gql | 154 +++++++++--------- .../FilterPosts/CategoriesFilterMenuItems.vue | 2 +- .../FilterPosts/FilterPosts.spec.js | 1 + webapp/components/FilterPosts/FilterPosts.vue | 10 +- ...nuItems.vue => GeneralFilterMenuItems.vue} | 34 +++- webapp/pages/index.vue | 8 +- webapp/store/postsFilter.js | 16 ++ 8 files changed, 154 insertions(+), 103 deletions(-) rename webapp/components/FilterPosts/{FollowsFilterMenuItems.vue => GeneralFilterMenuItems.vue} (63%) diff --git a/backend/src/schema/types/type/EMOTED.gql b/backend/src/schema/types/type/EMOTED.gql index cb8d37d62..c41a75228 100644 --- a/backend/src/schema/types/type/EMOTED.gql +++ b/backend/src/schema/types/type/EMOTED.gql @@ -1,21 +1,27 @@ type EMOTED @relation(name: "EMOTED") { - from: User - to: Post + from: User + to: Post - emotion: Emotion - #createdAt: DateTime - #updatedAt: DateTime - createdAt: String - updatedAt: String + emotion: Emotion + # createdAt: DateTime + # updatedAt: DateTime + createdAt: String + updatedAt: String } input _EMOTEDInput { - emotion: Emotion - createdAt: String - updatedAt: String + emotion: Emotion + createdAt: String + updatedAt: String +} + +input _PostEMOTEDFilter { + emotion: Emotion + createdAt: String + updatedAt: String } type Mutation { - AddPostEmotions(to: _PostInput!, data: _EMOTEDInput!): EMOTED - RemovePostEmotions(to: _PostInput!, data: _EMOTEDInput!): EMOTED -} + AddPostEmotions(to: _PostInput!, data: _EMOTEDInput!): EMOTED + RemovePostEmotions(to: _PostInput!, data: _EMOTEDInput!): EMOTED +} \ No newline at end of file diff --git a/backend/src/schema/types/type/Post.gql b/backend/src/schema/types/type/Post.gql index 5b11757d3..5f0aeea7a 100644 --- a/backend/src/schema/types/type/Post.gql +++ b/backend/src/schema/types/type/Post.gql @@ -1,92 +1,92 @@ type Post { - id: ID! - activityId: String - objectId: String - author: User @relation(name: "WROTE", direction: "IN") - title: String! - slug: String - content: String! - contentExcerpt: String - image: String - imageUpload: Upload - visibility: Visibility - deleted: Boolean - disabled: Boolean - disabledBy: User @relation(name: "DISABLED", direction: "IN") - createdAt: String - updatedAt: String - language: String - relatedContributions: [Post]! - @cypher( - statement: """ - MATCH (this)-[:TAGGED|CATEGORIZED]->(categoryOrTag)<-[:TAGGED|CATEGORIZED]-(post:Post) - WHERE NOT post.deleted AND NOT post.disabled - RETURN DISTINCT post - LIMIT 10 - """ - ) + id: ID! + activityId: String + objectId: String + author: User @relation(name: "WROTE", direction: "IN") + title: String! + slug: String + content: String! + contentExcerpt: String + image: String + imageUpload: Upload + visibility: Visibility + deleted: Boolean + disabled: Boolean + disabledBy: User @relation(name: "DISABLED", direction: "IN") + createdAt: String + updatedAt: String + language: String + relatedContributions: [Post]! + @cypher( + statement: """ + MATCH (this)-[: TAGGED|CATEGORIZED]->(categoryOrTag)<-[: TAGGED|CATEGORIZED]-(post: Post) + WHERE NOT post.deleted AND NOT post.disabled + RETURN DISTINCT post + LIMIT 10 + """ + ) - tags: [Tag]! @relation(name: "TAGGED", direction: "OUT") - categories: [Category]! @relation(name: "CATEGORIZED", direction: "OUT") + tags: [Tag]! @relation(name: "TAGGED", direction: "OUT") + categories: [Category]! @relation(name: "CATEGORIZED", direction: "OUT") - comments: [Comment]! @relation(name: "COMMENTS", direction: "IN") - commentsCount: Int! - @cypher( - statement: "MATCH (this)<-[:COMMENTS]-(r:Comment) WHERE NOT r.deleted = true AND NOT r.disabled = true RETURN COUNT(DISTINCT r)" - ) + comments: [Comment]! @relation(name: "COMMENTS", direction: "IN") + commentsCount: Int! + @cypher( + statement: "MATCH (this)<-[: COMMENTS]-(r: Comment) WHERE NOT r.deleted = true AND NOT r.disabled = true RETURN COUNT(DISTINCT r)" + ) - shoutedBy: [User]! @relation(name: "SHOUTED", direction: "IN") - shoutedCount: Int! - @cypher( - statement: "MATCH (this)<-[:SHOUTED]-(r:User) WHERE NOT r.deleted = true AND NOT r.disabled = true RETURN COUNT(DISTINCT r)" - ) + shoutedBy: [User]! @relation(name: "SHOUTED", direction: "IN") + shoutedCount: Int! + @cypher( + statement: "MATCH (this)<-[: SHOUTED]-(r: User) WHERE NOT r.deleted = true AND NOT r.disabled = true RETURN COUNT(DISTINCT r)" + ) - # Has the currently logged in user shouted that post? - shoutedByCurrentUser: Boolean! - @cypher( - statement: "MATCH (this)<-[:SHOUTED]-(u:User {id: $cypherParams.currentUserId}) RETURN COUNT(u) >= 1" - ) + # Has the currently logged in user shouted that post? + shoutedByCurrentUser: Boolean! + @cypher( + statement: "MATCH (this)<-[: SHOUTED]-(u: User { id: $cypherParams.currentUserId}) RETURN COUNT(u) >= 1" + ) - emotions: [EMOTED] - emotionsCount: Int! - @cypher(statement: "MATCH (this)<-[emoted:EMOTED]-(:User) RETURN COUNT(DISTINCT emoted)") + emotions: [EMOTED] + emotionsCount: Int! + @cypher(statement: "MATCH (this)<-[emoted: EMOTED]-(: User) RETURN COUNT(DISTINCT emoted)") } input _PostInput { - id: ID! + id: ID! } type Mutation { - CreatePost( - id: ID - title: String! - slug: String - content: String! - image: String - imageUpload: Upload - visibility: Visibility - language: String - categoryIds: [ID] - contentExcerpt: String - ): Post - UpdatePost( - id: ID! - title: String! - slug: String - content: String! - contentExcerpt: String - image: String - imageUpload: Upload - visibility: Visibility - language: String - categoryIds: [ID] - ): Post - DeletePost(id: ID!): Post - AddPostEmotions(to: _PostInput!, data: _EMOTEDInput!): EMOTED - RemovePostEmotions(to: _PostInput!, data: _EMOTEDInput!): EMOTED + CreatePost( + id: ID + title: String! + slug: String + content: String! + image: String + imageUpload: Upload + visibility: Visibility + language: String + categoryIds: [ID] + contentExcerpt: String + ): Post + UpdatePost( + id: ID! + title: String! + slug: String + content: String! + contentExcerpt: String + image: String + imageUpload: Upload + visibility: Visibility + language: String + categoryIds: [ID] + ): Post + DeletePost(id: ID!): Post + AddPostEmotions(to: _PostInput!, data: _EMOTEDInput!): EMOTED + RemovePostEmotions(to: _PostInput!, data: _EMOTEDInput!): EMOTED } type Query { - PostsEmotionsCountByEmotion(postId: ID!, data: _EMOTEDInput!): Int! - PostsEmotionsByCurrentUser(postId: ID!): [String] -} + PostsEmotionsCountByEmotion(postId: ID!, data: _EMOTEDInput!): Int! + PostsEmotionsByCurrentUser(postId: ID!): [String] +} \ No newline at end of file diff --git a/webapp/components/FilterPosts/CategoriesFilterMenuItems.vue b/webapp/components/FilterPosts/CategoriesFilterMenuItems.vue index 59d17cb59..7a35bf3cc 100644 --- a/webapp/components/FilterPosts/CategoriesFilterMenuItems.vue +++ b/webapp/components/FilterPosts/CategoriesFilterMenuItems.vue @@ -1,5 +1,5 @@ @@ -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 + }, }