Merge branch 'apollo' of https://github.com/TelescopeJS/Telescope into apollo

This commit is contained in:
Sacha Greif 2016-11-23 08:42:18 +09:00
commit 65e74e6e5d
17 changed files with 121 additions and 148 deletions

View file

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

View file

@ -66,7 +66,6 @@ mongo-id@1.0.6
nova:api@0.27.4-nova
nova:apollo@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-styles@0.27.4-nova
nova:categories@0.27.4-nova

View file

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

View file

@ -4,7 +4,7 @@ import classNames from 'classnames';
import Users from 'meteor/nova:users';
import { bindActionCreators } from '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';
class Vote extends Component {
@ -87,4 +87,4 @@ Vote.contextTypes = {
const mapStateToProps = state => ({ messages: state.messages });
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 NovaForm from "meteor/nova:forms";
import Users from 'meteor/nova:users';
import { withUsersSingle } from 'meteor/nova:base-containers';
import { withSingle } from 'meteor/nova:core';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
@ -57,4 +57,4 @@ UsersEditForm.displayName = "UsersEditForm";
const mapStateToProps = state => ({ messages: state.messages, });
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 Users from 'meteor/nova:users';
import { Link } from 'react-router';
import { withUsersSingle } from 'meteor/nova:base-containers';
import { withSingle } from 'meteor/nova:core';
const UsersProfile = (props) => {
console.log(props)
@ -44,4 +44,4 @@ UsersProfile.propTypes = {
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;
// Add notifications options to user profile settings
// Users.addField([
// {
// fieldName: '__notifications_users',
// fieldSchema: {
// label: 'New users',
// type: Boolean,
// optional: true,
// defaultValue: false,
// control: "checkbox",
// insertableIf: Users.isAdmin,
// editableIf: Users.isAdmin,
// group: notificationsGroup
// }
// },
// {
// fieldName: '__notifications_posts',
// fieldSchema: {
// label: 'New posts',
// type: Boolean,
// optional: true,
// defaultValue: false,
// control: "checkbox",
// insertableIf: canInsert,
// editableIf: canEdit,
// group: notificationsGroup
// }
// }
// ]);
Users.addField([
{
fieldName: '__notifications_users',
fieldSchema: {
label: 'New users',
type: Boolean,
optional: true,
defaultValue: false,
control: "checkbox",
insertableIf: Users.isAdmin,
editableIf: Users.isAdmin,
group: notificationsGroup
}
},
{
fieldName: '__notifications_posts',
fieldSchema: {
label: 'New posts',
type: Boolean,
optional: true,
defaultValue: false,
control: "checkbox",
insertableIf: canInsert,
editableIf: canEdit,
group: notificationsGroup
}
}
]);
// if (typeof Comments !== "undefined") {
// Users.addField([
// {
// fieldName: '__notifications_comments',
// fieldSchema: {
// label: 'Comments on my posts',
// type: Boolean,
// optional: true,
// defaultValue: true,
// control: "checkbox",
// insertableIf: canInsert,
// editableIf: canEdit
// }
// },
// {
// fieldName: '__notifications_replies',
// fieldSchema: {
// label: 'Replies to my comments',
// type: Boolean,
// optional: true,
// defaultValue: true,
// control: "checkbox",
// insertableIf: canInsert,
// editableIf: canEdit
// }
// }
// ]);
// }
if (typeof Comments !== "undefined") {
Users.addField([
{
fieldName: '__notifications_comments',
fieldSchema: {
label: 'Comments on my posts',
type: Boolean,
optional: true,
defaultValue: true,
control: "checkbox",
insertableIf: canInsert,
editableIf: canEdit
}
},
{
fieldName: '__notifications_replies',
fieldSchema: {
label: 'Replies to my comments',
type: Boolean,
optional: true,
defaultValue: true,
control: "checkbox",
insertableIf: canInsert,
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 gql from 'graphql-tag';
// to be moved in nova:voting
// Telescope.graphQL.addMutation('postsVote(documentId: String, voteType: String) : Post');
// 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) {
// to adapt like withNew? or withSingle?
export default function withVote(component) {
return graphql(gql`
mutation postsVote($documentId: String, $voteType: String) {
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 './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/cron.js';
import './modules.js';
import withVote from './modules';
export default withVote;