From a409fcbab7bfa65a74416ad2805ab4a8c2f7b5a3 Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Tue, 24 Jan 2017 15:10:09 -0300 Subject: [PATCH] Asset reducers --- client/coral-embed-stream/src/Embed.js | 12 ++++++++---- client/coral-framework/actions/asset.js | 5 +++++ client/coral-framework/index.js | 4 +++- client/coral-framework/reducers/asset.js | 19 +++++++++++++++++++ client/coral-framework/reducers/index.js | 8 +++++--- 5 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 client/coral-framework/actions/asset.js create mode 100644 client/coral-framework/reducers/asset.js diff --git a/client/coral-embed-stream/src/Embed.js b/client/coral-embed-stream/src/Embed.js index 0713843ad..7aa4cadb6 100644 --- a/client/coral-embed-stream/src/Embed.js +++ b/client/coral-embed-stream/src/Embed.js @@ -1,15 +1,17 @@ import React, {Component, PropTypes} from 'react'; import {compose} from 'react-apollo'; import {connect} from 'react-redux'; +import {isEqual} from 'lodash' import {TabBar, Tab, TabContent, Spinner} from '../../coral-ui'; const {logout, showSignInDialog} = authActions; const {addNotification, clearNotification} = notificationActions; +const {fetchAssetSuccess} = assetActions import {queryStream} from './graphql/queries'; import {postComment, postAction, deleteAction} from './graphql/mutations'; -import {Notification, notificationActions, authActions} from 'coral-framework'; +import {Notification, notificationActions, authActions, assetActions} from 'coral-framework'; import Stream from './Stream'; import InfoBox from 'coral-plugin-infobox/InfoBox'; @@ -49,10 +51,11 @@ class Embed extends Component { } componentWillReceiveProps (nextProps) { - if (nextProps.data != null) { - console.log(nextProps.data) + const {loadAsset} = this.props + if(!isEqual(nextProps.data.asset, this.props.data.asset)) { + loadAsset(nextProps.data.asset) } - } + } render () { const {activeTab} = this.state; @@ -155,6 +158,7 @@ const mapStateToProps = state => ({ }); const mapDispatchToProps = dispatch => ({ + loadAsset: (asset) => dispatch(fetchAssetSuccess(asset)), addNotification: (type, text) => dispatch(addNotification(type, text)), clearNotification: () => dispatch(clearNotification()), showSignInDialog: (offset) => dispatch(showSignInDialog(offset)), diff --git a/client/coral-framework/actions/asset.js b/client/coral-framework/actions/asset.js new file mode 100644 index 000000000..84de482ee --- /dev/null +++ b/client/coral-framework/actions/asset.js @@ -0,0 +1,5 @@ +import * as actions from '../constants/asset'; + +export const fetchAssetRequest = () => ({type: actions.FETCH_ASSET_REQUEST}); +export const fetchAssetSuccess = asset => ({type: actions.FETCH_ASSET_SUCCESS, asset}); +export const fetchAssetFailure = error => ({type: actions.FETCH_ASSET_FAILURE, error}) diff --git a/client/coral-framework/index.js b/client/coral-framework/index.js index 9a679d969..6ab7c6325 100644 --- a/client/coral-framework/index.js +++ b/client/coral-framework/index.js @@ -5,6 +5,7 @@ import I18n from './modules/i18n/i18n'; import * as notificationActions from './actions/notification'; import * as authActions from './actions/auth'; import * as configActions from './actions/config'; +import * as assetActions from './actions/asset'; export { Notification, @@ -13,5 +14,6 @@ export { I18n, notificationActions, authActions, - configActions + configActions, + assetActions }; diff --git a/client/coral-framework/reducers/asset.js b/client/coral-framework/reducers/asset.js new file mode 100644 index 000000000..fe3257998 --- /dev/null +++ b/client/coral-framework/reducers/asset.js @@ -0,0 +1,19 @@ +import {Map} from 'immutable'; +import * as actions from '../constants/asset'; + +const initialState = Map({ + closedAt: null, + settings: null, + title: null, + url: null +}); + +export default function asset (state = initialState, action) { + switch (action.type) { + case actions.FETCH_ASSET_SUCCESS : + return state + .merge(action.asset); + default : + return state; + } +} diff --git a/client/coral-framework/reducers/index.js b/client/coral-framework/reducers/index.js index c75b7020d..b16b8c01a 100644 --- a/client/coral-framework/reducers/index.js +++ b/client/coral-framework/reducers/index.js @@ -1,12 +1,14 @@ -import config from './config'; -import items from './items'; -import notification from './notification'; import auth from './auth'; import user from './user'; +import asset from './asset'; +import items from './items'; +import config from './config'; +import notification from './notification'; export default { auth, user, + asset, items, config, notification