2016-10-27 15:29:15 +09:00
|
|
|
import Telescope from 'meteor/nova:lib';
|
2016-11-03 14:07:58 +09:00
|
|
|
import React, { PropTypes, Component } from 'react';
|
2016-10-27 15:29:15 +09:00
|
|
|
import Posts from "meteor/nova:posts";
|
|
|
|
|
|
|
|
import { graphql } from 'react-apollo';
|
|
|
|
import gql from 'graphql-tag';
|
|
|
|
|
2016-11-03 14:07:58 +09:00
|
|
|
class PostsSingleContainer extends Component {
|
2016-10-27 15:29:15 +09:00
|
|
|
|
2016-11-03 14:07:58 +09:00
|
|
|
getChildContext() {
|
|
|
|
return {
|
|
|
|
refetchPostsSingleQuery: this.props.data.refetch
|
|
|
|
};
|
|
|
|
}
|
2016-10-27 15:29:15 +09:00
|
|
|
|
2016-11-03 14:07:58 +09:00
|
|
|
render() {
|
2016-11-04 14:38:31 +09:00
|
|
|
|
2016-11-07 17:45:17 +09:00
|
|
|
console.log(this.props)
|
2016-11-07 13:00:09 +09:00
|
|
|
|
2016-11-03 14:07:58 +09:00
|
|
|
const {loading, post, refetch} = this.props.data;
|
|
|
|
const Component = this.props.component
|
|
|
|
|
|
|
|
return loading ? <Telescope.components.Loading/> : <Component
|
|
|
|
document={post}
|
|
|
|
refetchQuery={refetch}
|
|
|
|
{...this.props.componentProps}
|
|
|
|
/>;
|
|
|
|
}
|
2016-10-27 15:29:15 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
PostsSingleContainer.propTypes = {
|
|
|
|
data: React.PropTypes.shape({
|
|
|
|
loading: React.PropTypes.bool,
|
|
|
|
post: React.PropTypes.object,
|
|
|
|
}).isRequired,
|
|
|
|
params: React.PropTypes.object
|
|
|
|
};
|
|
|
|
|
2016-11-03 14:07:58 +09:00
|
|
|
PostsSingleContainer.childContextTypes = {
|
|
|
|
refetchPostsSingleQuery: React.PropTypes.func
|
|
|
|
};
|
|
|
|
|
2016-10-27 15:29:15 +09:00
|
|
|
PostsSingleContainer.contextTypes = {
|
|
|
|
currentUser: React.PropTypes.object
|
|
|
|
};
|
|
|
|
|
|
|
|
PostsSingleContainer.displayName = "PostsSingleContainer";
|
|
|
|
|
|
|
|
// this query is really too big 💥...🚂
|
|
|
|
const PostsSingleContainerWithData = graphql(gql`
|
|
|
|
query getPost($postId: String) {
|
|
|
|
post(_id: $postId) {
|
2016-11-07 17:45:17 +09:00
|
|
|
${Posts.graphQLQueries.single}
|
2016-10-27 15:29:15 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
`, {
|
|
|
|
options(ownProps) {
|
|
|
|
return {
|
|
|
|
variables: { postId: ownProps.postId },
|
2016-11-02 19:56:44 +09:00
|
|
|
// pollInterval: 20000,
|
2016-10-27 15:29:15 +09:00
|
|
|
};
|
|
|
|
},
|
|
|
|
})(PostsSingleContainer);
|
|
|
|
|
|
|
|
module.exports = PostsSingleContainerWithData;
|