added an asset selector

This commit is contained in:
bill bittner 2018-02-14 12:30:30 -08:00
parent 0548906c4d
commit 7a8466ef68
5 changed files with 14 additions and 14 deletions

View file

@ -1,15 +1,14 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import View from './view'; import View from './view';
import { fileRequested } from 'actions/show'; import { fileRequested } from 'actions/show';
import selectAsset from 'selectors/asset';
const mapStateToProps = ({ show }) => { const mapStateToProps = ({ show }) => {
// select error and status // select error and status
const error = show.displayAsset.error; const error = show.displayAsset.error;
const status = show.displayAsset.status; const status = show.displayAsset.status;
// select asset // select asset
const request = show.requestList[show.request.id]; const asset = selectAsset(show);
const assetKey = request.key;
const asset = show.assetList[assetKey];
// return props // return props
return { return {
error, error,

View file

@ -1,11 +1,10 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import View from './view'; import View from './view';
import selectAsset from 'selectors/asset';
const mapStateToProps = ({ show }) => { const mapStateToProps = ({ show }) => {
// select asset // select asset
const request = show.requestList[show.request.id]; const asset = selectAsset(show);
const assetKey = request.key;
const asset = show.assetList[assetKey];
// return props // return props
return { return {
asset, asset,

View file

@ -1,15 +1,10 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import View from './view'; import View from './view';
import selectAsset from 'selectors/asset';
const mapStateToProps = ({ show }) => { const mapStateToProps = ({ show }) => {
// select title // select title
const request = show.requestList[show.request.id]; const { claimData: { title } } = selectAsset(show);
const assetKey = request.key;
const asset = show.assetList[assetKey];
let title;
if (asset) {
title = asset.claimData.title;
};
// return props // return props
return { return {
title, title,

View file

@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
const AssetTitle = ({title}) => { const AssetTitle = ({ title }) => {
return ( return (
<div> <div>
<span className="text--large">{title}</span> <span className="text--large">{title}</span>

7
react/selectors/asset.js Normal file
View file

@ -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;