From b4ddddf5a7b044646f0728a9b7694083def9654e Mon Sep 17 00:00:00 2001 From: xavcz Date: Fri, 11 Nov 2016 10:35:29 +0100 Subject: [PATCH] withCategoriesList HOC with the new syntax --- .../lib/categories/CategoriesList.jsx | 4 +- .../lib/posts/PostsListHeader.jsx | 2 +- packages/nova-base-containers/lib/client.js | 3 +- .../containers/CategoriesListContainer.jsx | 90 +++++++++---------- .../lib/containers/withCategoriesList.js | 31 +++++++ .../lib/containers/withCommentsList.js | 1 - packages/nova-base-containers/lib/server.js | 3 +- 7 files changed, 83 insertions(+), 51 deletions(-) diff --git a/packages/nova-base-components/lib/categories/CategoriesList.jsx b/packages/nova-base-components/lib/categories/CategoriesList.jsx index 3ffd7af61..681eaacc1 100644 --- a/packages/nova-base-components/lib/categories/CategoriesList.jsx +++ b/packages/nova-base-components/lib/categories/CategoriesList.jsx @@ -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); \ No newline at end of file +module.exports = withRouter(withCategoriesList(CategoriesList, {})); diff --git a/packages/nova-base-components/lib/posts/PostsListHeader.jsx b/packages/nova-base-components/lib/posts/PostsListHeader.jsx index f9398c69c..a774f8453 100644 --- a/packages/nova-base-components/lib/posts/PostsListHeader.jsx +++ b/packages/nova-base-components/lib/posts/PostsListHeader.jsx @@ -8,7 +8,7 @@ const PostsListHeader = () => {
- +
diff --git a/packages/nova-base-containers/lib/client.js b/packages/nova-base-containers/lib/client.js index 4362c02c6..1057c4a93 100644 --- a/packages/nova-base-containers/lib/client.js +++ b/packages/nova-base-containers/lib/client.js @@ -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} \ No newline at end of file +export {withPostsList, withPostsSingle, withCommentsList, withUsersSingle, withCategoriesList} diff --git a/packages/nova-base-containers/lib/containers/CategoriesListContainer.jsx b/packages/nova-base-containers/lib/containers/CategoriesListContainer.jsx index c912a99bb..3e603ef7d 100644 --- a/packages/nova-base-containers/lib/containers/CategoriesListContainer.jsx +++ b/packages/nova-base-containers/lib/containers/CategoriesListContainer.jsx @@ -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 ; - } -}; +// return ; +// } +// }; -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; \ No newline at end of file +// module.exports = CategoriesListContainerWithData; \ No newline at end of file diff --git a/packages/nova-base-containers/lib/containers/withCategoriesList.js b/packages/nova-base-containers/lib/containers/withCategoriesList.js index e69de29bb..ace291f7c 100644 --- a/packages/nova-base-containers/lib/containers/withCategoriesList.js +++ b/packages/nova-base-containers/lib/containers/withCategoriesList.js @@ -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; \ No newline at end of file diff --git a/packages/nova-base-containers/lib/containers/withCommentsList.js b/packages/nova-base-containers/lib/containers/withCommentsList.js index 89b2e743b..ca092e14a 100644 --- a/packages/nova-base-containers/lib/containers/withCommentsList.js +++ b/packages/nova-base-containers/lib/containers/withCommentsList.js @@ -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'; diff --git a/packages/nova-base-containers/lib/server.js b/packages/nova-base-containers/lib/server.js index 4362c02c6..1057c4a93 100644 --- a/packages/nova-base-containers/lib/server.js +++ b/packages/nova-base-containers/lib/server.js @@ -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} \ No newline at end of file +export {withPostsList, withPostsSingle, withCommentsList, withUsersSingle, withCategoriesList}