From a9104b749c1f9c3e97cefaa35cbab5d176249444 Mon Sep 17 00:00:00 2001 From: David Jay Date: Wed, 15 Feb 2017 12:19:36 -0500 Subject: [PATCH 01/11] Updating comments and replies using updatequeries w/ optimistic updating. --- client/coral-embed-stream/src/Comment.js | 1 - client/coral-embed-stream/src/Embed.js | 1 - .../graphql/mutations/index.js | 53 +++++++++++++++++-- .../graphql/mutations/postComment.graphql | 3 ++ 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/client/coral-embed-stream/src/Comment.js b/client/coral-embed-stream/src/Comment.js index 3bf787a9c..48dd52d09 100644 --- a/client/coral-embed-stream/src/Comment.js +++ b/client/coral-embed-stream/src/Comment.js @@ -140,7 +140,6 @@ class Comment extends React.Component { ? { setActiveReplyBox(''); - refetch(); }} setActiveReplyBox={setActiveReplyBox} parentId={parentId || comment.id} diff --git a/client/coral-embed-stream/src/Embed.js b/client/coral-embed-stream/src/Embed.js index d12dbd0d8..6240c293b 100644 --- a/client/coral-embed-stream/src/Embed.js +++ b/client/coral-embed-stream/src/Embed.js @@ -122,7 +122,6 @@ class Embed extends Component { { user ? ({ fragments: commentView }), - props: ({mutate}) => ({ - postItem: ({asset_id, body, parent_id} /* , type */ ) => { - return mutate({ + props: ({ownProps, mutate}) => ({ + postItem: ({asset_id, body, parent_id}) => + mutate({ variables: { asset_id, body, parent_id + }, + optimisticResponse: { + createComment: { + comment: { + user: { + id: ownProps.auth.user.id, + name: ownProps.auth.user.username + }, + created_at: new Date(), + body, + parent_id, + asset_id, + action_summaries: [], + tags: [], + status: null, + id: `${Date.now()}_temp_id` + } + } + }, + updateQueries: { + AssetQuery: (oldData, {mutationResult:{data:{createComment:{comment}}}}) => { + + // If posting a reply + return parent_id ? { + ...oldData, + asset: { + ...oldData.asset, + comments: oldData.asset.comments.map((comment) => + comment.id === parent_id + ? {...comment, replies: [...comment.replies, comment]} + : comment) + } + } + + // If posting a top-level comment + : { + ...oldData, + asset: { + ...oldData.asset, + comments: [comment, ...oldData.asset.comments] + } + }; + } } - }); - }}), + }) + }), }); export const postLike = graphql(POST_LIKE, { diff --git a/client/coral-framework/graphql/mutations/postComment.graphql b/client/coral-framework/graphql/mutations/postComment.graphql index 6ce46eaa8..3840d66c2 100644 --- a/client/coral-framework/graphql/mutations/postComment.graphql +++ b/client/coral-framework/graphql/mutations/postComment.graphql @@ -4,6 +4,9 @@ mutation CreateComment ($asset_id: ID!, $parent_id: ID, $body: String!) { createComment(asset_id:$asset_id, parent_id:$parent_id, body:$body) { comment { ...commentView + replies { + ...commentView + } } errors { translation_key From 904bda86dbf98ef28708361d26d8a4520cf41385 Mon Sep 17 00:00:00 2001 From: David Jay Date: Wed, 15 Feb 2017 12:36:19 -0500 Subject: [PATCH 02/11] Fixing error with replies. --- client/coral-framework/graphql/mutations/index.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/client/coral-framework/graphql/mutations/index.js b/client/coral-framework/graphql/mutations/index.js index 6345e797c..fd08e1751 100644 --- a/client/coral-framework/graphql/mutations/index.js +++ b/client/coral-framework/graphql/mutations/index.js @@ -37,17 +37,17 @@ export const postComment = graphql(POST_COMMENT, { } }, updateQueries: { - AssetQuery: (oldData, {mutationResult:{data:{createComment:{comment}}}}) => { - + AssetQuery: (oldData, {mutationResult:{data:{createComment:{comment}}}}) => + // If posting a reply - return parent_id ? { + parent_id ? { ...oldData, asset: { ...oldData.asset, - comments: oldData.asset.comments.map((comment) => - comment.id === parent_id - ? {...comment, replies: [...comment.replies, comment]} - : comment) + comments: oldData.asset.comments.map((oldComment) => + oldComment.id === parent_id + ? {...oldComment, replies: [...oldComment.replies, comment]} + : oldComment) } } @@ -58,7 +58,6 @@ export const postComment = graphql(POST_COMMENT, { ...oldData.asset, comments: [comment, ...oldData.asset.comments] } - }; } } }) From 79dbe7dcdabf13850cf9a4d9b857bdb03bc0666e Mon Sep 17 00:00:00 2001 From: David Jay Date: Wed, 15 Feb 2017 13:05:31 -0500 Subject: [PATCH 03/11] Updating commentCount on comment post. --- client/coral-framework/graphql/mutations/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/coral-framework/graphql/mutations/index.js b/client/coral-framework/graphql/mutations/index.js index fd08e1751..b67343521 100644 --- a/client/coral-framework/graphql/mutations/index.js +++ b/client/coral-framework/graphql/mutations/index.js @@ -38,7 +38,7 @@ export const postComment = graphql(POST_COMMENT, { }, updateQueries: { AssetQuery: (oldData, {mutationResult:{data:{createComment:{comment}}}}) => - + // If posting a reply parent_id ? { ...oldData, @@ -56,6 +56,7 @@ export const postComment = graphql(POST_COMMENT, { ...oldData, asset: { ...oldData.asset, + commentCount: oldData.asset.commentCount + 1, comments: [comment, ...oldData.asset.comments] } } From e3e85c5f3b6473bd816c651370e9909fddd9b9f2 Mon Sep 17 00:00:00 2001 From: David Jay Date: Thu, 16 Feb 2017 17:18:36 -0500 Subject: [PATCH 04/11] Fixing error when posting comment. --- client/coral-framework/graphql/mutations/postComment.graphql | 1 + 1 file changed, 1 insertion(+) diff --git a/client/coral-framework/graphql/mutations/postComment.graphql b/client/coral-framework/graphql/mutations/postComment.graphql index 3840d66c2..110ab4b4e 100644 --- a/client/coral-framework/graphql/mutations/postComment.graphql +++ b/client/coral-framework/graphql/mutations/postComment.graphql @@ -4,6 +4,7 @@ mutation CreateComment ($asset_id: ID!, $parent_id: ID, $body: String!) { createComment(asset_id:$asset_id, parent_id:$parent_id, body:$body) { comment { ...commentView + replyCount replies { ...commentView } From a35af36ee1eaf06aee7ca8a121e8d82952cf7c1d Mon Sep 17 00:00:00 2001 From: David Jay Date: Fri, 17 Feb 2017 11:26:19 -0500 Subject: [PATCH 05/11] Handling premod in optimistic comment updates. --- .../coral-framework/graphql/mutations/index.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/client/coral-framework/graphql/mutations/index.js b/client/coral-framework/graphql/mutations/index.js index b67343521..cdc57e73e 100644 --- a/client/coral-framework/graphql/mutations/index.js +++ b/client/coral-framework/graphql/mutations/index.js @@ -25,7 +25,7 @@ export const postComment = graphql(POST_COMMENT, { id: ownProps.auth.user.id, name: ownProps.auth.user.username }, - created_at: new Date(), + created_at: new Date().toString(), body, parent_id, asset_id, @@ -37,17 +37,22 @@ export const postComment = graphql(POST_COMMENT, { } }, updateQueries: { - AssetQuery: (oldData, {mutationResult:{data:{createComment:{comment}}}}) => + AssetQuery: (oldData, {mutationResult:{data:{createComment:{comment}}}}) => { + + if (oldData.asset.moderation === 'PRE') { + return oldData; + } // If posting a reply - parent_id ? { + return parent_id ? { ...oldData, asset: { ...oldData.asset, - comments: oldData.asset.comments.map((oldComment) => - oldComment.id === parent_id + comments: oldData.asset.comments.map((oldComment) => { + return oldComment.id === parent_id ? {...oldComment, replies: [...oldComment.replies, comment]} - : oldComment) + : oldComment; + }) } } @@ -59,6 +64,7 @@ export const postComment = graphql(POST_COMMENT, { commentCount: oldData.asset.commentCount + 1, comments: [comment, ...oldData.asset.comments] } + }; } } }) From 5a09beb727a48920cd03f4c2e1431839a85364fa Mon Sep 17 00:00:00 2001 From: gaba Date: Fri, 17 Feb 2017 10:12:37 -0800 Subject: [PATCH 06/11] It has to be translation_key and not message. --- client/coral-admin/src/actions/auth.js | 2 +- client/coral-admin/src/actions/install.js | 4 ++-- client/coral-framework/actions/auth.js | 2 +- client/coral-framework/components/SuspendedAccount.js | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/client/coral-admin/src/actions/auth.js b/client/coral-admin/src/actions/auth.js index 8bc0d4e4c..bdb101362 100644 --- a/client/coral-admin/src/actions/auth.js +++ b/client/coral-admin/src/actions/auth.js @@ -16,7 +16,7 @@ export const checkLogin = () => dispatch => { }) .catch(error => { console.error(error); - dispatch(checkLoginFailure(`${error.message}`)); + dispatch(checkLoginFailure(`${error.translation_key}`)); }); }; diff --git a/client/coral-admin/src/actions/install.js b/client/coral-admin/src/actions/install.js index a74a1929f..c1d05d253 100644 --- a/client/coral-admin/src/actions/install.js +++ b/client/coral-admin/src/actions/install.js @@ -81,7 +81,7 @@ export const submitUser = () => (dispatch, getState) => { }) .catch(error => { console.error(error); - dispatch(installFailure(`${error.message}`)); + dispatch(installFailure(`${error.translation_key}`)); }); }); }; @@ -104,6 +104,6 @@ export const checkInstall = next => dispatch => { }) .catch(error => { console.error(error); - dispatch(checkInstallFailure(`${error.message}`)); + dispatch(checkInstallFailure(`${error.translation_key}`)); }); }; diff --git a/client/coral-framework/actions/auth.js b/client/coral-framework/actions/auth.js index 8618cf1d3..92f489ae7 100644 --- a/client/coral-framework/actions/auth.js +++ b/client/coral-framework/actions/auth.js @@ -177,7 +177,7 @@ export const checkLogin = () => dispatch => { }) .catch(error => { console.error(error); - dispatch(checkLoginFailure(`${error.message}`)); + dispatch(checkLoginFailure(`${error.translation_key}`)); }); }; diff --git a/client/coral-framework/components/SuspendedAccount.js b/client/coral-framework/components/SuspendedAccount.js index 00adc9952..446169b37 100644 --- a/client/coral-framework/components/SuspendedAccount.js +++ b/client/coral-framework/components/SuspendedAccount.js @@ -26,7 +26,7 @@ class SuspendedAccount extends Component { editName(username) .then(() => location.reload()) .catch((error) => { - this.setState({alert: lang.t(`error.${error.message}`)}); + this.setState({alert: lang.t(`error.${error.translation_key}`)}); }); } else { this.setState({alert: lang.t('editName.error')}); From 6eb4725dd9bfe273dbfc4edb056951692bf6c2e1 Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Fri, 17 Feb 2017 14:03:37 -0700 Subject: [PATCH 07/11] remove ternary from return statement --- .../graphql/mutations/index.js | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/client/coral-framework/graphql/mutations/index.js b/client/coral-framework/graphql/mutations/index.js index cdc57e73e..ef5359eb1 100644 --- a/client/coral-framework/graphql/mutations/index.js +++ b/client/coral-framework/graphql/mutations/index.js @@ -43,28 +43,35 @@ export const postComment = graphql(POST_COMMENT, { return oldData; } + let updatedAsset; + // If posting a reply - return parent_id ? { - ...oldData, - asset: { - ...oldData.asset, - comments: oldData.asset.comments.map((oldComment) => { - return oldComment.id === parent_id - ? {...oldComment, replies: [...oldComment.replies, comment]} - : oldComment; - }) - } + if (parent_id) { + updatedAsset = { + ...oldData, + asset: { + ...oldData.asset, + comments: oldData.asset.comments.map((oldComment) => { + return oldComment.id === parent_id + ? {...oldComment, replies: [...oldComment.replies, comment]} + : oldComment; + }) + } + }; + } else { + + // If posting a top-level comment + updatedAsset = { + ...oldData, + asset: { + ...oldData.asset, + commentCount: oldData.asset.commentCount + 1, + comments: [comment, ...oldData.asset.comments] + } + }; } - // If posting a top-level comment - : { - ...oldData, - asset: { - ...oldData.asset, - commentCount: oldData.asset.commentCount + 1, - comments: [comment, ...oldData.asset.comments] - } - }; + return updatedAsset; } } }) From 2506442453877f041e401d68dc9d3a54ccbfe5ba Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Fri, 17 Feb 2017 14:10:21 -0700 Subject: [PATCH 08/11] toISOString --- client/coral-framework/graphql/mutations/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/coral-framework/graphql/mutations/index.js b/client/coral-framework/graphql/mutations/index.js index ef5359eb1..a9d08da85 100644 --- a/client/coral-framework/graphql/mutations/index.js +++ b/client/coral-framework/graphql/mutations/index.js @@ -25,7 +25,7 @@ export const postComment = graphql(POST_COMMENT, { id: ownProps.auth.user.id, name: ownProps.auth.user.username }, - created_at: new Date().toString(), + created_at: new Date().toISOString(), body, parent_id, asset_id, From 9f168e627adda55a4ac4e93157f2604794494643 Mon Sep 17 00:00:00 2001 From: gaba Date: Fri, 17 Feb 2017 14:19:30 -0800 Subject: [PATCH 09/11] It uses message and not translation key. --- client/coral-framework/actions/auth.js | 2 +- routes/api/users/index.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/client/coral-framework/actions/auth.js b/client/coral-framework/actions/auth.js index 92f489ae7..4a12245eb 100644 --- a/client/coral-framework/actions/auth.js +++ b/client/coral-framework/actions/auth.js @@ -123,7 +123,7 @@ export const fetchSignUp = (formData, redirectUri) => (dispatch) => { dispatch(signUpSuccess(user)); }) .catch(error => { - dispatch(signUpFailure(lang.t(`error.${error.translation_key}`))); + dispatch(signUpFailure(lang.t(`error.${error.message}`))); }); }; diff --git a/routes/api/users/index.js b/routes/api/users/index.js index 4182beb49..df7369bb3 100644 --- a/routes/api/users/index.js +++ b/routes/api/users/index.js @@ -136,7 +136,7 @@ router.post('/', (req, res, next) => { res.status(201).json(user); }); }) - .catch(err => { + .catch((err) => { next(err); }); }); @@ -163,7 +163,6 @@ router.post('/:user_id/actions', authorization.needed(), (req, res, next) => { res.status(201).json(action); }) .catch((err) => { - console.log('Error', err); next(err); }); }); From afcdacff0dcbdb6be9d9594da70d4d6e43afce4a Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Fri, 17 Feb 2017 17:49:59 -0700 Subject: [PATCH 10/11] Added yarn.lock to Dockerfile --- Dockerfile | 4 ++-- package.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index a01aae254..11587cafb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,8 +14,8 @@ ENV TALK_PORT 5000 EXPOSE 5000 # Install app dependencies -COPY package.json /usr/src/app/ -RUN yarn install --production +COPY package.json yarn.lock /usr/src/app/ +RUN yarn install # Bundle app source COPY . /usr/src/app diff --git a/package.json b/package.json index 09ce50aa9..70b0e17b1 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,6 @@ }, "homepage": "https://github.com/coralproject/talk#readme", "dependencies": { - "apollo-client": "^0.8.3", "bcrypt": "^0.8.7", "body-parser": "^1.15.2", "cli-table": "^0.3.1", @@ -66,7 +65,6 @@ "graphql": "^0.8.2", "graphql-errors": "^2.1.0", "graphql-server-express": "^0.5.0", - "graphql-tag": "^1.2.3", "graphql-tools": "^0.9.0", "helmet": "^3.1.0", "inquirer": "^3.0.1", @@ -88,6 +86,7 @@ "uuid": "^2.0.3" }, "devDependencies": { + "apollo-client": "^0.8.3", "autoprefixer": "^6.5.2", "babel-core": "^6.21.0", "babel-eslint": "^7.1.0", @@ -122,6 +121,7 @@ "exports-loader": "^0.6.3", "fetch-mock": "^5.5.0", "graphql-docs": "^0.2.0", + "graphql-tag": "^1.2.3", "hammerjs": "^2.0.8", "ignore-styles": "^5.0.1", "immutable": "^3.8.1", From 301c8e829f7e985d66c6fbc7b0c1f571d6173b33 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Fri, 17 Feb 2017 17:56:44 -0700 Subject: [PATCH 11/11] Added production flag back --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 11587cafb..14d606c0a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,7 +15,7 @@ EXPOSE 5000 # Install app dependencies COPY package.json yarn.lock /usr/src/app/ -RUN yarn install +RUN yarn install --production # Bundle app source COPY . /usr/src/app