re-organized the actions and reducers

This commit is contained in:
bill bittner 2018-02-07 18:41:22 -08:00
parent 489153fcde
commit d219cbf1a2
5 changed files with 129 additions and 114 deletions

View file

@ -1,5 +1,6 @@
import * as actions from 'constants/show_action_types';
// basic request parsing
export function updateRequestError (error) {
return {
type: actions.REQUEST_ERROR_UPDATE,
@ -10,10 +11,7 @@ export function updateRequestError (error) {
export function updateRequestWithChannelRequest (name, id) {
return {
type: actions.REQUEST_CHANNEL_UPDATE,
data: {
name,
id,
},
data: { name, id },
};
};
@ -34,61 +32,7 @@ export function updateRequestWithAssetRequest (name, id, channelName, channelId,
};
};
export function updateShowChannelError (error) {
return {
type: actions.SHOW_CHANNEL_ERROR,
data: error,
};
};
export function updateChannelData (name, longId, shortId) {
return {
type: actions.CHANNEL_DATA_UPDATE,
data: {
name,
longId,
shortId,
},
};
};
export function updateChannelClaimsData (claims, currentPage, totalPages, totalClaims) {
return {
type: actions.CHANNEL_CLAIMS_DATA_UPDATE,
data: {
claims,
currentPage,
totalPages,
totalClaims,
},
};
};
export function fileRequested (name, claimId) {
return {
type: actions.FILE_REQUESTED,
data: {
name,
claimId,
},
};
};
export function updateFileAvailability (status) {
return {
type: actions.FILE_AVAILABILITY_UPDATE,
data: status,
};
};
export function updateDisplayAssetError (error) {
return {
type: actions.DISPLAY_ASSET_ERROR,
data: error,
};
};
// new: request-related actions
// request for an asset
export function newAssetRequest (id, name, modifier) {
return {
@ -104,10 +48,9 @@ export function addAssetRequest (id, error, name, claimId) {
};
};
// new: asset-realted actions
// show an asset
export function showNewAsset (id, name, claimId) {
console.log('show new asset', id, name, claimId);
return {
type: actions.SHOW_NEW_ASSET,
data: { id, name, claimId },
@ -126,3 +69,52 @@ export function clearShowAsset () {
type: actions.SHOW_ASSET_CLEAR,
};
};
// request for a channel
// show a channel
export function updateShowChannelError (error) {
return {
type: actions.SHOW_CHANNEL_ERROR,
data: error,
};
};
export function updateChannelData (name, longId, shortId) {
return {
type: actions.CHANNEL_DATA_UPDATE,
data: { name, longId, shortId },
};
};
export function updateChannelClaimsData (claims, currentPage, totalPages, totalClaims) {
return {
type: actions.CHANNEL_CLAIMS_DATA_UPDATE,
data: { claims, currentPage, totalPages, totalClaims },
};
};
// display a file
export function fileRequested (name, claimId) {
return {
type: actions.FILE_REQUESTED,
data: { name, claimId },
};
};
export function updateFileAvailability (status) {
return {
type: actions.FILE_AVAILABILITY_UPDATE,
data: status,
};
};
export function updateDisplayAssetError (error) {
return {
type: actions.DISPLAY_ASSET_ERROR,
data: error,
};
};

36
react/api/channelApi.js Normal file
View file

@ -0,0 +1,36 @@
import Request from 'utils/request';
export function getLongClaimId (name, modifier) {
let body = {};
// create request params
if (modifier) {
if (modifier.id) {
body['claimId'] = modifier.id;
} else {
body['channelName'] = modifier.channel.name;
body['channelClaimId'] = modifier.channel.id;
}
}
body['claimName'] = name;
const params = {
method : 'POST',
headers: new Headers({
'Content-Type': 'application/json',
}),
body: JSON.stringify(body),
}
// crate url
const url = `/api/claim/long-id`;
// return the request promise
return Request(url, params);
};
export function getShortId (name, claimId) {
const url = `/api/claim/short-id/${claimId}/${name}`;
return Request(url);
};
export function getClaimData (name, claimId) {
const url = `/api/claim/data/${name}/${claimId}`;
return Request(url);
};

View file

@ -48,25 +48,18 @@ const initialState = {
status: LOCAL_CHECK,
},
channelRequests: {},
channels : {}, // same schema as showChannel
assetRequests : {},
channels : {},
assets : {}, // same schema as showAsset
};
/* asset request schema:
name#someidfrommodifier: {
error : null,
name : null,
claimId: null,
} */
/*
Reducers describe how the application's state changes in response to actions
*/
export default function (state = initialState, action) {
switch (action.type) {
// request cases
// handle request
case actions.REQUEST_ERROR_UPDATE:
return Object.assign({}, state, {
request: Object.assign({}, state.request, {
@ -89,49 +82,7 @@ export default function (state = initialState, action) {
},
assetRequest: action.data,
});
// show channel cases
case actions.SHOW_CHANNEL_ERROR:
return Object.assign({}, state, {
showChannel: Object.assign({}, state.showChannel, {
error: action.data,
}),
});
case actions.CHANNEL_DATA_UPDATE:
return Object.assign({}, state, {
showChannel: Object.assign({}, state.showChannel, {
channelData: action.data,
}),
});
case actions.CHANNEL_CLAIMS_DATA_UPDATE:
return Object.assign({}, state, {
showChannel: Object.assign({}, state.showChannel, {
channelClaimsData: action.data,
}),
});
// show asset cases
// case actions.SHOW_ASSET_UPDATE:
// return Object.assign({}, state, {
// showAsset: Object.assign({}, state.showAsset, {
// error : action.data.error,
// claimData: action.data.claimData,
// shortId : action.data.shortId,
// }),
// });
// display asset cases
case actions.FILE_AVAILABILITY_UPDATE:
return Object.assign({}, state, {
displayAsset: Object.assign({}, state.displayAsset, {
status: action.data,
}),
});
case actions.DISPLAY_ASSET_ERROR:
return Object.assign({}, state, {
displayAsset: Object.assign({}, state.displayAsset, {
error : action.data,
status: ERROR,
}),
});
// new actions
// request for an asset
case actions.ASSET_REQUEST_ADD:
return Object.assign({}, state, {
assetRequests: Object.assign({}, state.assets, {
@ -142,6 +93,7 @@ export default function (state = initialState, action) {
},
}),
});
// show an asset
case actions.SHOW_ASSET_UPDATE:
return Object.assign({}, state, {
assets: Object.assign({}, state.assets, {
@ -171,6 +123,41 @@ export default function (state = initialState, action) {
claimData: null,
}),
});
// request a channel
// show a channel
case actions.SHOW_CHANNEL_ERROR:
return Object.assign({}, state, {
showChannel: Object.assign({}, state.showChannel, {
error: action.data,
}),
});
case actions.CHANNEL_DATA_UPDATE:
return Object.assign({}, state, {
showChannel: Object.assign({}, state.showChannel, {
channelData: action.data,
}),
});
case actions.CHANNEL_CLAIMS_DATA_UPDATE:
return Object.assign({}, state, {
showChannel: Object.assign({}, state.showChannel, {
channelClaimsData: action.data,
}),
});
// display an asset
case actions.FILE_AVAILABILITY_UPDATE:
return Object.assign({}, state, {
displayAsset: Object.assign({}, state.displayAsset, {
status: action.data,
}),
});
case actions.DISPLAY_ASSET_ERROR:
return Object.assign({}, state, {
displayAsset: Object.assign({}, state.displayAsset, {
error : action.data,
status: ERROR,
}),
});
default:
return state;
}

View file

@ -3,7 +3,7 @@ import * as actions from 'constants/show_action_types';
import { addAssetRequest, updateShowAsset, 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';
import { getLongClaimId, getShortId, getClaimData } from 'api/assetApi';
function* newAssetRequest (action) {
const { id, name, modifier } = action.data;