2016-11-04 14:14:19 +01:00
|
|
|
import Telescope from 'meteor/nova:lib';
|
|
|
|
import React, { PropTypes, Component } from 'react';
|
|
|
|
import { FormattedMessage, intlShape } from 'react-intl';
|
2016-11-07 17:45:17 +09:00
|
|
|
import Posts from "meteor/nova:posts";
|
2016-11-04 14:14:19 +01:00
|
|
|
import { bindActionCreators } from 'redux';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { withRouter } from 'react-router'
|
|
|
|
import { graphql } from 'react-apollo';
|
|
|
|
import gql from 'graphql-tag';
|
|
|
|
|
|
|
|
const PostsEditFormContainer = (props, context) => {
|
|
|
|
const Component = props.component;
|
|
|
|
|
2016-11-07 15:03:45 +09:00
|
|
|
return <Component {...props} />;
|
2016-11-04 14:14:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
PostsEditFormContainer.propTypes = {
|
|
|
|
flash: React.PropTypes.func,
|
|
|
|
novaFormMutation: React.PropTypes.func,
|
|
|
|
post: React.PropTypes.object.isRequired,
|
|
|
|
router: React.PropTypes.object,
|
2016-11-07 15:03:45 +09:00
|
|
|
component: React.PropTypes.func,
|
|
|
|
successCallback: React.PropTypes.func,
|
|
|
|
cancelCallback: React.PropTypes.func,
|
2016-11-04 14:14:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const mapStateToProps = state => ({ messages: state.messages, });
|
|
|
|
const mapDispatchToProps = dispatch => bindActionCreators(Telescope.actions.messages, dispatch);
|
|
|
|
|
|
|
|
const PostsEditFormContainerWithMutation = graphql(gql`
|
2016-11-05 18:37:46 +09:00
|
|
|
mutation postsEdit($postId: String, $set: PostInput, $unset: PostUnsetModifier) {
|
2016-11-04 14:14:19 +01:00
|
|
|
postsEdit(postId: $postId, set: $set, unset: $unset) {
|
2016-11-07 17:45:17 +09:00
|
|
|
${Posts.graphQLQueries.single}
|
2016-11-04 14:14:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`, {
|
|
|
|
props: ({ownProps, mutate}) => ({
|
|
|
|
novaFormMutation: ({documentId, set, unset}) => {
|
|
|
|
return mutate({
|
2016-11-05 18:37:46 +09:00
|
|
|
variables: {postId: documentId, set, unset},
|
|
|
|
// optimisticResponse: {
|
|
|
|
// __typename: 'Mutation',
|
|
|
|
// postsEdit: {
|
|
|
|
// __typename: 'Post',
|
|
|
|
// ...set
|
|
|
|
// }
|
|
|
|
// },
|
2016-11-04 14:14:19 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
})(PostsEditFormContainer);
|
|
|
|
|
|
|
|
module.exports = withRouter(connect(mapStateToProps, mapDispatchToProps)(PostsEditFormContainerWithMutation));
|