Asset reducers

This commit is contained in:
Belen Curcio
2017-01-24 15:10:09 -03:00
parent 365f60c428
commit a409fcbab7
5 changed files with 40 additions and 8 deletions
+8 -4
View File
@@ -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)),
+5
View File
@@ -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})
+3 -1
View File
@@ -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
};
+19
View File
@@ -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;
}
}
+5 -3
View File
@@ -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