2016-08-08 11:18:21 +09:00
|
|
|
import Telescope from 'meteor/nova:lib';
|
2016-03-31 09:36:25 +09:00
|
|
|
import React, { PropTypes, Component } from 'react';
|
2016-10-19 10:32:24 +02:00
|
|
|
import { bindActionCreators } from 'redux';
|
|
|
|
import { connect } from 'react-redux';
|
2016-06-10 10:25:38 +09:00
|
|
|
import { intlShape } from 'react-intl';
|
2016-04-04 10:21:18 +09:00
|
|
|
import NovaForm from "meteor/nova:forms";
|
2016-06-14 10:01:44 +09:00
|
|
|
import { withRouter } from 'react-router'
|
2016-06-23 11:40:35 +09:00
|
|
|
import Posts from "meteor/nova:posts";
|
2016-11-04 10:28:54 +09:00
|
|
|
import { graphql } from 'react-apollo';
|
|
|
|
import gql from 'graphql-tag';
|
2016-03-31 09:36:25 +09:00
|
|
|
|
2016-04-14 10:12:35 +09:00
|
|
|
const PostsNewForm = (props, context) => {
|
2016-06-14 10:01:44 +09:00
|
|
|
|
|
|
|
const router = props.router;
|
2016-03-31 09:36:25 +09:00
|
|
|
|
|
|
|
return (
|
2016-08-04 10:50:03 +02:00
|
|
|
<Telescope.components.CanDo
|
|
|
|
action="posts.new"
|
|
|
|
noPermissionMessage="users.cannot_post"
|
|
|
|
displayNoPermissionMessage={true}
|
|
|
|
>
|
2016-04-19 15:45:36 +09:00
|
|
|
<div className="posts-new-form">
|
2016-11-04 10:28:54 +09:00
|
|
|
<NovaFormWithMutation
|
2016-03-31 09:36:25 +09:00
|
|
|
collection={Posts}
|
|
|
|
methodName="posts.new"
|
|
|
|
successCallback={(post)=>{
|
2016-06-14 10:17:11 +09:00
|
|
|
router.push({pathname: Posts.getPageUrl(post)});
|
2016-10-31 17:13:14 +01:00
|
|
|
props.flash(context.intl.formatMessage({id: "posts.created_message"}), "success");
|
2016-11-03 14:39:27 +09:00
|
|
|
context.triggerMainRefetch();
|
2016-03-31 09:36:25 +09:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
2016-08-04 10:50:03 +02:00
|
|
|
</Telescope.components.CanDo>
|
2016-03-31 09:36:25 +09:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2016-04-14 10:12:35 +09:00
|
|
|
PostsNewForm.contextTypes = {
|
2016-06-10 10:25:38 +09:00
|
|
|
currentUser: React.PropTypes.object,
|
2016-11-03 14:39:27 +09:00
|
|
|
triggerMainRefetch: React.PropTypes.func,
|
2016-06-10 10:25:38 +09:00
|
|
|
intl: intlShape
|
2016-03-31 09:36:25 +09:00
|
|
|
};
|
|
|
|
|
2016-05-22 16:42:24 +09:00
|
|
|
PostsNewForm.displayName = "PostsNewForm";
|
|
|
|
|
2016-10-19 10:32:24 +02:00
|
|
|
const mapStateToProps = state => ({ messages: state.messages });
|
|
|
|
const mapDispatchToProps = dispatch => bindActionCreators(Telescope.actions.messages, dispatch);
|
|
|
|
|
2016-11-04 10:28:54 +09:00
|
|
|
const NovaFormWithMutation = graphql(gql`
|
|
|
|
mutation postsNew($post: PostInput) {
|
|
|
|
postsNew(post: $post) {
|
|
|
|
_id
|
|
|
|
title
|
|
|
|
url
|
|
|
|
slug
|
|
|
|
body
|
|
|
|
htmlBody
|
|
|
|
thumbnailUrl
|
|
|
|
baseScore
|
|
|
|
postedAt
|
|
|
|
sticky
|
|
|
|
status
|
|
|
|
categories {
|
|
|
|
_id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
}
|
|
|
|
commentCount
|
|
|
|
comments {
|
|
|
|
_id
|
|
|
|
# note: currently not used in PostsCommentsThread
|
|
|
|
# parentComment {
|
|
|
|
# htmlBody
|
|
|
|
# postedAt
|
|
|
|
# user {
|
|
|
|
# _id
|
|
|
|
# telescope {
|
|
|
|
# slug
|
|
|
|
# emailHash # used for the avatar
|
|
|
|
# }
|
|
|
|
# }
|
|
|
|
# }
|
|
|
|
htmlBody
|
|
|
|
postedAt
|
|
|
|
user {
|
|
|
|
_id
|
|
|
|
telescope {
|
|
|
|
slug
|
|
|
|
emailHash # used for the avatar
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
upvoters {
|
|
|
|
_id
|
|
|
|
}
|
|
|
|
downvoters {
|
|
|
|
_id
|
|
|
|
}
|
|
|
|
upvotes # should be asked only for admins?
|
|
|
|
score # should be asked only for admins?
|
|
|
|
viewCount # should be asked only for admins?
|
|
|
|
clickCount # should be asked only for admins?
|
|
|
|
user {
|
|
|
|
_id
|
|
|
|
telescope {
|
|
|
|
displayName
|
|
|
|
slug
|
|
|
|
emailHash
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, {
|
|
|
|
props: ({ownProps, mutate}) => ({
|
|
|
|
novaFormMutation: ({document}) => {
|
|
|
|
return mutate({
|
|
|
|
variables: {post: document}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
})(NovaForm);
|
|
|
|
|
|
|
|
|
2016-10-19 10:32:24 +02:00
|
|
|
// note: why having both module.exports & export default?
|
|
|
|
module.exports = withRouter(connect(mapStateToProps, mapDispatchToProps)(PostsNewForm));
|
|
|
|
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(PostsNewForm));
|