spee.ch/react/containers/ShowAsset/index.js

46 lines
1.2 KiB
JavaScript
Raw Normal View History

import { connect } from 'react-redux';
import View from './view';
import { newAssetRequest, showNewAsset } from 'actions/show';
const mapStateToProps = ({ show }) => {
2018-02-13 04:01:29 +01:00
// select request info
const requestType = show.request.type;
const requestId = show.request.id;
const requestName = show.request.data.name;
const requestModifier = show.request.data.modifier;
const requestExtension = show.request.data.extension;
// select request
2018-02-13 04:01:29 +01:00
const previousRequest = show.assetRequests[show.request.id] || null;
// select asset info
2018-02-13 04:01:29 +01:00
let asset;
if (previousRequest) {
const assetKey = `a#${previousRequest.name}#${previousRequest.claimId}`; // note: just store this in the request
asset = show.assetList[assetKey] || null;
};
// return props
return {
requestType,
requestId,
requestName,
requestModifier,
requestExtension,
previousRequest,
asset,
};
};
2018-02-03 03:16:18 +01:00
const mapDispatchToProps = dispatch => {
return {
2018-02-09 01:23:09 +01:00
// request
onNewRequest: (id, name, modifier) => {
dispatch(newAssetRequest(id, name, modifier));
2018-02-07 22:26:07 +01:00
},
2018-02-09 01:23:09 +01:00
// show asset
onShowNewAsset: (name, claimId) => {
dispatch(showNewAsset(name, claimId));
},
2018-02-03 03:16:18 +01:00
};
};
export default connect(mapStateToProps, mapDispatchToProps)(View);