removed showAsset action
This commit is contained in:
parent
aedc636241
commit
855a7dab42
8 changed files with 44 additions and 79 deletions
|
@ -39,30 +39,18 @@ export function updateRequestWithAssetRequest (name, id, channelName, channelId,
|
||||||
|
|
||||||
export function newAssetRequest (id, name, modifier) {
|
export function newAssetRequest (id, name, modifier) {
|
||||||
return {
|
return {
|
||||||
type: actions.ASSET_REQUEST_ASYNC,
|
type: actions.ASSET_REQUEST_NEW,
|
||||||
data: { id, name, modifier },
|
data: { id, name, modifier },
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export function addAssetRequest (id, error, name, claimId) {
|
export function addRequestToAssetRequests (id, error, name, claimId) {
|
||||||
return {
|
return {
|
||||||
type: actions.ASSET_REQUEST_SUCCESS,
|
type: actions.ASSET_REQUEST_SUCCESS,
|
||||||
data: { id, error, name, claimId },
|
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) {
|
export function addAssetToAssetList (id, error, name, claimId, shortId, claimData) {
|
||||||
return {
|
return {
|
||||||
type: actions.ASSET_NEW_SUCCESS,
|
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 {
|
return {
|
||||||
type: actions.CHANNEL_REQUEST_SUCCESS,
|
type: actions.CHANNEL_REQUEST_SUCCESS,
|
||||||
data: { id, error, name, longId, shortId },
|
data: { id, error, name, longId, shortId },
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import Request from 'utils/request';
|
import Request from 'utils/request';
|
||||||
|
|
||||||
export function getLongClaimId (name, modifier) {
|
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 = {};
|
let body = {};
|
||||||
// create request params
|
// create request params
|
||||||
if (modifier) {
|
if (modifier) {
|
||||||
|
@ -27,13 +27,13 @@ export function getLongClaimId (name, modifier) {
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getShortId (name, claimId) {
|
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}`;
|
const url = `/api/claim/short-id/${claimId}/${name}`;
|
||||||
return Request(url);
|
return Request(url);
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getClaimData (name, claimId) {
|
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}`;
|
const url = `/api/claim/data/${name}/${claimId}`;
|
||||||
return Request(url);
|
return Request(url);
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,7 +4,7 @@ export const REQUEST_UPDATE_CLAIM = 'REQUEST_UPDATE_CLAIM';
|
||||||
export const REQUEST_ERROR = 'REQUEST_ERROR';
|
export const REQUEST_ERROR = 'REQUEST_ERROR';
|
||||||
|
|
||||||
// asset actions
|
// 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_REQUEST_SUCCESS = 'ASSET_REQUEST_SUCCESS';
|
||||||
|
|
||||||
export const ASSET_NEW_ASYNC = 'ASSET_NEW_ASYNC';
|
export const ASSET_NEW_ASYNC = 'ASSET_NEW_ASYNC';
|
||||||
|
|
|
@ -9,14 +9,15 @@ const mapStateToProps = ({ show }) => {
|
||||||
const requestName = show.request.data.name;
|
const requestName = show.request.data.name;
|
||||||
const requestModifier = show.request.data.modifier;
|
const requestModifier = show.request.data.modifier;
|
||||||
const requestExtension = show.request.data.extension;
|
const requestExtension = show.request.data.extension;
|
||||||
// select request
|
const assetList = show.assetList;
|
||||||
const previousRequest = show.assetRequests[show.request.id] || null;
|
|
||||||
// select asset info
|
// select asset info
|
||||||
|
const previousRequest = show.assetRequests[show.request.id] || null;
|
||||||
let asset;
|
let asset;
|
||||||
if (previousRequest) {
|
if (previousRequest) {
|
||||||
const assetKey = `a#${previousRequest.name}#${previousRequest.claimId}`; // note: just store this in the request
|
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 props
|
||||||
return {
|
return {
|
||||||
requestType,
|
requestType,
|
||||||
|
@ -24,7 +25,6 @@ const mapStateToProps = ({ show }) => {
|
||||||
requestName,
|
requestName,
|
||||||
requestModifier,
|
requestModifier,
|
||||||
requestExtension,
|
requestExtension,
|
||||||
previousRequest,
|
|
||||||
asset,
|
asset,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -35,10 +35,6 @@ const mapDispatchToProps = dispatch => {
|
||||||
onNewRequest: (id, name, modifier) => {
|
onNewRequest: (id, name, modifier) => {
|
||||||
dispatch(newAssetRequest(id, name, modifier));
|
dispatch(newAssetRequest(id, name, modifier));
|
||||||
},
|
},
|
||||||
// show asset
|
|
||||||
onShowNewAsset: (name, claimId) => {
|
|
||||||
dispatch(showNewAsset(name, claimId));
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -11,25 +11,17 @@ function requestIsAnAssetRequest ({ requestType }) {
|
||||||
|
|
||||||
class ShowAsset extends React.Component {
|
class ShowAsset extends React.Component {
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
const { asset, previousRequest, requestId, requestName, requestModifier } = this.props;
|
const { asset, requestId, requestName, requestModifier } = this.props;
|
||||||
if (!previousRequest) { // case: the asset request does not exist
|
if (!asset) { // case: the asset info does not exist
|
||||||
return this.props.onNewRequest(requestId, requestName, requestModifier);
|
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) {
|
componentWillReceiveProps (nextProps) {
|
||||||
if (requestIsAnAssetRequest(nextProps)) {
|
if (requestIsAnAssetRequest(nextProps)) {
|
||||||
const { asset, previousRequest, requestId, requestName, requestModifier } = nextProps;
|
const { asset, requestId, requestName, requestModifier } = nextProps;
|
||||||
if (!previousRequest) {
|
if (!asset) { // case: the asset info does not exist
|
||||||
return this.props.onNewRequest(requestId, requestName, requestModifier);
|
return this.props.onNewRequest(requestId, requestName, requestModifier);
|
||||||
};
|
};
|
||||||
if (!asset) {
|
|
||||||
const { name, claimId } = previousRequest;
|
|
||||||
return this.props.onShowNewAsset(name, claimId);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
render () {
|
render () {
|
||||||
|
|
|
@ -2,13 +2,11 @@ import { all } from 'redux-saga/effects';
|
||||||
import { watchNewAssetRequest, watchNewChannelRequest } from './request';
|
import { watchNewAssetRequest, watchNewChannelRequest } from './request';
|
||||||
import { watchFileIsRequested } from './file';
|
import { watchFileIsRequested } from './file';
|
||||||
import { watchShowNewChannel, watchShowNewChannelClaimsRequest } from './show_channel';
|
import { watchShowNewChannel, watchShowNewChannelClaimsRequest } from './show_channel';
|
||||||
import { watchShowNewAsset } from './show_asset';
|
|
||||||
|
|
||||||
export default function* rootSaga () {
|
export default function* rootSaga () {
|
||||||
yield all([
|
yield all([
|
||||||
watchNewAssetRequest(),
|
watchNewAssetRequest(),
|
||||||
watchNewChannelRequest(),
|
watchNewChannelRequest(),
|
||||||
watchShowNewAsset(),
|
|
||||||
watchShowNewChannel(),
|
watchShowNewChannel(),
|
||||||
watchFileIsRequested(),
|
watchFileIsRequested(),
|
||||||
watchShowNewChannelClaimsRequest(),
|
watchShowNewChannelClaimsRequest(),
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
import { call, put, takeLatest } from 'redux-saga/effects';
|
import { call, put, takeLatest } from 'redux-saga/effects';
|
||||||
import * as actions from 'constants/show_action_types';
|
import * as actions from 'constants/show_action_types';
|
||||||
import { addAssetRequest, updateRequestError, showNewAsset, addChannelRequest, showNewChannel } from 'actions/show';
|
import { addRequestToAssetRequests, updateRequestError, addRequestToChannelRequests, showNewChannel, addAssetToAssetList } from 'actions/show';
|
||||||
import { getLongClaimId } from 'api/assetApi';
|
import { getLongClaimId, getShortId, getClaimData } from 'api/assetApi';
|
||||||
import { getChannelData } from 'api/channelApi';
|
import { getChannelData } from 'api/channelApi';
|
||||||
|
|
||||||
function* newAssetRequest (action) {
|
function* newAssetRequest (action) {
|
||||||
const { id, name, modifier } = action.data;
|
const { id, name, modifier } = action.data;
|
||||||
console.log('getting asset long id');
|
// get long id
|
||||||
|
console.log(`getting asset long id ${name}`);
|
||||||
let longId;
|
let longId;
|
||||||
try {
|
try {
|
||||||
({data: longId} = yield call(getLongClaimId, name, modifier));
|
({data: longId} = yield call(getLongClaimId, name, modifier));
|
||||||
|
@ -14,8 +15,29 @@ function* newAssetRequest (action) {
|
||||||
console.log('error:', error);
|
console.log('error:', error);
|
||||||
return yield put(updateRequestError(error.message));
|
return yield put(updateRequestError(error.message));
|
||||||
}
|
}
|
||||||
yield put(addAssetRequest(id, null, name, longId));
|
// put action to add request to asset request list
|
||||||
yield put(showNewAsset(name, longId));
|
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) {
|
function* newChannelRequest (action) {
|
||||||
|
@ -25,16 +47,15 @@ function* newChannelRequest (action) {
|
||||||
try {
|
try {
|
||||||
({data} = yield call(getChannelData, name, channelId));
|
({data} = yield call(getChannelData, name, channelId));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// return yield put(addChannelRequest(id, error.message, null, null, null));
|
|
||||||
return yield put(updateRequestError(error.message));
|
return yield put(updateRequestError(error.message));
|
||||||
}
|
}
|
||||||
const { longChannelClaimId: longId, shortChannelClaimId: shortId } = data;
|
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));
|
yield put(showNewChannel(name, shortId, longId));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function* watchNewAssetRequest () {
|
export function* watchNewAssetRequest () {
|
||||||
yield takeLatest(actions.ASSET_REQUEST_ASYNC, newAssetRequest);
|
yield takeLatest(actions.ASSET_REQUEST_NEW, newAssetRequest);
|
||||||
};
|
};
|
||||||
|
|
||||||
export function* watchNewChannelRequest () {
|
export function* watchNewChannelRequest () {
|
||||||
|
|
|
@ -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);
|
|
||||||
};
|
|
Loading…
Reference in a new issue