split showing asset and adding asset actions
This commit is contained in:
parent
0fcdba8290
commit
0a3e052564
8 changed files with 60 additions and 45 deletions
|
@ -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 {
|
return {
|
||||||
type: actions.SHOW_ASSET_UPDATE,
|
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
|
// request for a channel
|
||||||
|
|
||||||
export function newChannelRequest (id, name, channelId) {
|
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) {
|
export function showNewChannel (id, name, longId, channelData) {
|
||||||
return {
|
return {
|
||||||
type: actions.SHOW_CHANNEL_NEW,
|
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) {
|
export function updateShowChannel (error, channelData, claimData) {
|
||||||
return {
|
return {
|
||||||
type: actions.SHOW_CHANNEL_UPDATE,
|
type: actions.SHOW_CHANNEL_UPDATE,
|
||||||
data: { error, channelData, claimData },
|
data: { error, channelData, claimData },
|
||||||
}
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export function clearShowChannel () {
|
export function clearShowChannel () {
|
||||||
|
|
|
@ -1,20 +1,19 @@
|
||||||
|
// request actions
|
||||||
export const REQUEST_CHANNEL_UPDATE = 'REQUEST_CHANNEL_UPDATE';
|
export const REQUEST_CHANNEL_UPDATE = 'REQUEST_CHANNEL_UPDATE';
|
||||||
export const REQUEST_CLAIM_UPDATE = 'REQUEST_CLAIM_UPDATE';
|
export const REQUEST_CLAIM_UPDATE = 'REQUEST_CLAIM_UPDATE';
|
||||||
export const REQUEST_ERROR_UPDATE = 'REQUEST_ERROR_UPDATE';
|
export const REQUEST_ERROR_UPDATE = 'REQUEST_ERROR_UPDATE';
|
||||||
|
|
||||||
export const SHOW_ASSET_UPDATE = 'SHOW_ASSET_UPDATE';
|
// asset request actions
|
||||||
|
|
||||||
export const FILE_REQUESTED = 'FILE_REQUESTED';
|
|
||||||
export const FILE_AVAILABILITY_UPDATE = 'FILE_AVAILABILITY_UPDATE';
|
|
||||||
export const DISPLAY_ASSET_ERROR = 'DISPLAY_ASSET_ERROR';
|
|
||||||
|
|
||||||
// new
|
|
||||||
export const ASSET_REQUEST_NEW = 'ASSET_REQUEST_NEW';
|
export const ASSET_REQUEST_NEW = 'ASSET_REQUEST_NEW';
|
||||||
export const ASSET_REQUEST_ADD = 'ASSET_REQUEST_ADD';
|
export const ASSET_REQUEST_ADD = 'ASSET_REQUEST_ADD';
|
||||||
|
|
||||||
export const SHOW_ASSET_NEW = 'SHOW_ASSET_NEW';
|
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 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_NEW = 'CHANNEL_REQUEST_NEW';
|
||||||
export const CHANNEL_REQUEST_ADD = 'CHANNEL_REQUEST_ADD';
|
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 SHOW_CHANNEL_CLEAR = 'SHOW_CHANNEL_CLEAR';
|
||||||
|
|
||||||
export const CHANNEL_LIST_ADD = 'CHANNEL_LIST_ADD';
|
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';
|
||||||
|
|
|
@ -30,8 +30,8 @@ const mapDispatchToProps = dispatch => {
|
||||||
onShowNewAsset: (id, name, claimId) => {
|
onShowNewAsset: (id, name, claimId) => {
|
||||||
dispatch(showNewAsset(id, name, claimId));
|
dispatch(showNewAsset(id, name, claimId));
|
||||||
},
|
},
|
||||||
onShowExistingAsset: (id, error, name, claimId, shortId, claimData) => {
|
onShowExistingAsset: (error, name, claimId, shortId, claimData) => {
|
||||||
dispatch(updateShowAsset(id, error, name, claimId, shortId, claimData));
|
dispatch(updateShowAsset(error, name, claimId, shortId, claimData));
|
||||||
},
|
},
|
||||||
onLeaveShowAsset: () => {
|
onLeaveShowAsset: () => {
|
||||||
dispatch(clearShowAsset()); // clear any errors
|
dispatch(clearShowAsset()); // clear any errors
|
||||||
|
|
|
@ -52,7 +52,7 @@ class ShowAsset extends React.Component {
|
||||||
const assetId = `a#${name}#${claimId}`;
|
const assetId = `a#${name}#${claimId}`;
|
||||||
const existingAssetRecord = assets[assetId];
|
const existingAssetRecord = assets[assetId];
|
||||||
if (existingAssetRecord) { // case: the asset data already exists
|
if (existingAssetRecord) { // case: the asset data already exists
|
||||||
this.showExistingAsset(assetId, existingAssetRecord);
|
this.showExistingAsset(existingAssetRecord);
|
||||||
} else { // case: the asset data does not exist yet
|
} else { // case: the asset data does not exist yet
|
||||||
this.showNewAsset(assetId, name, claimId);
|
this.showNewAsset(assetId, name, claimId);
|
||||||
}
|
}
|
||||||
|
@ -60,9 +60,9 @@ class ShowAsset extends React.Component {
|
||||||
showNewAsset (assetId, name, claimId) {
|
showNewAsset (assetId, name, claimId) {
|
||||||
this.props.onShowNewAsset(assetId, name, claimId);
|
this.props.onShowNewAsset(assetId, name, claimId);
|
||||||
}
|
}
|
||||||
showExistingAsset (assetId, existingAssetRecord) {
|
showExistingAsset (existingAssetRecord) {
|
||||||
let { error, name, claimId, shortId, claimData } = 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 () {
|
componentWillUnmount () {
|
||||||
this.props.onLeaveShowAsset();
|
this.props.onLeaveShowAsset();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { connect } from 'react-redux';
|
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';
|
import View from './view';
|
||||||
|
|
||||||
const mapStateToProps = ({ show }) => {
|
const mapStateToProps = ({ show }) => {
|
||||||
|
@ -30,8 +30,8 @@ const mapDispatchToProps = dispatch => {
|
||||||
onShowNewChannel: (id, name, longId) => {
|
onShowNewChannel: (id, name, longId) => {
|
||||||
dispatch(showNewChannel(id, name, longId));
|
dispatch(showNewChannel(id, name, longId));
|
||||||
},
|
},
|
||||||
onShowExistingChannel: () => {
|
onShowExistingChannel: (error, channelData, claimData) => {
|
||||||
|
dispatch(updateShowChannel(error, channelData, claimData));
|
||||||
},
|
},
|
||||||
onShowChannelClear: () => {
|
onShowChannelClear: () => {
|
||||||
dispatch(clearShowChannel());
|
dispatch(clearShowChannel());
|
||||||
|
|
|
@ -56,7 +56,8 @@ class ShowChannel extends React.Component {
|
||||||
this.props.onShowNewChannel(channelRecordId, name, longId);
|
this.props.onShowNewChannel(channelRecordId, name, longId);
|
||||||
};
|
};
|
||||||
showExistingChannel (existingChannel) {
|
showExistingChannel (existingChannel) {
|
||||||
this.props.onShowExistingChannel(existingChannel);
|
const { error, channelData, claimData } = existingChannel;
|
||||||
|
this.props.onShowExistingChannel(error, channelData, claimData);
|
||||||
};
|
};
|
||||||
componentWillUnmount () {
|
componentWillUnmount () {
|
||||||
this.props.onShowChannelClear();
|
this.props.onShowChannelClear();
|
||||||
|
|
|
@ -92,15 +92,6 @@ export default function (state = initialState, action) {
|
||||||
// show an asset
|
// show an asset
|
||||||
case actions.SHOW_ASSET_UPDATE:
|
case actions.SHOW_ASSET_UPDATE:
|
||||||
return Object.assign({}, state, {
|
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, {
|
showAsset: Object.assign({}, state.showAsset, {
|
||||||
error : action.data.error,
|
error : action.data.error,
|
||||||
name : action.data.name,
|
name : action.data.name,
|
||||||
|
@ -119,6 +110,19 @@ export default function (state = initialState, action) {
|
||||||
claimData: null,
|
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
|
// request a channel
|
||||||
case actions.CHANNEL_REQUEST_ADD:
|
case actions.CHANNEL_REQUEST_ADD:
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
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, 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 { UNAVAILABLE, AVAILABLE } from 'constants/asset_display_states';
|
||||||
import { checkFileAvailability, triggerClaimGet } from 'api/fileApi';
|
import { checkFileAvailability, triggerClaimGet } from 'api/fileApi';
|
||||||
import { getLongClaimId, getShortId, getClaimData } from 'api/assetApi';
|
import { getLongClaimId, getShortId, getClaimData } from 'api/assetApi';
|
||||||
|
@ -29,10 +29,12 @@ function* getAssetDataAndShowAsset (action) {
|
||||||
try {
|
try {
|
||||||
({success, message, data: shortId} = yield call(getShortId, name, claimId));
|
({success, message, data: shortId} = yield call(getShortId, name, claimId));
|
||||||
} catch (error) {
|
} 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) {
|
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
|
// if no error, get claim data
|
||||||
success = null;
|
success = null;
|
||||||
|
@ -40,14 +42,16 @@ function* getAssetDataAndShowAsset (action) {
|
||||||
try {
|
try {
|
||||||
({success, message, data: claimData} = yield call(getClaimData, name, claimId));
|
({success, message, data: claimData} = yield call(getClaimData, name, claimId));
|
||||||
} catch (error) {
|
} 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) {
|
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
|
// if both are successfull, add to asset list and select for showing
|
||||||
yield put(updateShowAsset(id, null, name, claimId, shortId, claimData));
|
yield put(updateShowAsset(null, name, claimId, shortId, claimData));
|
||||||
// yield put(addAssetToAssetList(arg1, arg2));
|
yield put(addAssetToAssetList(id, null, name, claimId, shortId, claimData));
|
||||||
}
|
}
|
||||||
|
|
||||||
function* retrieveFile (action) {
|
function* retrieveFile (action) {
|
||||||
|
@ -105,11 +109,11 @@ function* getNewChannelDataAndShowChannel (action) {
|
||||||
try {
|
try {
|
||||||
({ success, message, data: claimsData } = yield call(getChannelClaims, name, longId, 1));
|
({ success, message, data: claimsData } = yield call(getChannelClaims, name, longId, 1));
|
||||||
} catch (error) {
|
} 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));
|
// yield put(addNewChannelToChannelList(id, error.message, null, null));
|
||||||
}
|
}
|
||||||
if (!success) {
|
if (!success) {
|
||||||
return yield put(updateShowChannel(message, channelData, null));
|
return yield put(updateShowChannel(message, channelData));
|
||||||
// yield put(addNewChannelToChannelList(id, message, null, null));
|
// yield put(addNewChannelToChannelList(id, message, null, null));
|
||||||
}
|
}
|
||||||
yield put(updateShowChannel(null, channelData, claimsData));
|
yield put(updateShowChannel(null, channelData, claimsData));
|
||||||
|
|
Loading…
Add table
Reference in a new issue