spee.ch/react/reducers/show.js

128 lines
3.7 KiB
JavaScript
Raw Normal View History

import * as actions from 'constants/show_action_types';
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';
const initialState = {
request: {
2018-02-08 05:15:44 +01:00
error : null,
type : null,
data : null,
requestId: null,
},
2018-02-07 22:26:07 +01:00
channelRequests: {},
channelList : {},
2018-02-07 22:26:07 +01:00
assetRequests : {},
assetList : {},
2018-02-14 01:51:59 +01:00
displayAsset : {
error : null,
status: LOCAL_CHECK,
},
};
export default function (state = initialState, action) {
switch (action.type) {
2018-02-08 03:41:22 +01:00
// handle request
2018-02-14 02:16:50 +01:00
case actions.REQUEST_UPDATE_ERROR:
return Object.assign({}, state, {
request: Object.assign({}, state.request, {
error: action.data,
}),
});
2018-02-13 05:01:02 +01:00
case actions.REQUEST_UPDATE_CHANNEL:
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-14 02:16:50 +01:00
case actions.REQUEST_UPDATE_ASSET:
return Object.assign({}, state, {
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-14 01:51:59 +01:00
// asset actions
2018-02-13 05:01:02 +01:00
case actions.ASSET_REQUEST_SUCCESS:
2018-02-07 22:26:07 +01:00
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,
name : action.data.name,
2018-02-07 22:26:07 +01:00
claimId: action.data.claimId,
},
}),
});
2018-02-14 02:16:50 +01:00
case actions.ASSET_ADD:
return Object.assign({}, state, {
2018-02-13 05:01:02 +01:00
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 07:22:17 +01:00
});
2018-02-14 01:51:59 +01:00
// channel actions
2018-02-14 02:16:50 +01:00
case actions.CHANNEL_REQUEST_ADD:
2018-02-14 01:51:59 +01:00
return Object.assign({}, state, {
channelRequests: Object.assign({}, state.channelRequests, {
[action.data.id]: {
error : action.data.error,
name : action.data.name,
longId : action.data.longId,
shortId: action.data.shortId,
},
}),
});
2018-02-14 02:16:50 +01:00
case actions.CHANNEL_ADD:
return Object.assign({}, state, {
channelList: Object.assign({}, state.channelList, {
[action.data.id]: {
name : action.data.name,
longId : action.data.longId,
shortId : action.data.shortId,
claimsData: action.data.claimsData,
},
}),
});
2018-02-13 05:01:02 +01:00
case actions.CHANNEL_CLAIMS_UPDATE_SUCCESS:
return Object.assign({}, state, {
channelList: Object.assign({}, state.channelList, {
[action.data.channelListId]: Object.assign({}, state.channelList[action.data.channelListId], {
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,
}),
});
default:
return state;
}
}