diff --git a/backend/src/schema/resolvers/users.js b/backend/src/schema/resolvers/users.js index 74561c5fe..4710942b6 100644 --- a/backend/src/schema/resolvers/users.js +++ b/backend/src/schema/resolvers/users.js @@ -151,7 +151,6 @@ export default { friendsCount: '<-[:FRIENDS]->(related:User)', followingCount: '-[:FOLLOWS]->(related:User)', followedByCount: '<-[:FOLLOWS]-(related:User)', - commentsCount: '-[:WROTE]->(r:Comment)', commentedCount: '-[:WROTE]->(:Comment)-[:COMMENTS]->(related:Post)', shoutedCount: '-[:SHOUTED]->(related:Post)', badgesCount: '<-[:REWARDED]-(related:Badge)', diff --git a/backend/src/schema/types/type/Post.gql b/backend/src/schema/types/type/Post.gql index 519af14ae..cbbcddfc9 100644 --- a/backend/src/schema/types/type/Post.gql +++ b/backend/src/schema/types/type/Post.gql @@ -29,11 +29,6 @@ type Post { 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(r)" - ) - shoutedBy: [User]! @relation(name: "SHOUTED", direction: "IN") shoutedCount: Int! @cypher( diff --git a/backend/src/schema/types/type/User.gql b/backend/src/schema/types/type/User.gql index e3e8f8450..46e699410 100644 --- a/backend/src/schema/types/type/User.gql +++ b/backend/src/schema/types/type/User.gql @@ -64,7 +64,6 @@ type User { ) comments: [Comment]! @relation(name: "WROTE", direction: "OUT") - commentsCount: Int! @cypher(statement: "MATCH (this)-[:WROTE]->(r:Comment) WHERE NOT r.deleted = true AND NOT r.disabled = true RETURN COUNT(r)") commentedCount: Int! @cypher(statement: "MATCH (this)-[:WROTE]->(r:Comment)-[:COMMENTS]->(p:Post) WHERE NOT r.deleted = true AND NOT r.disabled = true AND NOT p.deleted = true AND NOT p.disabled = true RETURN COUNT(DISTINCT(p))") shouted: [Post]! @relation(name: "SHOUTED", direction: "OUT") @@ -143,7 +142,6 @@ type Query { followedByCount: Int followedByCurrentUser: Boolean contributionsCount: Int - commentsCount: Int commentedCount: Int shoutedCount: Int badgesCount: Int diff --git a/cypress/integration/common/steps.js b/cypress/integration/common/steps.js index 25c87d600..7192b097b 100644 --- a/cypress/integration/common/steps.js +++ b/cypress/integration/common/steps.js @@ -260,7 +260,7 @@ Then("the first post on the landing page has the title:", title => { Then( "the page {string} returns a 404 error with a message:", (route, message) => { - // TODO: how can we check HTTP codes with cypress? + cy.request({ url: route, failOnStatusCode: false }).its('status').should('eq', 404) cy.visit(route, { failOnStatusCode: false }); cy.get(".error").should("contain", message); } diff --git a/webapp/components/Comment.vue b/webapp/components/Comment.vue index 9d273cca9..6d3b05eff 100644 --- a/webapp/components/Comment.vue +++ b/webapp/components/Comment.vue @@ -67,7 +67,7 @@ import { mapGetters, mapMutations } from 'vuex' import HcUser from '~/components/User' import ContentMenu from '~/components/ContentMenu' import ContentViewer from '~/components/Editor/ContentViewer' -import HcEditCommentForm from '~/components/comments/EditCommentForm/EditCommentForm' +import HcEditCommentForm from '~/components/EditCommentForm/EditCommentForm' export default { data: function() { diff --git a/webapp/components/comments/CommentForm/CommentForm.spec.js b/webapp/components/CommentForm/CommentForm.spec.js similarity index 98% rename from webapp/components/comments/CommentForm/CommentForm.spec.js rename to webapp/components/CommentForm/CommentForm.spec.js index 5cc274ce2..07069e2d5 100644 --- a/webapp/components/comments/CommentForm/CommentForm.spec.js +++ b/webapp/components/CommentForm/CommentForm.spec.js @@ -1,5 +1,5 @@ import { mount, createLocalVue } from '@vue/test-utils' -import CommentForm from './CommentForm.vue' +import CommentForm from './CommentForm' import Styleguide from '@human-connection/styleguide' import Vuex from 'vuex' import MutationObserver from 'mutation-observer' diff --git a/webapp/components/comments/CommentForm/CommentForm.vue b/webapp/components/CommentForm/CommentForm.vue similarity index 89% rename from webapp/components/comments/CommentForm/CommentForm.vue rename to webapp/components/CommentForm/CommentForm.vue index d863a7e4d..823b47fa6 100644 --- a/webapp/components/comments/CommentForm/CommentForm.vue +++ b/webapp/components/CommentForm/CommentForm.vue @@ -30,10 +30,10 @@ diff --git a/webapp/components/CountTo.vue b/webapp/components/CountTo.vue index 65ad84b56..3210944c8 100644 --- a/webapp/components/CountTo.vue +++ b/webapp/components/CountTo.vue @@ -20,7 +20,7 @@ export default { }, props: { startVal: { type: Number, default: 0 }, - endVal: { type: Number, required: true }, + endVal: { type: Number, default: 0 }, duration: { type: Number, default: 3000 }, autoplay: { type: Boolean, default: true }, separator: { type: String, default: '.' }, diff --git a/webapp/components/DeleteData/DeleteData.spec.js b/webapp/components/DeleteData/DeleteData.spec.js index 139316ed2..73ca985fa 100644 --- a/webapp/components/DeleteData/DeleteData.spec.js +++ b/webapp/components/DeleteData/DeleteData.spec.js @@ -48,7 +48,7 @@ describe('DeleteData.vue', () => { } getters = { 'auth/user': () => { - return { id: 'u343', name: deleteAccountName, contributionsCount: 2, commentsCount: 3 } + return { id: 'u343', name: deleteAccountName, contributionsCount: 2, commentedCount: 3 } }, } actions = { 'auth/logout': jest.fn() } diff --git a/webapp/components/DeleteData/DeleteData.vue b/webapp/components/DeleteData/DeleteData.vue index 293e65221..f6e6d47f0 100644 --- a/webapp/components/DeleteData/DeleteData.vue +++ b/webapp/components/DeleteData/DeleteData.vue @@ -30,12 +30,12 @@ }} - @@ -44,7 +44,7 @@ uppercase > - + @@ -58,7 +58,7 @@ uppercase > - + @@ -72,7 +72,7 @@ uppercase > - + @@ -81,7 +81,7 @@ - + @@ -90,7 +90,7 @@ - + @@ -99,7 +99,7 @@ - + diff --git a/webapp/pages/index.vue b/webapp/pages/index.vue index 7566ce791..e8d68a561 100644 --- a/webapp/pages/index.vue +++ b/webapp/pages/index.vue @@ -96,7 +96,7 @@ export default { label: this.$t('sorting.commented'), value: 'Commented', icons: 'comment', - order: 'commentsCount_desc', + order: 'commentedCount_desc', }, ], } diff --git a/webapp/pages/post/_id/_slug/index.vue b/webapp/pages/post/_id/_slug/index.vue index 0a3a2ef38..1a7e84789 100644 --- a/webapp/pages/post/_id/_slug/index.vue +++ b/webapp/pages/post/_id/_slug/index.vue @@ -81,10 +81,10 @@ import HcTag from '~/components/Tag' import ContentMenu from '~/components/ContentMenu' import HcUser from '~/components/User' import HcShoutButton from '~/components/ShoutButton.vue' -import HcCommentForm from '~/components/comments/CommentForm/CommentForm' -import HcCommentList from '~/components/comments/CommentList' +import HcCommentForm from '~/components/CommentForm/CommentForm' +import HcCommentList from '~/components/CommentList/CommentList' import { postMenuModalsData, deletePostMutation } from '~/components/utils/PostHelpers' -import PostQuery from '~/graphql/PostQuery.js' +import PostQuery from '~/graphql/PostQuery' import HcEmotions from '~/components/Emotions/Emotions' export default { @@ -122,29 +122,6 @@ export default { this.title = this.post.title }, }, - async asyncData(context) { - const { - params, - error, - app: { apolloProvider, $i18n }, - } = context - const client = apolloProvider.defaultClient - const query = PostQuery($i18n) - const variables = { slug: params.slug } - const { - data: { Post }, - } = await client.query({ query, variables }) - if (Post.length <= 0) { - // TODO: custom 404 error page with translations - const message = 'This post could not be found' - return error({ statusCode: 404, message }) - } - const [post] = Post - return { - post, - title: post.title, - } - }, mounted() { setTimeout(() => { // NOTE: quick fix for jumping flexbox implementation @@ -175,6 +152,19 @@ export default { } }, }, + apollo: { + Post: { + query() { + return PostQuery(this.$i18n) + }, + variables() { + return { + slug: this.$route.params.slug, + } + }, + fetchPolicy: 'cache-and-network', + }, + }, } @@ -187,7 +177,6 @@ export default { } .post-card { - // max-width: 800px; margin: auto; .comments { diff --git a/webapp/pages/post/_id/_slug/more-info.vue b/webapp/pages/post/_id/_slug/more-info.vue index ef442b7d6..ab711e101 100644 --- a/webapp/pages/post/_id/_slug/more-info.vue +++ b/webapp/pages/post/_id/_slug/more-info.vue @@ -91,7 +91,7 @@ export default { slug contentExcerpt shoutedCount - commentsCount + commentedCount categories { id name @@ -105,7 +105,7 @@ export default { contributionsCount followedByCount followedByCurrentUser - commentsCount + commentedCount location { name: name${this.$i18n.locale().toUpperCase()} } diff --git a/webapp/pages/profile/_id/_slug.vue b/webapp/pages/profile/_id/_slug.vue index 0b0a31a1d..0be23371b 100644 --- a/webapp/pages/profile/_id/_slug.vue +++ b/webapp/pages/profile/_id/_slug.vue @@ -43,14 +43,14 @@ - + - + @@ -254,9 +254,9 @@ import HcEmpty from '~/components/Empty.vue' import ContentMenu from '~/components/ContentMenu' import HcUpload from '~/components/Upload' import HcAvatar from '~/components/Avatar/Avatar.vue' -import PostQuery from '~/graphql/UserProfile/Post.js' -import UserQuery from '~/graphql/User.js' -import { Block, Unblock } from '~/graphql/settings/BlockedUsers.js' +import { filterPosts } from '~/graphql/PostQuery' +import UserQuery from '~/graphql/User' +import { Block, Unblock } from '~/graphql/settings/BlockedUsers' const tabToFilterMapping = ({ tab, id }) => { return { @@ -309,10 +309,6 @@ export default { myProfile() { return this.$route.params.id === this.$store.getters['auth/user'].id }, - followedByCount() { - let count = Number(this.user.followedByCount) || 0 - return count - }, user() { return this.User ? this.User[0] : {} }, @@ -401,7 +397,7 @@ export default { apollo: { Post: { query() { - return PostQuery(this.$i18n) + return filterPosts(this.$i18n) }, variables() { return { diff --git a/webapp/store/auth.js b/webapp/store/auth.js index a9219d8b4..a87897548 100644 --- a/webapp/store/auth.js +++ b/webapp/store/auth.js @@ -70,7 +70,7 @@ export const actions = { data: { currentUser }, } = await client.query({ query: gql` - { + query { currentUser { id name @@ -81,7 +81,7 @@ export const actions = { about locationName contributionsCount - commentsCount + commentedCount socialMedia { id url diff --git a/webapp/store/posts.js b/webapp/store/posts.js index 17e764537..2d9e3ffdc 100644 --- a/webapp/store/posts.js +++ b/webapp/store/posts.js @@ -88,7 +88,7 @@ export const actions = { deleted contributionsCount shoutedCount - commentsCount + commentedCount followedByCount followedByCurrentUser location { @@ -99,7 +99,6 @@ export const actions = { icon } } - commentsCount categories { id name diff --git a/webapp/store/search.js b/webapp/store/search.js index c5ed9523a..0d0172a98 100644 --- a/webapp/store/search.js +++ b/webapp/store/search.js @@ -45,15 +45,14 @@ export const actions = { commit('SET_QUICK_PENDING', true) await this.app.apolloProvider.defaultClient .query({ - query: gql(` + query: gql` query findPosts($query: String!) { findPosts(query: $query, limit: 10) { id slug label: title - value: title, + value: title shoutedCount - commentsCount createdAt author { id @@ -62,7 +61,7 @@ export const actions = { } } } - `), + `, variables: { query: value.replace(/\s/g, '~ ') + '~', },