2018-02-01 23:29:33 +01:00
|
|
|
import * as actions from 'constants/show_action_types';
|
2018-02-02 20:10:58 +01:00
|
|
|
import { CHANNEL, ASSET } from 'constants/show_request_types';
|
2018-02-07 04:00:52 +01:00
|
|
|
import { LOCAL_CHECK, ERROR } from 'constants/asset_display_states';
|
2018-02-01 23:29:33 +01:00
|
|
|
|
|
|
|
const initialState = {
|
2018-02-07 19:52:09 +01:00
|
|
|
request: {
|
2018-02-08 05:15:44 +01:00
|
|
|
error : null,
|
|
|
|
type : null,
|
|
|
|
data : null,
|
|
|
|
requestId: null,
|
2018-02-01 23:29:33 +01:00
|
|
|
},
|
2018-02-03 03:16:18 +01:00
|
|
|
showChannel: {
|
2018-02-07 20:30:39 +01:00
|
|
|
error : null,
|
2018-02-03 03:16:18 +01:00
|
|
|
channelData: {
|
|
|
|
name : null,
|
|
|
|
shortId: null,
|
|
|
|
longId : null,
|
|
|
|
},
|
|
|
|
channelClaimsData: {
|
|
|
|
claims : null,
|
|
|
|
currentPage: null,
|
|
|
|
totalPages : null,
|
|
|
|
totalClaims: null,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
showAsset: {
|
2018-02-07 04:00:52 +01:00
|
|
|
error : null,
|
2018-02-08 03:01:51 +01:00
|
|
|
name : null,
|
|
|
|
claimId : null,
|
2018-02-07 04:00:52 +01:00
|
|
|
shortId : null,
|
2018-02-08 03:01:51 +01:00
|
|
|
claimData: null,
|
2018-02-03 03:16:18 +01:00
|
|
|
},
|
2018-02-07 19:52:09 +01:00
|
|
|
displayAsset: {
|
|
|
|
error : null,
|
|
|
|
status: LOCAL_CHECK,
|
|
|
|
},
|
2018-02-07 22:26:07 +01:00
|
|
|
channelRequests: {},
|
2018-02-08 19:59:49 +01:00
|
|
|
channelList : {},
|
2018-02-07 22:26:07 +01:00
|
|
|
assetRequests : {},
|
2018-02-08 20:50:30 +01:00
|
|
|
assetList : {}, // same schema as showAsset
|
2018-02-01 23:29:33 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Reducers describe how the application's state changes in response to actions
|
|
|
|
*/
|
|
|
|
|
|
|
|
export default function (state = initialState, action) {
|
|
|
|
switch (action.type) {
|
2018-02-08 03:41:22 +01:00
|
|
|
// handle request
|
2018-02-07 20:30:39 +01:00
|
|
|
case actions.REQUEST_ERROR_UPDATE:
|
2018-02-01 23:29:33 +01:00
|
|
|
return Object.assign({}, state, {
|
2018-02-07 19:52:09 +01:00
|
|
|
request: Object.assign({}, state.request, {
|
2018-02-07 20:30:39 +01:00
|
|
|
error: action.data,
|
2018-02-07 19:52:09 +01:00
|
|
|
}),
|
2018-02-07 20:30:39 +01:00
|
|
|
});
|
|
|
|
case actions.REQUEST_CHANNEL_UPDATE:
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
request: {
|
|
|
|
type : CHANNEL,
|
|
|
|
error: null,
|
2018-02-08 05:15:44 +01:00
|
|
|
id : action.data.requestId,
|
|
|
|
data : {
|
|
|
|
name: action.data.name,
|
|
|
|
id : action.data.id,
|
|
|
|
},
|
2018-02-07 20:30:39 +01:00
|
|
|
},
|
2018-02-01 23:29:33 +01:00
|
|
|
});
|
2018-02-07 19:52:09 +01:00
|
|
|
case actions.REQUEST_CLAIM_UPDATE:
|
2018-02-01 23:29:33 +01:00
|
|
|
return Object.assign({}, state, {
|
2018-02-07 20:30:39 +01:00
|
|
|
request: {
|
|
|
|
type : ASSET,
|
|
|
|
error: null,
|
2018-02-08 05:15:44 +01:00
|
|
|
id : action.data.requestId,
|
|
|
|
data : {
|
|
|
|
name : action.data.name,
|
|
|
|
modifier : action.data.modifier,
|
|
|
|
extension: action.data.extension,
|
|
|
|
},
|
2018-02-07 20:30:39 +01:00
|
|
|
},
|
2018-02-01 23:29:33 +01:00
|
|
|
});
|
2018-02-08 03:41:22 +01:00
|
|
|
// request for an asset
|
2018-02-07 22:26:07 +01:00
|
|
|
case actions.ASSET_REQUEST_ADD:
|
|
|
|
return Object.assign({}, state, {
|
2018-02-08 05:15:44 +01:00
|
|
|
assetRequests: Object.assign({}, state.assetRequests, {
|
2018-02-07 22:26:07 +01:00
|
|
|
[action.data.id]: {
|
|
|
|
error : action.data.error,
|
2018-02-08 03:01:51 +01:00
|
|
|
name : action.data.name,
|
2018-02-07 22:26:07 +01:00
|
|
|
claimId: action.data.claimId,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
});
|
2018-02-08 03:41:22 +01:00
|
|
|
// show an asset
|
2018-02-08 03:01:51 +01:00
|
|
|
case actions.SHOW_ASSET_UPDATE:
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
showAsset: Object.assign({}, state.showAsset, {
|
|
|
|
error : action.data.error,
|
|
|
|
name : action.data.name,
|
|
|
|
claimId : action.data.claimId,
|
|
|
|
shortId : action.data.shortId,
|
|
|
|
claimData: action.data.claimData,
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
case actions.SHOW_ASSET_CLEAR:
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
showAsset: Object.assign({}, state.showAsset, {
|
|
|
|
error : null,
|
|
|
|
name : null,
|
|
|
|
claimId : null,
|
|
|
|
shortId : null,
|
|
|
|
claimData: null,
|
|
|
|
}),
|
|
|
|
});
|
2018-02-08 20:22:19 +01:00
|
|
|
// 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,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
});
|
2018-02-08 03:41:22 +01:00
|
|
|
// request a channel
|
2018-02-08 06:30:32 +01:00
|
|
|
case actions.CHANNEL_REQUEST_ADD:
|
2018-02-08 03:41:22 +01:00
|
|
|
return Object.assign({}, state, {
|
2018-02-08 08:02:57 +01:00
|
|
|
channelRequests: Object.assign({}, state.channelRequests, {
|
2018-02-08 06:30:32 +01:00
|
|
|
[action.data.id]: {
|
2018-02-08 19:02:29 +01:00
|
|
|
error : action.data.error,
|
|
|
|
channelData: {
|
|
|
|
name : action.data.name,
|
|
|
|
longId : action.data.longId,
|
|
|
|
shortId: action.data.shortId,
|
|
|
|
},
|
2018-02-08 06:30:32 +01:00
|
|
|
},
|
2018-02-08 03:41:22 +01:00
|
|
|
}),
|
|
|
|
});
|
2018-02-08 06:30:32 +01:00
|
|
|
// show a channel
|
2018-02-08 19:59:49 +01:00
|
|
|
case actions.SHOW_CHANNEL_UPDATE:
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
showChannel: {
|
2018-02-08 20:50:30 +01:00
|
|
|
error : action.data.error,
|
|
|
|
channelData: {
|
|
|
|
name : action.data.name,
|
|
|
|
shortId: action.data.shortId,
|
|
|
|
longId : action.data.longId,
|
|
|
|
},
|
|
|
|
claimData: action.data.claimData,
|
2018-02-08 19:59:49 +01:00
|
|
|
},
|
|
|
|
});
|
2018-02-08 07:22:17 +01:00
|
|
|
case actions.SHOW_CHANNEL_CLEAR:
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
showChannel: {
|
|
|
|
error : null,
|
|
|
|
channelData: {
|
|
|
|
name : null,
|
|
|
|
shortId: null,
|
|
|
|
longId : null,
|
|
|
|
},
|
|
|
|
channelClaimsData: {
|
|
|
|
claims : null,
|
|
|
|
currentPage: null,
|
|
|
|
totalPages : null,
|
|
|
|
totalClaims: null,
|
|
|
|
},
|
2018-02-08 08:02:57 +01:00
|
|
|
},
|
2018-02-08 07:22:17 +01:00
|
|
|
});
|
2018-02-08 19:59:49 +01:00
|
|
|
// add channel to channel list
|
|
|
|
case actions.CHANNEL_LIST_ADD:
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
channelList: Object.assign({}, state.channelList, {
|
|
|
|
[action.data.id]: {
|
|
|
|
error : action.data.error,
|
|
|
|
channelData: action.data.channelData,
|
|
|
|
claimsData : action.data.claimsData,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
});
|
2018-02-08 03:41:22 +01:00
|
|
|
// 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,
|
|
|
|
}),
|
|
|
|
});
|
2018-02-01 23:29:33 +01:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|