diff --git a/packages/nova-base-components/lib/posts/PostsCommentsThread.jsx b/packages/nova-base-components/lib/posts/PostsCommentsThread.jsx index cd80e6168..b30c3bec6 100644 --- a/packages/nova-base-components/lib/posts/PostsCommentsThread.jsx +++ b/packages/nova-base-components/lib/posts/PostsCommentsThread.jsx @@ -50,7 +50,8 @@ PostsCommentsThread.propTypes = { currentUser: React.PropTypes.object }; -const fragment = gql` +PostsCommentsThread.fragmentName = 'commentsListFragment'; +PostsCommentsThread.fragment = gql` fragment commentsListFragment on Comment { _id postId @@ -71,17 +72,8 @@ const fragment = gql` const options = { collection: Comments, queryName: 'commentsListQuery', - fragmentName: 'commentsListFragment', - fragment: fragment, - limit: 0, - options: { - variables: { - postId: { - type: 'String', - usedForTotal: true - } - } - }, + fragmentName: PostsCommentsThread.fragmentName, + fragment: PostsCommentsThread.fragment, }; Telescope.registerComponent('PostsCommentsThread', PostsCommentsThread, withCurrentUser, withList(options)); diff --git a/packages/nova-core/lib/components/App.jsx b/packages/nova-core/lib/components/App.jsx index 54d8ad46d..361a8d11f 100644 --- a/packages/nova-core/lib/components/App.jsx +++ b/packages/nova-core/lib/components/App.jsx @@ -1,7 +1,7 @@ import Telescope from 'meteor/nova:lib'; import React, { PropTypes, Component } from 'react'; import { IntlProvider, intlShape} from 'react-intl'; -import { withCurrentUser } from 'meteor/nova:users'; +import { loadCurrentUser } from 'meteor/nova:users'; class App extends Component { @@ -43,6 +43,6 @@ App.childContextTypes = { intl: intlShape, } -Telescope.registerComponent('App', App, withCurrentUser); +Telescope.registerComponent('App', App, loadCurrentUser); export default App; \ No newline at end of file diff --git a/packages/nova-core/lib/containers/withList.js b/packages/nova-core/lib/containers/withList.js index 6ccfe1ac6..64feeb7b5 100644 --- a/packages/nova-core/lib/containers/withList.js +++ b/packages/nova-core/lib/containers/withList.js @@ -29,7 +29,7 @@ export default function withList (options) { }; }, props(props) { - + const loading = props.data.loading, fetchMore = props.data.fetchMore, refetch = props.data.refetch, diff --git a/packages/nova-users/lib/containers/loadCurrentUser.js b/packages/nova-users/lib/containers/loadCurrentUser.js new file mode 100644 index 000000000..37cf2a3ed --- /dev/null +++ b/packages/nova-users/lib/containers/loadCurrentUser.js @@ -0,0 +1,32 @@ +import Telescope from 'meteor/nova:lib'; +import Users from '../collection.js'; +import { graphql } from 'react-apollo'; +import gql from 'graphql-tag'; + +const loadCurrentUser = component => { + + const preloadedFields = _.compact(_.map(Users.simpleSchema()._schema, (field, fieldName) => { + return field.preload ? fieldName : undefined; + })); + + // console.log('preloaded fields', preloadedFields); + + return graphql( + gql`query getCurrentUser { + currentUser { + ${preloadedFields.join('\n')} + } + } + `, { + props(props) { + const {data: {loading, currentUser}} = props; + return { + loading, + currentUser, + }; + }, + } + )(component); +}; + +export default loadCurrentUser; diff --git a/packages/nova-users/lib/containers/withCurrentUser.js b/packages/nova-users/lib/containers/withCurrentUser.js index eb52cf0b7..7d50ecf14 100644 --- a/packages/nova-users/lib/containers/withCurrentUser.js +++ b/packages/nova-users/lib/containers/withCurrentUser.js @@ -1,32 +1,30 @@ +import React, { Component, PropTypes } from 'react'; +import hoistStatics from 'hoist-non-react-statics'; +import { Meteor } from 'meteor/meteor'; import Telescope from 'meteor/nova:lib'; -import Users from '../collection.js'; -import { graphql } from 'react-apollo'; -import gql from 'graphql-tag'; -const withCurrentUser = component => { +/** + * withCurrentUser - HOC to give access to the currentUser as a prop of a WrappedComponent + **/ +export default function withCurrentUser(WrappedComponent) { - const preloadedFields = _.compact(_.map(Users.simpleSchema()._schema, (field, fieldName) => { - return field.preload ? fieldName : undefined; - })); - - // console.log('preloaded fields', preloadedFields); - - return graphql( - gql`query getCurrentUser { - currentUser { - ${preloadedFields.join('\n')} - } + class WithCurrentUser extends Component { + constructor(...args) { + super(...args); } - `, { - props(props) { - const {data: {loading, currentUser}} = props; - return { - loading, - currentUser, - }; - }, - } - )(component); -}; + + render() { + const {client} = this.context; // grab the apollo client from the context -export default withCurrentUser; \ No newline at end of file + const currentUser = client ? client.store.getState().apollo.data[`User${Meteor.userId()}`] : null; + + return currentUser ? : ; + } + } + + WithCurrentUser.contextTypes = { client: PropTypes.object.isRequired }; + WithCurrentUser.displayName = `withCurrentUser(${Telescope.utils.getComponentDisplayName(WrappedComponent)}`; + WithCurrentUser.WrappedComponent = WrappedComponent; + + return hoistStatics(WithCurrentUser, WrappedComponent); +} \ No newline at end of file diff --git a/packages/nova-users/lib/modules.js b/packages/nova-users/lib/modules.js index 12c7a6154..b2d6182f7 100644 --- a/packages/nova-users/lib/modules.js +++ b/packages/nova-users/lib/modules.js @@ -9,3 +9,4 @@ import './permissions.js'; export default Users; export { default as withCurrentUser } from './containers/withCurrentUser.js'; +export { default as loadCurrentUser } from './containers/loadCurrentUser.js';