split showing asset and adding asset actions

This commit is contained in:
bill bittner 2018-02-08 11:22:19 -08:00
parent 0fcdba8290
commit 0a3e052564
8 changed files with 60 additions and 45 deletions

View file

@ -60,10 +60,10 @@ export function showNewAsset (id, name, claimId) {
};
};
export function updateShowAsset (id, error, name, claimId, shortId, claimData) {
export function updateShowAsset (error, name, claimId, shortId, claimData) {
return {
type: actions.SHOW_ASSET_UPDATE,
data: { id, error, name, claimId, shortId, claimData },
data: { error, name, claimId, shortId, claimData },
};
};
@ -73,6 +73,15 @@ export function clearShowAsset () {
};
};
// add asset to asset list
export function addAssetToAssetList (id, error, name, claimId, shortId, claimData) {
return {
type: actions.ASSET_LIST_ADD,
data: { id, error, name, claimId, shortId, claimData },
};
}
// request for a channel
export function newChannelRequest (id, name, channelId) {
@ -94,22 +103,15 @@ export function addChannelRequest (id, error, name, longId, shortId) {
export function showNewChannel (id, name, longId, channelData) {
return {
type: actions.SHOW_CHANNEL_NEW,
data: { id, name, longId, channelData},
data: { id, name, longId, channelData },
};
};
// export function showExistingChannel (existingChannel) {
// return {
// type: actions.SHOW_CHANNEL_EXISTING,
// data: { existingChannel },
// };
// };
export function updateShowChannel (error, channelData, claimData) {
return {
type: actions.SHOW_CHANNEL_UPDATE,
data: { error, channelData, claimData },
}
};
};
export function clearShowChannel () {

View file

@ -1,20 +1,19 @@
// request actions
export const REQUEST_CHANNEL_UPDATE = 'REQUEST_CHANNEL_UPDATE';
export const REQUEST_CLAIM_UPDATE = 'REQUEST_CLAIM_UPDATE';
export const REQUEST_ERROR_UPDATE = 'REQUEST_ERROR_UPDATE';
export const SHOW_ASSET_UPDATE = 'SHOW_ASSET_UPDATE';
export const FILE_REQUESTED = 'FILE_REQUESTED';
export const FILE_AVAILABILITY_UPDATE = 'FILE_AVAILABILITY_UPDATE';
export const DISPLAY_ASSET_ERROR = 'DISPLAY_ASSET_ERROR';
// new
// asset request actions
export const ASSET_REQUEST_NEW = 'ASSET_REQUEST_NEW';
export const ASSET_REQUEST_ADD = 'ASSET_REQUEST_ADD';
export const SHOW_ASSET_NEW = 'SHOW_ASSET_NEW';
export const SHOW_ASSET_UPDATE = 'SHOW_ASSET_UPDATE';
export const SHOW_ASSET_CLEAR = 'SHOW_ASSET_CLEAR';
export const ASSET_LIST_ADD = `ASSET_LIST_ADD`;
// channel request actions
export const CHANNEL_REQUEST_NEW = 'CHANNEL_REQUEST_NEW';
export const CHANNEL_REQUEST_ADD = 'CHANNEL_REQUEST_ADD';
@ -23,3 +22,8 @@ export const SHOW_CHANNEL_UPDATE = 'SHOW_CHANNEL_UPDATE';
export const SHOW_CHANNEL_CLEAR = 'SHOW_CHANNEL_CLEAR';
export const CHANNEL_LIST_ADD = 'CHANNEL_LIST_ADD';
// asset/file display actions
export const FILE_REQUESTED = 'FILE_REQUESTED';
export const FILE_AVAILABILITY_UPDATE = 'FILE_AVAILABILITY_UPDATE';
export const DISPLAY_ASSET_ERROR = 'DISPLAY_ASSET_ERROR';

View file

@ -30,8 +30,8 @@ const mapDispatchToProps = dispatch => {
onShowNewAsset: (id, name, claimId) => {
dispatch(showNewAsset(id, name, claimId));
},
onShowExistingAsset: (id, error, name, claimId, shortId, claimData) => {
dispatch(updateShowAsset(id, error, name, claimId, shortId, claimData));
onShowExistingAsset: (error, name, claimId, shortId, claimData) => {
dispatch(updateShowAsset(error, name, claimId, shortId, claimData));
},
onLeaveShowAsset: () => {
dispatch(clearShowAsset()); // clear any errors

View file

@ -52,7 +52,7 @@ class ShowAsset extends React.Component {
const assetId = `a#${name}#${claimId}`;
const existingAssetRecord = assets[assetId];
if (existingAssetRecord) { // case: the asset data already exists
this.showExistingAsset(assetId, existingAssetRecord);
this.showExistingAsset(existingAssetRecord);
} else { // case: the asset data does not exist yet
this.showNewAsset(assetId, name, claimId);
}
@ -60,9 +60,9 @@ class ShowAsset extends React.Component {
showNewAsset (assetId, name, claimId) {
this.props.onShowNewAsset(assetId, name, claimId);
}
showExistingAsset (assetId, existingAssetRecord) {
showExistingAsset (existingAssetRecord) {
let { error, name, claimId, shortId, claimData } = existingAssetRecord;
this.props.onShowExistingAsset(assetId, error, name, claimId, shortId, claimData);
this.props.onShowExistingAsset(error, name, claimId, shortId, claimData);
}
componentWillUnmount () {
this.props.onLeaveShowAsset();

View file

@ -1,5 +1,5 @@
import { connect } from 'react-redux';
import {newChannelRequest, updateRequestError, showNewChannel, clearShowChannel} from 'actions/show';
import {newChannelRequest, updateRequestError, showNewChannel, updateShowChannel, clearShowChannel} from 'actions/show';
import View from './view';
const mapStateToProps = ({ show }) => {
@ -30,8 +30,8 @@ const mapDispatchToProps = dispatch => {
onShowNewChannel: (id, name, longId) => {
dispatch(showNewChannel(id, name, longId));
},
onShowExistingChannel: () => {
onShowExistingChannel: (error, channelData, claimData) => {
dispatch(updateShowChannel(error, channelData, claimData));
},
onShowChannelClear: () => {
dispatch(clearShowChannel());

View file

@ -56,7 +56,8 @@ class ShowChannel extends React.Component {
this.props.onShowNewChannel(channelRecordId, name, longId);
};
showExistingChannel (existingChannel) {
this.props.onShowExistingChannel(existingChannel);
const { error, channelData, claimData } = existingChannel;
this.props.onShowExistingChannel(error, channelData, claimData);
};
componentWillUnmount () {
this.props.onShowChannelClear();

View file

@ -92,15 +92,6 @@ export default function (state = initialState, action) {
// show an asset
case actions.SHOW_ASSET_UPDATE:
return Object.assign({}, state, {
assets: Object.assign({}, state.assets, {
[action.data.id]: {
error : action.data.error,
name : action.data.name,
claimId : action.data.claimId,
shortId : action.data.shortId,
claimData: action.data.claimData,
},
}),
showAsset: Object.assign({}, state.showAsset, {
error : action.data.error,
name : action.data.name,
@ -119,6 +110,19 @@ export default function (state = initialState, action) {
claimData: null,
}),
});
// add asset to asset list
case actions.ASSET_LIST_ADD:
return Object.assign({}, state, {
assetList: Object.assign({}, state.assetList, {
[action.data.id]: {
error : action.data.error,
name : action.data.name,
claimId : action.data.claimId,
shortId : action.data.shortId,
claimData: action.data.claimData,
},
}),
});
// request a channel
case actions.CHANNEL_REQUEST_ADD:
return Object.assign({}, state, {

View file

@ -1,6 +1,6 @@
import { call, put, takeLatest } from 'redux-saga/effects';
import * as actions from 'constants/show_action_types';
import { addAssetRequest, updateShowAsset, showNewAsset, addChannelRequest, showNewChannel, updateShowChannel, addNewChannelToChannelList, updateFileAvailability, updateDisplayAssetError } from 'actions/show';
import { addAssetRequest, showNewAsset, updateShowAsset, addAssetToAssetList, addChannelRequest, showNewChannel, updateShowChannel, addNewChannelToChannelList, updateFileAvailability, updateDisplayAssetError } from 'actions/show';
import { UNAVAILABLE, AVAILABLE } from 'constants/asset_display_states';
import { checkFileAvailability, triggerClaimGet } from 'api/fileApi';
import { getLongClaimId, getShortId, getClaimData } from 'api/assetApi';
@ -29,10 +29,12 @@ function* getAssetDataAndShowAsset (action) {
try {
({success, message, data: shortId} = yield call(getShortId, name, claimId));
} catch (error) {
return yield put(updateShowAsset(id, error.message, null, null, null)); // add with error
return yield put(updateShowAsset(error.message, name, claimId));
// yield put(addAssetToAssetList(arg1, arg2));
}
if (!success) {
return yield put(updateShowAsset(id, message, null, null, null)); // add with error
return yield put(updateShowAsset(message, name, claimId));
// yield put(addAssetToAssetList(arg1, arg2));
}
// if no error, get claim data
success = null;
@ -40,14 +42,16 @@ function* getAssetDataAndShowAsset (action) {
try {
({success, message, data: claimData} = yield call(getClaimData, name, claimId));
} catch (error) {
return yield put(updateShowAsset(id, error.message, null, null, null)); // add with error
return yield put(updateShowAsset(error.message, name, claimId));
// yield put(addAssetToAssetList(arg1, arg2));
}
if (!success) {
return yield put(updateShowAsset(id, message, null, null, null)); // add with error
return yield put(updateShowAsset(message, name, claimId));
// yield put(addAssetToAssetList(arg1, arg2));
}
// if both are successfull, add to asset list and select for showing
yield put(updateShowAsset(id, null, name, claimId, shortId, claimData));
// yield put(addAssetToAssetList(arg1, arg2));
yield put(updateShowAsset(null, name, claimId, shortId, claimData));
yield put(addAssetToAssetList(id, null, name, claimId, shortId, claimData));
}
function* retrieveFile (action) {
@ -105,11 +109,11 @@ function* getNewChannelDataAndShowChannel (action) {
try {
({ success, message, data: claimsData } = yield call(getChannelClaims, name, longId, 1));
} catch (error) {
return yield put(updateShowChannel(error.message, channelData, null));
return yield put(updateShowChannel(error.message, channelData));
// yield put(addNewChannelToChannelList(id, error.message, null, null));
}
if (!success) {
return yield put(updateShowChannel(message, channelData, null));
return yield put(updateShowChannel(message, channelData));
// yield put(addNewChannelToChannelList(id, message, null, null));
}
yield put(updateShowChannel(null, channelData, claimsData));