From 7a8466ef68ed21053c9845f6a2b90f528073c121 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 14 Feb 2018 12:30:30 -0800 Subject: [PATCH] added an asset selector --- react/components/AssetDisplay/index.js | 5 ++--- react/components/AssetInfo/index.js | 5 ++--- react/components/AssetTitle/index.js | 9 ++------- react/components/AssetTitle/view.jsx | 2 +- react/selectors/asset.js | 7 +++++++ 5 files changed, 14 insertions(+), 14 deletions(-) create mode 100644 react/selectors/asset.js diff --git a/react/components/AssetDisplay/index.js b/react/components/AssetDisplay/index.js index 2b5c9e26..9a4ab58f 100644 --- a/react/components/AssetDisplay/index.js +++ b/react/components/AssetDisplay/index.js @@ -1,15 +1,14 @@ import { connect } from 'react-redux'; import View from './view'; import { fileRequested } from 'actions/show'; +import selectAsset from 'selectors/asset'; const mapStateToProps = ({ show }) => { // select error and status const error = show.displayAsset.error; const status = show.displayAsset.status; // select asset - const request = show.requestList[show.request.id]; - const assetKey = request.key; - const asset = show.assetList[assetKey]; + const asset = selectAsset(show); // return props return { error, diff --git a/react/components/AssetInfo/index.js b/react/components/AssetInfo/index.js index 792a8040..93a17591 100644 --- a/react/components/AssetInfo/index.js +++ b/react/components/AssetInfo/index.js @@ -1,11 +1,10 @@ import { connect } from 'react-redux'; import View from './view'; +import selectAsset from 'selectors/asset'; const mapStateToProps = ({ show }) => { // select asset - const request = show.requestList[show.request.id]; - const assetKey = request.key; - const asset = show.assetList[assetKey]; + const asset = selectAsset(show); // return props return { asset, diff --git a/react/components/AssetTitle/index.js b/react/components/AssetTitle/index.js index c91886df..76872f6d 100644 --- a/react/components/AssetTitle/index.js +++ b/react/components/AssetTitle/index.js @@ -1,15 +1,10 @@ import { connect } from 'react-redux'; import View from './view'; +import selectAsset from 'selectors/asset'; const mapStateToProps = ({ show }) => { // select title - const request = show.requestList[show.request.id]; - const assetKey = request.key; - const asset = show.assetList[assetKey]; - let title; - if (asset) { - title = asset.claimData.title; - }; + const { claimData: { title } } = selectAsset(show); // return props return { title, diff --git a/react/components/AssetTitle/view.jsx b/react/components/AssetTitle/view.jsx index f943a940..38e59257 100644 --- a/react/components/AssetTitle/view.jsx +++ b/react/components/AssetTitle/view.jsx @@ -1,6 +1,6 @@ import React from 'react'; -const AssetTitle = ({title}) => { +const AssetTitle = ({ title }) => { return (
{title} diff --git a/react/selectors/asset.js b/react/selectors/asset.js new file mode 100644 index 00000000..bee2858c --- /dev/null +++ b/react/selectors/asset.js @@ -0,0 +1,7 @@ +const selectAsset = (show) => { + const request = show.requestList[show.request.id]; + const assetKey = request.key; + return show.assetList[assetKey]; +}; + +export default selectAsset;