From 30b6f8d112c0c3afb9e5faf8188ae7091a4c3602 Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Wed, 25 Jan 2017 11:04:23 -0300 Subject: [PATCH] my Comment History working :tada: : TADA : --- .../containers/ConfigureStreamContainer.js | 6 ++-- client/coral-embed-stream/src/Embed.js | 36 ++----------------- client/coral-framework/client.js | 1 + .../graphql/fragments/commentView.graphql | 0 .../graphql/mutations/deleteAction.graphql | 0 .../graphql/mutations/index.js | 0 .../graphql/mutations/postAction.graphql | 0 .../graphql/mutations/postComment.graphql | 0 .../graphql/queries/index.js | 5 ++- .../graphql/queries/myCommentHistory.graphql | 9 +++++ .../graphql/queries/streamQuery.graphql | 0 client/coral-plugin-history/CommentHistory.js | 12 +++---- .../containers/SettingsContainer.js | 22 +++++++++--- 13 files changed, 42 insertions(+), 49 deletions(-) rename client/{coral-embed-stream/src => coral-framework}/graphql/fragments/commentView.graphql (100%) rename client/{coral-embed-stream/src => coral-framework}/graphql/mutations/deleteAction.graphql (100%) rename client/{coral-embed-stream/src => coral-framework}/graphql/mutations/index.js (100%) rename client/{coral-embed-stream/src => coral-framework}/graphql/mutations/postAction.graphql (100%) rename client/{coral-embed-stream/src => coral-framework}/graphql/mutations/postComment.graphql (100%) rename client/{coral-embed-stream/src => coral-framework}/graphql/queries/index.js (72%) create mode 100644 client/coral-framework/graphql/queries/myCommentHistory.graphql rename client/{coral-embed-stream/src => coral-framework}/graphql/queries/streamQuery.graphql (100%) diff --git a/client/coral-configure/containers/ConfigureStreamContainer.js b/client/coral-configure/containers/ConfigureStreamContainer.js index 90835ab3f..7b4b7c9af 100644 --- a/client/coral-configure/containers/ConfigureStreamContainer.js +++ b/client/coral-configure/containers/ConfigureStreamContainer.js @@ -1,5 +1,6 @@ import React, {Component} from 'react'; import {connect} from 'react-redux'; +import {compose} from 'react-apollo'; import {I18n} from '../../coral-framework'; import {updateOpenStatus, updateConfiguration} from '../../coral-framework/actions/asset'; @@ -89,7 +90,6 @@ const mapDispatchToProps = dispatch => ({ updateConfiguration: newConfig => dispatch(updateConfiguration(newConfig)) }); -export default connect( - mapStateToProps, - mapDispatchToProps +export default compose( + connect(mapStateToProps, mapDispatchToProps) )(ConfigureStreamContainer); diff --git a/client/coral-embed-stream/src/Embed.js b/client/coral-embed-stream/src/Embed.js index bfb09857c..c787b075f 100644 --- a/client/coral-embed-stream/src/Embed.js +++ b/client/coral-embed-stream/src/Embed.js @@ -1,5 +1,4 @@ import React, {Component} from 'react'; -import gql from 'graphql-tag'; import {compose} from 'react-apollo'; import {connect} from 'react-redux'; import {isEqual} from 'lodash'; @@ -10,8 +9,8 @@ const {logout, showSignInDialog} = authActions; const {addNotification, clearNotification} = notificationActions; const {fetchAssetSuccess} = assetActions; -import {queryStream} from './graphql/queries'; -import {postComment, postAction, deleteAction} from './graphql/mutations'; +import {queryStream} from 'coral-framework/graphql/queries'; +import {postComment, postAction, deleteAction} from 'coral-framework/graphql/mutations'; import {Notification, notificationActions, authActions, assetActions, pym} from 'coral-framework'; import Stream from './Stream'; @@ -196,37 +195,6 @@ const mapDispatchToProps = dispatch => ({ dispatch: d => dispatch(d) }); -// import commentView from './graphql/fragments/commentView.graphql'; -// -// Embed.fragments = { -// entry: commentView -// }; - -Embed.fragments = { - entry: gql` - fragment commentView on Comment { - id - body - created_at - user { - id - name: displayName - settings { - bio - } - } - actions { - type: action_type - count - current: current_user { - id - created_at - } - } - } - `, -}; - export default compose( connect(mapStateToProps, mapDispatchToProps), postComment, diff --git a/client/coral-framework/client.js b/client/coral-framework/client.js index 40a539634..b4a7a38df 100644 --- a/client/coral-framework/client.js +++ b/client/coral-framework/client.js @@ -2,6 +2,7 @@ import ApolloClient, {addTypename} from 'apollo-client'; import getNetworkInterface from './transport'; export const client = new ApolloClient({ + connectToDevTools: true, queryTransformer: addTypename, dataIdFromObject: (result) => { if (result.id && result.__typename) { // eslint-disable-line no-underscore-dangle diff --git a/client/coral-embed-stream/src/graphql/fragments/commentView.graphql b/client/coral-framework/graphql/fragments/commentView.graphql similarity index 100% rename from client/coral-embed-stream/src/graphql/fragments/commentView.graphql rename to client/coral-framework/graphql/fragments/commentView.graphql diff --git a/client/coral-embed-stream/src/graphql/mutations/deleteAction.graphql b/client/coral-framework/graphql/mutations/deleteAction.graphql similarity index 100% rename from client/coral-embed-stream/src/graphql/mutations/deleteAction.graphql rename to client/coral-framework/graphql/mutations/deleteAction.graphql diff --git a/client/coral-embed-stream/src/graphql/mutations/index.js b/client/coral-framework/graphql/mutations/index.js similarity index 100% rename from client/coral-embed-stream/src/graphql/mutations/index.js rename to client/coral-framework/graphql/mutations/index.js diff --git a/client/coral-embed-stream/src/graphql/mutations/postAction.graphql b/client/coral-framework/graphql/mutations/postAction.graphql similarity index 100% rename from client/coral-embed-stream/src/graphql/mutations/postAction.graphql rename to client/coral-framework/graphql/mutations/postAction.graphql diff --git a/client/coral-embed-stream/src/graphql/mutations/postComment.graphql b/client/coral-framework/graphql/mutations/postComment.graphql similarity index 100% rename from client/coral-embed-stream/src/graphql/mutations/postComment.graphql rename to client/coral-framework/graphql/mutations/postComment.graphql diff --git a/client/coral-embed-stream/src/graphql/queries/index.js b/client/coral-framework/graphql/queries/index.js similarity index 72% rename from client/coral-embed-stream/src/graphql/queries/index.js rename to client/coral-framework/graphql/queries/index.js index 0bdc6cdaf..727102df9 100644 --- a/client/coral-embed-stream/src/graphql/queries/index.js +++ b/client/coral-framework/graphql/queries/index.js @@ -1,7 +1,8 @@ import {graphql} from 'react-apollo'; import STREAM_QUERY from './streamQuery.graphql'; -import pym from 'coral-framework/PymConnection'; +import MY_COMMENT_HISTORY from './myCommentHistory.graphql'; +import pym from 'coral-framework/PymConnection'; let url = pym.parentUrl.split('#')[0] || 'http://localhost:3000/'; export const queryStream = graphql(STREAM_QUERY, { @@ -11,3 +12,5 @@ export const queryStream = graphql(STREAM_QUERY, { } }) }); + +export const myCommentHistory = graphql(MY_COMMENT_HISTORY, {}); diff --git a/client/coral-framework/graphql/queries/myCommentHistory.graphql b/client/coral-framework/graphql/queries/myCommentHistory.graphql new file mode 100644 index 000000000..6a4309dac --- /dev/null +++ b/client/coral-framework/graphql/queries/myCommentHistory.graphql @@ -0,0 +1,9 @@ +query myCommentHistory { + me { + comments { + id + body + created_at + } + } +} diff --git a/client/coral-embed-stream/src/graphql/queries/streamQuery.graphql b/client/coral-framework/graphql/queries/streamQuery.graphql similarity index 100% rename from client/coral-embed-stream/src/graphql/queries/streamQuery.graphql rename to client/coral-framework/graphql/queries/streamQuery.graphql diff --git a/client/coral-plugin-history/CommentHistory.js b/client/coral-plugin-history/CommentHistory.js index add7c121a..dc505e38a 100644 --- a/client/coral-plugin-history/CommentHistory.js +++ b/client/coral-plugin-history/CommentHistory.js @@ -7,12 +7,12 @@ const CommentHistory = props => {
{props.comments.map((comment, i) => { - const asset = props.assets.find(asset => asset.id === comment.asset_id); - return ; + return
{comment.body}
+ {/*return ;*/} })}
diff --git a/client/coral-settings/containers/SettingsContainer.js b/client/coral-settings/containers/SettingsContainer.js index 6dc2bf3b9..752f01c40 100644 --- a/client/coral-settings/containers/SettingsContainer.js +++ b/client/coral-settings/containers/SettingsContainer.js @@ -1,12 +1,15 @@ import {connect} from 'react-redux'; +import {compose} from 'react-apollo'; import React, {Component} from 'react'; import I18n from 'coral-framework/modules/i18n/i18n'; +import {myCommentHistory} from 'coral-framework/graphql/queries'; import {saveBio} from 'coral-framework/actions/user'; import BioContainer from './BioContainer'; import {TabBar, Tab, TabContent} from 'coral-ui'; import NotLoggedIn from '../components/NotLoggedIn'; +import CommentHistory from 'coral-plugin-history/CommentHistory'; import SettingsHeader from '../components/SettingsHeader'; import RestrictedContent from 'coral-framework/components/RestrictedContent'; @@ -30,9 +33,13 @@ class SettingsContainer extends Component { } render() { - const {loggedIn, userData, showSignInDialog, user} = this.props; + const {loggedIn, userData, showSignInDialog, user, data} = this.props; const {activeTab} = this.state; + if (data.loading) { + return
Loading
+ } + return ( }> @@ -41,7 +48,12 @@ class SettingsContainer extends Component { {lang.t('profileSettings')} - {lang.t('myCommentHistory')} + { + data.me.comments.length ? + + : +

{lang.t('user-no-comment')}

+ }
@@ -59,7 +71,7 @@ const mapDispatchToProps = dispatch => ({ saveBio: (user_id, formData) => dispatch(saveBio(user_id, formData)) }); -export default connect( - mapStateToProps, - mapDispatchToProps +export default compose( + connect(mapStateToProps, mapDispatchToProps), + myCommentHistory )(SettingsContainer);