withCategoriesList HOC with the new syntax

This commit is contained in:
xavcz 2016-11-11 10:35:29 +01:00
parent 7a170786c8
commit b4ddddf5a7
7 changed files with 83 additions and 51 deletions

View file

@ -6,6 +6,7 @@ import { /* ModalTrigger, */ ContextPasser } from "meteor/nova:core";
import { withRouter } from 'react-router'
import { LinkContainer } from 'react-router-bootstrap';
import Users from 'meteor/nova:users';
import { withCategoriesList } from 'meteor/nova:base-containers';
// note: cannot use ModalTrigger component because of https://github.com/react-bootstrap/react-bootstrap/issues/1808
@ -155,5 +156,4 @@ CategoriesList.contextTypes = {
currentUser: React.PropTypes.object,
};
module.exports = withRouter(CategoriesList);
export default withRouter(CategoriesList);
module.exports = withRouter(withCategoriesList(CategoriesList, {}));

View file

@ -8,7 +8,7 @@ const PostsListHeader = () => {
<div>
<div className="posts-list-header">
<div className="posts-list-header-categories">
<Telescope.components.CategoriesListContainer component={Telescope.components.CategoriesList} />
<Telescope.components.CategoriesList />
</div>
<Telescope.components.PostsViews />
<Telescope.components.SearchForm/>

View file

@ -4,5 +4,6 @@ import withPostsList from './containers/withPostsList.js';
import withPostsSingle from './containers/withPostsSingle.js';
import withCommentsList from './containers/withCommentsList.js';
import withUsersSingle from './containers/withUsersSingle.js';
import withCategoriesList from './containers/withCategoriesList.js';
export {withPostsList, withPostsSingle, withCommentsList, withUsersSingle}
export {withPostsList, withPostsSingle, withCommentsList, withUsersSingle, withCategoriesList}

View file

@ -1,54 +1,54 @@
import Telescope from 'meteor/nova:lib';
import React, { PropTypes, Component } from 'react';
import Categories from "meteor/nova:categories";
// import Telescope from 'meteor/nova:lib';
// import React, { PropTypes, Component } from 'react';
// import Categories from "meteor/nova:categories";
import { graphql } from 'react-apollo';
import gql from 'graphql-tag';
// import { graphql } from 'react-apollo';
// import gql from 'graphql-tag';
class CategoriesListContainer extends Component {
// class CategoriesListContainer extends Component {
render() {
// render() {
const {loading, results, componentProps} = this.props;
const Component = this.props.component;
// const {loading, results, componentProps} = this.props;
// const Component = this.props.component;
return <Component results={results || []} loading={loading} {...componentProps}
/>;
}
};
// return <Component results={results || []} loading={loading} {...componentProps}
// />;
// }
// };
CategoriesListContainer.propTypes = {
loading: React.PropTypes.bool,
results: React.PropTypes.array,
};
// CategoriesListContainer.propTypes = {
// loading: React.PropTypes.bool,
// results: React.PropTypes.array,
// };
CategoriesListContainer.displayName = "CategoriesListContainer";
// CategoriesListContainer.displayName = "CategoriesListContainer";
const CategoriesListContainerWithData = graphql(gql`
query getCategoriesList {
categories {
_id
name
description
order
slug
image
}
}
`, {
options(ownProps) {
return {
variables: {},
// pollInterval: 20000,
};
},
props(props) {
const {data: {loading, categories}} = props;
return {
loading,
results: categories,
};
},
})(CategoriesListContainer);
// const CategoriesListContainerWithData = graphql(gql`
// query getCategoriesList {
// categories {
// _id
// name
// description
// order
// slug
// image
// }
// }
// `, {
// options(ownProps) {
// return {
// variables: {},
// // pollInterval: 20000,
// };
// },
// props(props) {
// const {data: {loading, categories}} = props;
// return {
// loading,
// results: categories,
// };
// },
// })(CategoriesListContainer);
module.exports = CategoriesListContainerWithData;
// module.exports = CategoriesListContainerWithData;

View file

@ -0,0 +1,31 @@
import Telescope from 'meteor/nova:lib';
import React, { PropTypes, Component } from 'react';
import { graphql } from 'react-apollo';
import Categories from 'meteor/nova:categories'
import gql from 'graphql-tag';
export default function withCategoriesList(component, options) {
return graphql(gql`
query getCategoriesList {
categories {
${Categories.graphQLQueries.single}
}
}
`, {
options(ownProps) {
return {
variables: {},
// pollInterval: 20000,
};
},
props(props) {
const {data: {loading, categories}} = props;
return {
loading,
results: categories,
};
}
})(component);
}
module.exports = withCategoriesList;

View file

@ -1,6 +1,5 @@
import Telescope from 'meteor/nova:lib';
import React, { PropTypes, Component } from 'react';
import Posts from "meteor/nova:posts";
import { graphql } from 'react-apollo';
import gql from 'graphql-tag';

View file

@ -4,5 +4,6 @@ import withPostsList from './containers/withPostsList.js';
import withPostsSingle from './containers/withPostsSingle.js';
import withCommentsList from './containers/withCommentsList.js';
import withUsersSingle from './containers/withUsersSingle.js';
import withCategoriesList from './containers/withCategoriesList.js';
export {withPostsList, withPostsSingle, withCommentsList, withUsersSingle}
export {withPostsList, withPostsSingle, withCommentsList, withUsersSingle, withCategoriesList}