removed showAsset action

This commit is contained in:
bill bittner 2018-02-13 15:53:27 -08:00
parent aedc636241
commit 855a7dab42
8 changed files with 44 additions and 79 deletions

View file

@ -39,30 +39,18 @@ export function updateRequestWithAssetRequest (name, id, channelName, channelId,
export function newAssetRequest (id, name, modifier) {
return {
type: actions.ASSET_REQUEST_ASYNC,
type: actions.ASSET_REQUEST_NEW,
data: { id, name, modifier },
};
};
export function addAssetRequest (id, error, name, claimId) {
export function addRequestToAssetRequests (id, error, name, claimId) {
return {
type: actions.ASSET_REQUEST_SUCCESS,
data: { id, error, name, claimId },
};
};
// show an asset
export function showNewAsset (name, claimId) {
const id = `a#${name}#${claimId}`;
return {
type: actions.ASSET_NEW_ASYNC,
data: { id, name, claimId },
};
};
// add asset to asset list
export function addAssetToAssetList (id, error, name, claimId, shortId, claimData) {
return {
type: actions.ASSET_NEW_SUCCESS,
@ -79,7 +67,7 @@ export function newChannelRequest (id, name, channelId) {
};
};
export function addChannelRequest (id, error, name, longId, shortId) {
export function addRequestToChannelRequests (id, error, name, longId, shortId) {
return {
type: actions.CHANNEL_REQUEST_SUCCESS,
data: { id, error, name, longId, shortId },

View file

@ -1,7 +1,7 @@
import Request from 'utils/request';
export function getLongClaimId (name, modifier) {
console.log('getting long claim id for asset:', name, modifier);
// console.log('getting long claim id for asset:', name, modifier);
let body = {};
// create request params
if (modifier) {
@ -27,13 +27,13 @@ export function getLongClaimId (name, modifier) {
};
export function getShortId (name, claimId) {
console.log('getting short id for asset:', name, claimId);
// console.log('getting short id for asset:', name, claimId);
const url = `/api/claim/short-id/${claimId}/${name}`;
return Request(url);
};
export function getClaimData (name, claimId) {
console.log('getting claim data for asset:', name, claimId);
// console.log('getting claim data for asset:', name, claimId);
const url = `/api/claim/data/${name}/${claimId}`;
return Request(url);
};

View file

@ -4,7 +4,7 @@ export const REQUEST_UPDATE_CLAIM = 'REQUEST_UPDATE_CLAIM';
export const REQUEST_ERROR = 'REQUEST_ERROR';
// asset actions
export const ASSET_REQUEST_ASYNC = 'ASSET_REQUEST_ASYNC';
export const ASSET_REQUEST_NEW = 'ASSET_REQUEST_NEW';
export const ASSET_REQUEST_SUCCESS = 'ASSET_REQUEST_SUCCESS';
export const ASSET_NEW_ASYNC = 'ASSET_NEW_ASYNC';

View file

@ -9,14 +9,15 @@ const mapStateToProps = ({ show }) => {
const requestName = show.request.data.name;
const requestModifier = show.request.data.modifier;
const requestExtension = show.request.data.extension;
// select request
const previousRequest = show.assetRequests[show.request.id] || null;
const assetList = show.assetList;
// select asset info
const previousRequest = show.assetRequests[show.request.id] || null;
let asset;
if (previousRequest) {
const assetKey = `a#${previousRequest.name}#${previousRequest.claimId}`; // note: just store this in the request
asset = show.assetList[assetKey] || null;
asset = assetList[assetKey] || null;
};
// console.log('previousRequest:', previousRequest, 'asset:', asset, 'asset list', assetList);
// return props
return {
requestType,
@ -24,7 +25,6 @@ const mapStateToProps = ({ show }) => {
requestName,
requestModifier,
requestExtension,
previousRequest,
asset,
};
};
@ -35,10 +35,6 @@ const mapDispatchToProps = dispatch => {
onNewRequest: (id, name, modifier) => {
dispatch(newAssetRequest(id, name, modifier));
},
// show asset
onShowNewAsset: (name, claimId) => {
dispatch(showNewAsset(name, claimId));
},
};
};

View file

@ -11,25 +11,17 @@ function requestIsAnAssetRequest ({ requestType }) {
class ShowAsset extends React.Component {
componentDidMount () {
const { asset, previousRequest, requestId, requestName, requestModifier } = this.props;
if (!previousRequest) { // case: the asset request does not exist
const { asset, requestId, requestName, requestModifier } = this.props;
if (!asset) { // case: the asset info does not exist
return this.props.onNewRequest(requestId, requestName, requestModifier);
};
if (!asset) { // case: the asset request does not exist
const { name, claimId } = previousRequest;
return this.props.onShowNewAsset(name, claimId);
};
}
componentWillReceiveProps (nextProps) {
if (requestIsAnAssetRequest(nextProps)) {
const { asset, previousRequest, requestId, requestName, requestModifier } = nextProps;
if (!previousRequest) {
const { asset, requestId, requestName, requestModifier } = nextProps;
if (!asset) { // case: the asset info does not exist
return this.props.onNewRequest(requestId, requestName, requestModifier);
};
if (!asset) {
const { name, claimId } = previousRequest;
return this.props.onShowNewAsset(name, claimId);
};
}
}
render () {

View file

@ -2,13 +2,11 @@ import { all } from 'redux-saga/effects';
import { watchNewAssetRequest, watchNewChannelRequest } from './request';
import { watchFileIsRequested } from './file';
import { watchShowNewChannel, watchShowNewChannelClaimsRequest } from './show_channel';
import { watchShowNewAsset } from './show_asset';
export default function* rootSaga () {
yield all([
watchNewAssetRequest(),
watchNewChannelRequest(),
watchShowNewAsset(),
watchShowNewChannel(),
watchFileIsRequested(),
watchShowNewChannelClaimsRequest(),

View file

@ -1,12 +1,13 @@
import { call, put, takeLatest } from 'redux-saga/effects';
import * as actions from 'constants/show_action_types';
import { addAssetRequest, updateRequestError, showNewAsset, addChannelRequest, showNewChannel } from 'actions/show';
import { getLongClaimId } from 'api/assetApi';
import { addRequestToAssetRequests, updateRequestError, addRequestToChannelRequests, showNewChannel, addAssetToAssetList } from 'actions/show';
import { getLongClaimId, getShortId, getClaimData } from 'api/assetApi';
import { getChannelData } from 'api/channelApi';
function* newAssetRequest (action) {
const { id, name, modifier } = action.data;
console.log('getting asset long id');
// get long id
console.log(`getting asset long id ${name}`);
let longId;
try {
({data: longId} = yield call(getLongClaimId, name, modifier));
@ -14,8 +15,29 @@ function* newAssetRequest (action) {
console.log('error:', error);
return yield put(updateRequestError(error.message));
}
yield put(addAssetRequest(id, null, name, longId));
yield put(showNewAsset(name, longId));
// put action to add request to asset request list
yield put(addRequestToAssetRequests(id, null, name, longId));
// get short Id
console.log(`getting asset short id ${name} ${longId}`);
let shortId;
try {
({data: shortId} = yield call(getShortId, name, longId));
} catch (error) {
return yield put(updateRequestError(error.message));
}
// get claim data
console.log(`getting asset claim data ${name} ${longId}`);
let claimData;
try {
({data: claimData} = yield call(getClaimData, name, longId));
} catch (error) {
return yield put(updateRequestError(error.message));
}
// put action to add asset to asset list
const assetKey = `a#${name}#${longId}`;
yield put(addAssetToAssetList(assetKey, null, name, longId, shortId, claimData));
// clear any errors in request error
yield put(updateRequestError(null));
};
function* newChannelRequest (action) {
@ -25,16 +47,15 @@ function* newChannelRequest (action) {
try {
({data} = yield call(getChannelData, name, channelId));
} catch (error) {
// return yield put(addChannelRequest(id, error.message, null, null, null));
return yield put(updateRequestError(error.message));
}
const { longChannelClaimId: longId, shortChannelClaimId: shortId } = data;
yield put(addChannelRequest(id, null, name, longId, shortId));
yield put(addRequestToChannelRequests(id, null, name, longId, shortId));
yield put(showNewChannel(name, shortId, longId));
}
export function* watchNewAssetRequest () {
yield takeLatest(actions.ASSET_REQUEST_ASYNC, newAssetRequest);
yield takeLatest(actions.ASSET_REQUEST_NEW, newAssetRequest);
};
export function* watchNewChannelRequest () {

View file

@ -1,30 +0,0 @@
import { call, put, takeLatest } from 'redux-saga/effects';
import * as actions from 'constants/show_action_types';
import { updateRequestError, addAssetToAssetList } from 'actions/show';
import { getShortId, getClaimData } from 'api/assetApi';
function* getAssetDataAndShowAsset (action) {
const {id, name, claimId} = action.data;
// get short Id
console.log('getting short id');
let shortId;
try {
({data: shortId} = yield call(getShortId, name, claimId));
} catch (error) {
return yield put(updateRequestError(error.message));
}
// if no error, get claim data
console.log('getting claim data');
let claimData;
try {
({data: claimData} = yield call(getClaimData, name, claimId));
} catch (error) {
return yield put(updateRequestError(error.message));
}
yield put(addAssetToAssetList(id, null, name, claimId, shortId, claimData));
yield put(updateRequestError(null));
}
export function* watchShowNewAsset () {
yield takeLatest(actions.ASSET_NEW_ASYNC, getAssetDataAndShowAsset);
};