diff --git a/Dockerfile b/Dockerfile index a01aae254..14d606c0a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ ENV TALK_PORT 5000 EXPOSE 5000 # Install app dependencies -COPY package.json /usr/src/app/ +COPY package.json yarn.lock /usr/src/app/ RUN yarn install --production # Bundle app source 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-embed-stream/src/Comment.js b/client/coral-embed-stream/src/Comment.js index 034c44f6a..9d679473e 100644 --- a/client/coral-embed-stream/src/Comment.js +++ b/client/coral-embed-stream/src/Comment.js @@ -142,7 +142,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 8b420836e..a7c4dcb38 100644 --- a/client/coral-embed-stream/src/Embed.js +++ b/client/coral-embed-stream/src/Embed.js @@ -128,7 +128,6 @@ class Embed extends Component { { user ? (dispatch) => { dispatch(signUpSuccess(user)); }) .catch(error => { - dispatch(signUpFailure(lang.t(`error.${error.translation_key}`))); + dispatch(signUpFailure(lang.t(`error.${error.message}`))); }); }; @@ -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')}); diff --git a/client/coral-framework/graphql/mutations/index.js b/client/coral-framework/graphql/mutations/index.js index 40ca0a7a3..a9d08da85 100644 --- a/client/coral-framework/graphql/mutations/index.js +++ b/client/coral-framework/graphql/mutations/index.js @@ -10,16 +10,72 @@ export const postComment = graphql(POST_COMMENT, { options: () => ({ 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().toISOString(), + body, + parent_id, + asset_id, + action_summaries: [], + tags: [], + status: null, + id: `${Date.now()}_temp_id` + } + } + }, + updateQueries: { + AssetQuery: (oldData, {mutationResult:{data:{createComment:{comment}}}}) => { + + if (oldData.asset.moderation === 'PRE') { + return oldData; + } + + let updatedAsset; + + // If posting a reply + 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] + } + }; + } + + return updatedAsset; + } } - }); - }}), + }) + }), }); 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..110ab4b4e 100644 --- a/client/coral-framework/graphql/mutations/postComment.graphql +++ b/client/coral-framework/graphql/mutations/postComment.graphql @@ -4,6 +4,10 @@ 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 + } } errors { translation_key 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", 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); }); });