Vulcan/packages/nova-users/lib/containers/withCurrentUser.js

32 lines
744 B
JavaScript
Raw Normal View History

2016-11-29 18:54:37 +09:00
import Telescope from 'meteor/nova:lib';
2016-11-29 14:08:24 +01:00
import Users from '../collection.js';
2016-11-29 18:54:37 +09:00
import { graphql } from 'react-apollo';
import gql from 'graphql-tag';
2016-11-29 14:08:24 +01:00
const withCurrentUser = component => {
2016-11-29 18:54:37 +09:00
const preloadedFields = _.compact(_.map(Users.simpleSchema()._schema, (field, fieldName) => {
return field.preload ? fieldName : undefined;
}));
2016-11-29 14:08:24 +01:00
// console.log('preloaded fields', preloadedFields);
2016-11-29 18:54:37 +09:00
return graphql(
gql`query getCurrentUser {
currentUser {
${preloadedFields.join('\n')}
}
}
`, {
props(props) {
const {data: {loading, currentUser}} = props;
return {
loading,
currentUser,
};
},
}
2016-11-29 14:08:24 +01:00
)(component);
2016-11-29 18:54:37 +09:00
};
export default withCurrentUser;