Handling edited comments data

This commit is contained in:
okbel
2018-02-22 08:59:21 -03:00
parent 6eb442d59a
commit 6f6fe69129
4 changed files with 51 additions and 4 deletions
@@ -53,6 +53,8 @@ export class EditableCommentContent extends React.Component {
this.state = {
body: props.comment.body,
loadingState: '',
// data: {@object} contains data that might be useful for plugins, metadata, etc
data: {},
};
}
componentDidMount() {
@@ -72,8 +74,14 @@ export class EditableCommentContent extends React.Component {
}
}
handleBodyChange = body => {
this.setState({ body });
handleBodyChange = (body, ...data) => {
this.setState(state => ({
body,
data: {
...state.data,
...data[0],
},
}));
};
handleSubmit = async () => {
@@ -88,9 +96,16 @@ export class EditableCommentContent extends React.Component {
if (typeof editComment !== 'function') {
return;
}
let input = {
body: this.state.body,
...this.state.data,
};
let response;
try {
response = await editComment({ body: this.state.body });
response = await editComment(input);
if (!this.unmounted) {
this.setState({ loadingState: 'success' });
}
+18
View File
@@ -15,6 +15,13 @@ export default {
}
}
`,
EditCommentResponse: gql`
fragment TalkRTE_EditCommentResponse on EditCommentResponse {
comment {
htmlBody
}
}
`,
},
mutations: {
PostComment: ({ variables: { input } }) => {
@@ -28,5 +35,16 @@ export default {
},
};
},
EditComment: ({ variables: { edit } }) => {
return {
optimisticResponse: {
editComment: {
comment: {
htmlBody: edit.htmlBody,
},
},
},
};
},
},
};
+10
View File
@@ -12,5 +12,15 @@ module.exports = {
);
},
},
editComment: {
async pre(_, { edit }, _context, _info) {
edit.metadata = merge(
{},
{
htmlBody: edit.htmlBody,
}
);
},
},
},
};
@@ -2,6 +2,10 @@ input CreateCommentInput {
htmlBody: String
}
input EditCommentInput {
htmlBody: String
}
type Comment {
htmlBody: String
}
}