diff --git a/client/coral-embed-stream/src/CommentStream.js b/client/coral-embed-stream/src/CommentStream.js index f1eb8743b..4750f5880 100644 --- a/client/coral-embed-stream/src/CommentStream.js +++ b/client/coral-embed-stream/src/CommentStream.js @@ -1,6 +1,6 @@ import React, {Component, PropTypes} from 'react'; import Pym from 'pym.js'; -import {graphql} from 'react-apollo'; +import {graphql, compose} from 'react-apollo'; import {connect} from 'react-redux'; import gql from 'graphql-tag'; @@ -59,7 +59,7 @@ class CommentStream extends Component { } static propTypes = { - data: PropTypes.object.isRequired, + data: PropTypes.object.isRequired } componentDidMount () { @@ -324,24 +324,29 @@ class CommentStream extends Component { } const mapStateToProps = state => (state); +const mapDispatchToProps = (dispatch, ownProps) => ({}); -const mapDispatchToProps = (dispatch) => ({ - addItem: (item, item_id) => dispatch(addItem(item, item_id)), - updateItem: (id, property, value, itemType) => dispatch(updateItem(id, property, value, itemType)), - postItem: (data, type, id) => dispatch(postItem(data, type, id)), - getStream: (rootId) => dispatch(getStream(rootId)), - addNotification: (type, text) => dispatch(addNotification(type, text)), - clearNotification: () => dispatch(clearNotification()), - postAction: (item, itemType, action) => dispatch(postAction(item, itemType, action)), - showSignInDialog: (offset) => dispatch(showSignInDialog(offset)), - deleteAction: (item, action, user, itemType) => dispatch(deleteAction(item, action, user, itemType)), - appendItemArray: (item, property, value, addToFront, itemType) => dispatch(appendItemArray(item, property, value, addToFront, itemType)), - handleSignInDialog: () => dispatch(authActions.showSignInDialog()), - logout: () => dispatch(logout()), -}); +// const mapDispatchToProps = (dispatch, ownProps) => ({ +// addItem: (item, item_id) => dispatch(addItem(item, item_id)), +// updateItem: (id, property, value, itemType) => dispatch(updateItem(id, property, value, itemType)), +// postItem: (data, type, id) => { +// console.log('postItem', dispatch, ownProps) +// // dispatch(postItem(data, type, id, ownProps)) +// }, +// getStream: (rootId) => dispatch(getStream(rootId)), +// addNotification: (type, text) => dispatch(addNotification(type, text)), +// clearNotification: () => dispatch(clearNotification()), +// postAction: (item, itemType, action) => dispatch(postAction(item, itemType, action)), +// showSignInDialog: (offset) => dispatch(showSignInDialog(offset)), +// deleteAction: (item, action, user, itemType) => dispatch(deleteAction(item, action, user, itemType)), +// appendItemArray: (item, property, value, addToFront, itemType) => dispatch(appendItemArray(item, property, value, addToFront, itemType)), +// handleSignInDialog: () => dispatch(authActions.showSignInDialog()), +// logout: () => dispatch(logout()), +// }); // Initialize GraphQL queries or mutations with the `gql` tag -const StreamQuery = gql`fragment commentView on Comment { +const StreamQuery = gql` +fragment commentView on Comment { id body user { @@ -385,19 +390,27 @@ query AssetQuery($asset_id: ID!) { id, displayName } -}`; +} +`; -const CommentStreamWithData = graphql( - StreamQuery, { - options: { - variables: { - asset_id: assetID +const postComment = gql` + mutation CreateComment ($asset_id: ID!, $parent_id: ID, $body: String!) { + createComment(asset_id:$asset_id, parent_id:$parent_id, body:$body) { + ...commentView } } - } -)(CommentStream); +`; -export default connect( - mapStateToProps, - mapDispatchToProps -)(CommentStreamWithData); +export default compose( + graphql(StreamQuery, { + options: { variables: { asset_id: assetID } }, + props: props => props, + }), + graphql(postComment, { + options: { variables: { asset_id: assetID } }, + props: ({ownProps, mutate}) => ({ + postComment: (data) => mutate(data) + }), + }), + connect(mapStateToProps, mapDispatchToProps) +)(CommentStream); diff --git a/client/coral-framework/actions/items.js b/client/coral-framework/actions/items.js index 48418b2a2..78e3f64b7 100644 --- a/client/coral-framework/actions/items.js +++ b/client/coral-framework/actions/items.js @@ -2,6 +2,8 @@ import coralApi from '../helpers/response'; import {fromJS} from 'immutable'; import {UPDATE_CONFIG} from '../constants/config'; +import gql from 'graphql-tag'; + /** * Action name constants */ @@ -189,17 +191,43 @@ export function getItemsArray (ids) { * The newly put item to the item store */ -export function postItem (item, type, id) { - return (dispatch) => { - if (id) { - item.id = id; + +const postComment = gql` + mutation CreateComment ($asset_id: ID!, $parent_id: ID, $body: String!) { + createComment(asset_id:$asset_id, parent_id:$parent_id, body:$body) { + ...commentView } - return coralApi(`/${type}`, {method: 'POST', body: item}) - .then((json) => { - dispatch(addItem({...item, id:json.id}, type)); - return json; - }); - }; + } +`; + +export function postItem (item, type, id, mutate) { + console.log( + item, + type, + id, + mutate + ) + mutate({ + variables: { + asset_id: id, + body: item, + parent_id: null + } + }).then(({data}) => { + console.log('it workt'); + console.log(data); + }); + + // return (dispatch) => { + // if (id) { + // item.id = id; + // } + // return coralApi(`/${type}`, {method: 'POST', body: item}) + // .then((json) => { + // dispatch(addItem({...item, id:json.id}, type)); + // return json; + // }); + // }; } /* diff --git a/client/coral-framework/store.js b/client/coral-framework/store.js index 9b9ecfb21..af942ecdd 100644 --- a/client/coral-framework/store.js +++ b/client/coral-framework/store.js @@ -8,6 +8,13 @@ export default createStore( auth: authReducer, apollo: client.reducer() }), + { + apollo: { + data: { + loading: true, + } + } + }, compose( applyMiddleware(thunk), window.devToolsExtension && window.devToolsExtension()