get rid of nova:base-containers, move graphql vote-related code to nova:voting, undo mistake on some user fields

This commit is contained in:
xavcz 2016-11-22 18:39:50 -05:00
parent 1137fb96aa
commit 22dd58114b
18 changed files with 121 additions and 161 deletions

View file

@ -28,7 +28,6 @@ nova:apollo # do not remove!
############ Customizable Packages ############ ############ Customizable Packages ############
nova:base-containers # default data containers
nova:base-components # default ui components nova:base-components # default ui components
nova:base-styles # default styling nova:base-styles # default styling
nova:base-routes # default routes nova:base-routes # default routes

View file

@ -66,7 +66,6 @@ mongo-id@1.0.6
nova:api@0.27.4-nova nova:api@0.27.4-nova
nova:apollo@0.27.4-nova nova:apollo@0.27.4-nova
nova:base-components@0.27.4-nova nova:base-components@0.27.4-nova
nova:base-containers@0.27.4-nova
nova:base-routes@0.27.4-nova nova:base-routes@0.27.4-nova
nova:base-styles@0.27.4-nova nova:base-styles@0.27.4-nova
nova:categories@0.27.4-nova nova:categories@0.27.4-nova

View file

@ -1,18 +1,5 @@
import Telescope from 'meteor/nova:lib'; import Telescope from 'meteor/nova:lib';
console.log(`
${Telescope.graphQL.getCollectionsSchemas()}
${Telescope.graphQL.getAdditionalSchemas()}
type Query {
${Telescope.graphQL.queries.join('\n')}
}
type Mutation {
${Telescope.graphQL.mutations.join('\n')}
}
`);
const generateTypeDefs = () => [` const generateTypeDefs = () => [`
${Telescope.graphQL.getCollectionsSchemas()} ${Telescope.graphQL.getCollectionsSchemas()}
${Telescope.graphQL.getAdditionalSchemas()} ${Telescope.graphQL.getAdditionalSchemas()}

View file

@ -82,8 +82,8 @@ const currentUserContainer = graphql(
__htmlBio __htmlBio
__karma __karma
__newsletter_subscribeToNewsletter __newsletter_subscribeToNewsletter
#__notifications_users __notifications_users
#__notifications_posts __notifications_posts
__postCount __postCount
__slug __slug
__twitterUsername __twitterUsername

View file

@ -4,7 +4,7 @@ import classNames from 'classnames';
import Users from 'meteor/nova:users'; import Users from 'meteor/nova:users';
import { bindActionCreators } from 'redux'; import { bindActionCreators } from 'redux';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { withVoteMutation } from 'meteor/nova:base-containers'; import withVote from 'meteor/nova:voting';
import { withCurrentUser } from 'meteor/nova:core'; import { withCurrentUser } from 'meteor/nova:core';
class Vote extends Component { class Vote extends Component {
@ -87,4 +87,4 @@ Vote.contextTypes = {
const mapStateToProps = state => ({ messages: state.messages }); const mapStateToProps = state => ({ messages: state.messages });
const mapDispatchToProps = dispatch => bindActionCreators(Telescope.actions.messages, dispatch); const mapDispatchToProps = dispatch => bindActionCreators(Telescope.actions.messages, dispatch);
Telescope.registerComponent('Vote', Vote, withCurrentUser, connect(mapStateToProps, mapDispatchToProps), withVoteMutation); Telescope.registerComponent('Vote', Vote, withCurrentUser, connect(mapStateToProps, mapDispatchToProps), withVote);

View file

@ -4,7 +4,7 @@ import { FormattedMessage, intlShape } from 'react-intl';
import { Row, Col } from 'react-bootstrap'; import { Row, Col } from 'react-bootstrap';
import NovaForm from "meteor/nova:forms"; import NovaForm from "meteor/nova:forms";
import Users from 'meteor/nova:users'; import Users from 'meteor/nova:users';
import { withUsersSingle } from 'meteor/nova:base-containers'; import { withSingle } from 'meteor/nova:core';
import { bindActionCreators } from 'redux'; import { bindActionCreators } from 'redux';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
@ -57,4 +57,4 @@ UsersEditForm.displayName = "UsersEditForm";
const mapStateToProps = state => ({ messages: state.messages, }); const mapStateToProps = state => ({ messages: state.messages, });
const mapDispatchToProps = dispatch => bindActionCreators(Telescope.actions.messages, dispatch); const mapDispatchToProps = dispatch => bindActionCreators(Telescope.actions.messages, dispatch);
Telescope.registerComponent('UsersEditForm', UsersEditForm, connect(mapStateToProps, mapDispatchToProps)/*, withUsersSingle*/); Telescope.registerComponent('UsersEditForm', UsersEditForm, connect(mapStateToProps, mapDispatchToProps)/*, withSingle*/);

View file

@ -4,7 +4,7 @@ import { FormattedMessage } from 'react-intl';
import Posts from "meteor/nova:posts"; import Posts from "meteor/nova:posts";
import Users from 'meteor/nova:users'; import Users from 'meteor/nova:users';
import { Link } from 'react-router'; import { Link } from 'react-router';
import { withUsersSingle } from 'meteor/nova:base-containers'; import { withSingle } from 'meteor/nova:core';
const UsersProfile = (props) => { const UsersProfile = (props) => {
console.log(props) console.log(props)
@ -44,4 +44,4 @@ UsersProfile.propTypes = {
UsersProfile.displayName = "UsersProfile"; UsersProfile.displayName = "UsersProfile";
Telescope.registerComponent('UsersProfile', UsersProfile/*, withUsersSingle*/); Telescope.registerComponent('UsersProfile', UsersProfile/*, withSingle*/);

View file

@ -1 +0,0 @@
Nova basic React containers: they fetch data thanks to Apollo and give them back to React components in `nova:base-components`.

View file

@ -1,7 +0,0 @@
import withVoteMutation from './mutations/withVoteMutation.js';
export {
// mutation containers
withVoteMutation,
}

View file

@ -1,7 +0,0 @@
import withVoteMutation from './mutations/withVoteMutation.js';
export {
// mutation containers
withVoteMutation,
}

View file

@ -1,24 +0,0 @@
Package.describe({
name: "nova:base-containers",
summary: "Telescope containers package",
version: "0.27.4-nova",
git: "https://github.com/TelescopeJS/Telescope.git"
});
Package.onUse(function (api) {
api.versionsFrom(['METEOR@1.0']);
api.use([
// Nova packages
'nova:core@0.27.4-nova',
'nova:posts@0.27.4-nova',
'nova:users@0.27.4-nova',
'nova:comments@0.27.4-nova',
'nova:categories@0.27.4-nova',
]);
api.mainModule("lib/server.js", "server");
api.mainModule("lib/client.js", "client");
});

View file

@ -11,60 +11,60 @@ const canInsert = user => Users.canDo(user, "users.new");
const canEdit = Users.canEdit; const canEdit = Users.canEdit;
// Add notifications options to user profile settings // Add notifications options to user profile settings
// Users.addField([ Users.addField([
// { {
// fieldName: '__notifications_users', fieldName: '__notifications_users',
// fieldSchema: { fieldSchema: {
// label: 'New users', label: 'New users',
// type: Boolean, type: Boolean,
// optional: true, optional: true,
// defaultValue: false, defaultValue: false,
// control: "checkbox", control: "checkbox",
// insertableIf: Users.isAdmin, insertableIf: Users.isAdmin,
// editableIf: Users.isAdmin, editableIf: Users.isAdmin,
// group: notificationsGroup group: notificationsGroup
// } }
// }, },
// { {
// fieldName: '__notifications_posts', fieldName: '__notifications_posts',
// fieldSchema: { fieldSchema: {
// label: 'New posts', label: 'New posts',
// type: Boolean, type: Boolean,
// optional: true, optional: true,
// defaultValue: false, defaultValue: false,
// control: "checkbox", control: "checkbox",
// insertableIf: canInsert, insertableIf: canInsert,
// editableIf: canEdit, editableIf: canEdit,
// group: notificationsGroup group: notificationsGroup
// } }
// } }
// ]); ]);
// if (typeof Comments !== "undefined") { if (typeof Comments !== "undefined") {
// Users.addField([ Users.addField([
// { {
// fieldName: '__notifications_comments', fieldName: '__notifications_comments',
// fieldSchema: { fieldSchema: {
// label: 'Comments on my posts', label: 'Comments on my posts',
// type: Boolean, type: Boolean,
// optional: true, optional: true,
// defaultValue: true, defaultValue: true,
// control: "checkbox", control: "checkbox",
// insertableIf: canInsert, insertableIf: canInsert,
// editableIf: canEdit editableIf: canEdit
// } }
// }, },
// { {
// fieldName: '__notifications_replies', fieldName: '__notifications_replies',
// fieldSchema: { fieldSchema: {
// label: 'Replies to my comments', label: 'Replies to my comments',
// type: Boolean, type: Boolean,
// optional: true, optional: true,
// defaultValue: true, defaultValue: true,
// control: "checkbox", control: "checkbox",
// insertableIf: canInsert, insertableIf: canInsert,
// editableIf: canEdit editableIf: canEdit
// } }
// } }
// ]); ]);
// } }

View file

@ -1 +1,3 @@
import './modules'; import withVote from './modules';
export default withVote;

View file

@ -3,16 +3,8 @@ import React, { PropTypes, Component } from 'react';
import { graphql } from 'react-apollo'; import { graphql } from 'react-apollo';
import gql from 'graphql-tag'; import gql from 'graphql-tag';
// to be moved in nova:voting // to adapt like withNew? or withSingle?
// Telescope.graphQL.addMutation('postsVote(documentId: String, voteType: String) : Post'); export default function withVote(component) {
// postsVote(root, {documentId, voteType}, context) {
// Meteor._sleepForMs(2000); // wait 2 seconds for demonstration purpose
// console.log("sleep done");
// const post = Posts.findOne(documentId);
// return context.Users.canDo(context.currentUser, `posts.${voteType}`) ? Telescope.operateOnItem(context.Posts, post, context.currentUser, voteType) : false;
// },
export default function withVoteMutation (component, options) {
return graphql(gql` return graphql(gql`
mutation postsVote($documentId: String, $voteType: String) { mutation postsVote($documentId: String, $voteType: String) {
postsVote(documentId: $documentId, voteType: $voteType) { postsVote(documentId: $documentId, voteType: $voteType) {

View file

@ -0,0 +1,44 @@
import Telescope from 'meteor/nova:lib';
/**
* @summary Vote schema
* @type {SimpleSchema}
*/
Telescope.schemas.votes = new SimpleSchema({
itemId: {
type: String
},
power: {
type: Number,
optional: true
},
votedAt: {
type: Date,
optional: true
}
});
const voteSchema = `
type Vote {
itemId: String
power: Float
votedAt: String
}
`;
Telescope.graphQL.addSchema(voteSchema);
Telescope.graphQL.addMutation('postsVote(documentId: String, voteType: String) : Post');
const voteResolver = {
Mutation: {
postsVote(root, {documentId, voteType}, context) {
Meteor._sleepForMs(2000); // wait 2 seconds for demonstration purpose
console.log("sleep done");
const post = Posts.findOne(documentId);
return context.Users.canDo(context.currentUser, `posts.${voteType}`) ? Telescope.operateOnItem(context.Posts, post, context.currentUser, voteType) : false;
},
},
};
Telescope.graphQL.addResolvers(voteResolver);

View file

@ -1,3 +1,6 @@
import './schema.js'; import './graphql.js';
import './custom_fields.js'; import './custom_fields.js';
import './vote.js'; import './vote.js';
import withVote from './containers/withVote.js';
export default withVote;

View file

@ -1,29 +0,0 @@
import Telescope from 'meteor/nova:lib';
/**
* @summary Vote schema
* @type {SimpleSchema}
*/
Telescope.schemas.votes = new SimpleSchema({
itemId: {
type: String
},
power: {
type: Number,
optional: true
},
votedAt: {
type: Date,
optional: true
}
});
const voteSchema = `
type Vote {
itemId: String
power: Float
votedAt: String
}
`;
Telescope.graphQL.addSchema(voteSchema);

View file

@ -1,4 +1,6 @@
import './server/scoring.js'; import './server/scoring.js';
import './server/cron.js'; import './server/cron.js';
import './modules.js'; import withVote from './modules';
export default withVote;