mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 01:51:40 -05:00
put withCurrentUser back in nova:core after all…
This commit is contained in:
parent
0c2b9da97c
commit
b16c7ce0be
26 changed files with 90 additions and 85 deletions
|
@ -25,7 +25,7 @@ nova:subscribe
|
|||
|
||||
############ Debug Packages ############
|
||||
|
||||
# nova:debug
|
||||
nova:debug
|
||||
# nova:kadira
|
||||
|
||||
############ Theme Packages ############
|
||||
|
|
|
@ -69,6 +69,7 @@ nova:base-styles@0.27.4-nova
|
|||
nova:categories@0.27.4-nova
|
||||
nova:comments@0.27.4-nova
|
||||
nova:core@0.27.4-nova
|
||||
nova:debug@0.27.4-nova
|
||||
nova:email@0.27.4-nova
|
||||
nova:email-templates@0.27.4-nova
|
||||
nova:embedly@0.27.4-nova
|
||||
|
|
|
@ -11,7 +11,7 @@ import { Button } from 'react-bootstrap';
|
|||
import { ModalTrigger } from 'meteor/nova:core';
|
||||
import MoviesEditForm from './MoviesEditForm.jsx';
|
||||
import MoviesDetails from './MoviesDetails.jsx';
|
||||
import { withCurrentUser } from 'meteor/nova:users';
|
||||
import { withCurrentUser } from 'meteor/nova:core';
|
||||
import Movies from '../collection.js';
|
||||
import gql from 'graphql-tag';
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ import Movies from '../collection.js';
|
|||
import MoviesNewForm from './MoviesNewForm.jsx';
|
||||
import { compose } from 'react-apollo';
|
||||
import { withList } from 'meteor/nova:core';
|
||||
import { withCurrentUser } from 'meteor/nova:users';
|
||||
import { withCurrentUser } from 'meteor/nova:core';
|
||||
|
||||
const LoadMore = props => <a href="#" className="load-more button button--primary" onClick={props.loadMore}>Load More ({props.count}/{props.totalCount})</a>
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import Users from 'meteor/nova:users';
|
|||
import { bindActionCreators } from 'redux';
|
||||
import { connect } from 'react-redux';
|
||||
import NovaForm from "meteor/nova:forms";
|
||||
import { withCurrentUser } from 'meteor/nova:users';
|
||||
import { withCurrentUser } from 'meteor/nova:core';
|
||||
|
||||
class CommentsItem extends Component{
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import Telescope from 'meteor/nova:lib';
|
||||
import React from 'react';
|
||||
import { withCurrentUser } from 'meteor/nova:users';
|
||||
import { withCurrentUser } from 'meteor/nova:core';
|
||||
|
||||
const Header = (props, context) => {
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import Cookie from 'react-cookie';
|
|||
import Users from 'meteor/nova:users';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { connect } from 'react-redux';
|
||||
import { withCurrentUser } from 'meteor/nova:users';
|
||||
import { withCurrentUser } from 'meteor/nova:core';
|
||||
|
||||
class Newsletter extends Component {
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import classNames from 'classnames';
|
|||
import Users from 'meteor/nova:users';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { connect } from 'react-redux';
|
||||
import { withCurrentUser } from 'meteor/nova:users';
|
||||
import { withCurrentUser } from 'meteor/nova:core';
|
||||
import { withVote, hasUpvoted, hasDownvoted } from 'meteor/nova:voting';
|
||||
|
||||
class Vote extends Component {
|
||||
|
|
|
@ -2,7 +2,7 @@ import Telescope from 'meteor/nova:lib';
|
|||
import React, { PropTypes } from 'react';
|
||||
import { FormattedMessage } from 'react-intl';
|
||||
import Users from 'meteor/nova:users';
|
||||
import { withCurrentUser } from 'meteor/nova:users';
|
||||
import { withCurrentUser } from 'meteor/nova:core';
|
||||
|
||||
const CanDo = (props, context) => {
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import Telescope from 'meteor/nova:lib';
|
|||
import React from 'react';
|
||||
import {FormattedMessage } from 'react-intl';
|
||||
import { ModalTrigger, withList } from 'meteor/nova:core';
|
||||
import { withCurrentUser } from 'meteor/nova:users';
|
||||
import { withCurrentUser } from 'meteor/nova:core';
|
||||
import Comments from 'meteor/nova:comments';
|
||||
import gql from 'graphql-tag';
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import { ModalTrigger } from "meteor/nova:core";
|
|||
import { Link } from 'react-router';
|
||||
import Posts from "meteor/nova:posts";
|
||||
import Users from 'meteor/nova:users';
|
||||
import { withCurrentUser } from 'meteor/nova:users';
|
||||
import { withCurrentUser } from 'meteor/nova:core';
|
||||
import gql from 'graphql-tag';
|
||||
|
||||
class PostsItem extends Component {
|
||||
|
|
|
@ -4,7 +4,7 @@ import { FormattedMessage, intlShape } from 'react-intl';
|
|||
import { Button } from 'react-bootstrap';
|
||||
import { ModalTrigger } from "meteor/nova:core";
|
||||
import Posts from "meteor/nova:posts";
|
||||
import { withCurrentUser } from 'meteor/nova:users';
|
||||
import { withCurrentUser } from 'meteor/nova:core';
|
||||
|
||||
const PostsNewButton = (props, context) => {
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import { Button, ButtonGroup, DropdownButton, MenuItem } from 'react-bootstrap';
|
|||
import { LinkContainer } from 'react-router-bootstrap';
|
||||
import { withRouter } from 'react-router'
|
||||
import Users from 'meteor/nova:users';
|
||||
import { withCurrentUser } from 'meteor/nova:users';
|
||||
import { withCurrentUser } from 'meteor/nova:core';
|
||||
|
||||
const PostsViews = (props, context) => {
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import Telescope from 'meteor/nova:lib';
|
||||
import React from 'react';
|
||||
import Users from 'meteor/nova:users';
|
||||
import { withCurrentUser } from 'meteor/nova:users';
|
||||
import { withCurrentUser } from 'meteor/nova:core';
|
||||
|
||||
const UsersAccount = (props, context) => {
|
||||
const terms = props.params.slug ? {slug: props.params.slug} : props.currentUser ? {userId: props.currentUser._id } : {};
|
||||
|
|
|
@ -5,7 +5,7 @@ import { Meteor } from 'meteor/meteor';
|
|||
import { Dropdown, MenuItem } from 'react-bootstrap';
|
||||
import { LinkContainer } from 'react-router-bootstrap';
|
||||
import Users from 'meteor/nova:users';
|
||||
import { withCurrentUser } from 'meteor/nova:users';
|
||||
import { withCurrentUser } from 'meteor/nova:core';
|
||||
import { withApollo } from 'react-apollo';
|
||||
|
||||
class UsersMenu extends Component {
|
||||
|
|
|
@ -5,7 +5,7 @@ import { Modal } from 'react-bootstrap';
|
|||
import NovaForm from "meteor/nova:forms";
|
||||
import { withRouter } from 'react-router'
|
||||
import Users from 'meteor/nova:users';
|
||||
import { withCurrentUser } from 'meteor/nova:users';
|
||||
import { withCurrentUser } from 'meteor/nova:core';
|
||||
|
||||
const UsersProfileCheckModal = ({show, router, currentUser}, context) => {
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import Telescope from 'meteor/nova:lib';
|
|||
import React, { Component } from 'react';
|
||||
import { Accounts, STATES } from 'meteor/std:accounts-ui';
|
||||
import { Link } from 'react-router';
|
||||
import { withCurrentUser } from 'meteor/nova:users';
|
||||
import { withCurrentUser } from 'meteor/nova:core';
|
||||
|
||||
class UsersResetPassword extends Component {
|
||||
componentDidMount() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import Telescope from 'meteor/nova:lib';
|
||||
import React, { PropTypes, Component } from 'react';
|
||||
import { IntlProvider, intlShape} from 'react-intl';
|
||||
import { loadCurrentUser } from 'meteor/nova:users';
|
||||
import withApp from '../containers/withApp.js';
|
||||
|
||||
class App extends Component {
|
||||
|
||||
|
@ -43,6 +43,6 @@ App.childContextTypes = {
|
|||
intl: intlShape,
|
||||
}
|
||||
|
||||
Telescope.registerComponent('App', App, loadCurrentUser);
|
||||
Telescope.registerComponent('App', App, withApp);
|
||||
|
||||
export default App;
|
|
@ -1,31 +1,37 @@
|
|||
// import React from 'react';
|
||||
// import { graphql } from 'react-apollo';
|
||||
// import gql from 'graphql-tag';
|
||||
// import Users from 'meteor/nova:users';
|
||||
import Users from 'meteor/nova:users';
|
||||
import { graphql } from 'react-apollo';
|
||||
import gql from 'graphql-tag';
|
||||
|
||||
// export default function withApp(component, options) {
|
||||
// return graphql(gql`
|
||||
// query getCurrentUser {
|
||||
// currentUser {
|
||||
// ...fullUserInfo
|
||||
// }
|
||||
// }
|
||||
// ${Users.fragments.full}
|
||||
// `, {
|
||||
// options(ownProps) {
|
||||
// return {
|
||||
// variables: {},
|
||||
// pollInterval: 20000,
|
||||
// };
|
||||
// },
|
||||
// props(props) {
|
||||
// const {data: {loading, currentUser}} = props;
|
||||
// return {
|
||||
// loading,
|
||||
// currentUser,
|
||||
// };
|
||||
// },
|
||||
// })(component)
|
||||
// };
|
||||
const withApp = component => {
|
||||
|
||||
// module.exports = withApp;
|
||||
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')}
|
||||
}
|
||||
}
|
||||
`, {
|
||||
options(ownProps) {
|
||||
return {
|
||||
variables: {},
|
||||
pollInterval: 20000,
|
||||
};
|
||||
},
|
||||
props(props) {
|
||||
const {data: {loading, currentUser}} = props;
|
||||
return {
|
||||
loading,
|
||||
currentUser,
|
||||
};
|
||||
},
|
||||
}
|
||||
)(component);
|
||||
};
|
||||
|
||||
export default withApp;
|
||||
|
|
30
packages/nova-core/lib/containers/withCurrentUser.js
Normal file
30
packages/nova-core/lib/containers/withCurrentUser.js
Normal file
|
@ -0,0 +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';
|
||||
|
||||
/**
|
||||
* withCurrentUser - HOC to give access to the currentUser as a prop of a WrappedComponent
|
||||
**/
|
||||
export default function withCurrentUser(WrappedComponent) {
|
||||
|
||||
class WithCurrentUser extends Component {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
}
|
||||
|
||||
render() {
|
||||
const {client} = this.context; // grab the apollo client from the context
|
||||
|
||||
const currentUser = client ? client.store.getState().apollo.data[`User${Meteor.userId()}`] : null;
|
||||
|
||||
return currentUser ? <WrappedComponent currentUser={currentUser} {...this.props} /> : <WrappedComponent {...this.props} />;
|
||||
}
|
||||
}
|
||||
|
||||
WithCurrentUser.contextTypes = { client: PropTypes.object.isRequired };
|
||||
WithCurrentUser.displayName = `withCurrentUser(${Telescope.utils.getComponentDisplayName(WrappedComponent)}`;
|
||||
WithCurrentUser.WrappedComponent = WrappedComponent;
|
||||
|
||||
return hoistStatics(WithCurrentUser, WrappedComponent);
|
||||
}
|
|
@ -13,4 +13,5 @@ export { default as withList } from './containers/withList.js';
|
|||
export { default as withSingle } from './containers/withSingle.js';
|
||||
export { default as withNew } from './containers/withNew.js';
|
||||
export { default as withEdit } from './containers/withEdit.js';
|
||||
export { default as withRemove } from './containers/withRemove.js';
|
||||
export { default as withRemove } from './containers/withRemove.js';
|
||||
export { default as withCurrentUser } from './containers/withCurrentUser.js';
|
||||
|
|
|
@ -28,7 +28,7 @@ import Telescope from 'meteor/nova:lib';
|
|||
import React, { PropTypes, Component } from 'react';
|
||||
import { intlShape } from 'react-intl';
|
||||
import { withApollo, compose } from 'react-apollo';
|
||||
import { withCurrentUser } from 'meteor/nova:users';
|
||||
import { withCurrentUser } from 'meteor/nova:core';
|
||||
import { withNew, withEdit, withRemove } from 'meteor/nova:core';
|
||||
import { getEditableFields, getInsertableFields } from './utils.js';
|
||||
import Form from './Form.jsx';
|
||||
|
|
|
@ -107,7 +107,7 @@ const schema = {
|
|||
max: 3000,
|
||||
viewableIf: ['anonymous'],
|
||||
insertableIf: ['default'],
|
||||
editableIf: (user, document) => Users.isAdmin(user) || Users.isOwner(user, document),
|
||||
editableIf: ['default'],
|
||||
control: "textarea",
|
||||
publish: true,
|
||||
order: 30
|
||||
|
@ -154,7 +154,7 @@ const schema = {
|
|||
type: Number,
|
||||
optional: true,
|
||||
publish: true,
|
||||
viewableIf: (user, document) => Users.isAdmin(user) || Users.isOwner(user, document),
|
||||
viewableIf: ['admins'],
|
||||
defaultValue: 0
|
||||
},
|
||||
/**
|
||||
|
|
|
@ -4,7 +4,7 @@ import Telescope from 'meteor/nova:lib';
|
|||
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { connect } from 'react-redux';
|
||||
import { withCurrentUser } from 'meteor/nova:users';
|
||||
import { withCurrentUser } from 'meteor/nova:core';
|
||||
|
||||
class SubscribeTo extends Component {
|
||||
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
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;
|
|
@ -9,4 +9,3 @@ import './permissions.js';
|
|||
|
||||
export default Users;
|
||||
export { default as withCurrentUser } from './containers/withCurrentUser.js';
|
||||
export { default as loadCurrentUser } from './containers/loadCurrentUser.js';
|
||||
|
|
Loading…
Add table
Reference in a new issue