spee.ch/react/reducers/index.js

65 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-01-10 03:25:38 +01:00
import {
CHANNEL_UPDATE, CLAIM_UPDATE, FILE_CLEAR, FILE_SELECTED, METADATA_UPDATE,
SET_PUBLISH_IN_CHANNEL,
} from '../actions';
2018-01-09 02:06:31 +01:00
const initialState = {
2018-01-10 03:25:38 +01:00
loggedInChannel: {
name : null,
shortId: null,
longId : null,
},
2018-01-10 20:26:01 +01:00
publishInChannel: false,
publishStatus : null,
error : null,
file : null,
claim : '',
metadata : {
title : '',
thumbnail : '',
description: '',
license : '',
nsfw : '',
},
2018-01-09 02:06:31 +01:00
};
/*
Reducers describe how the application's state changes in response to actions
*/
export default function (state = initialState, action) {
switch (action.type) {
case FILE_SELECTED:
return Object.assign({}, state, {
file: action.file,
2018-01-09 02:06:31 +01:00
});
case FILE_CLEAR:
return initialState;
case METADATA_UPDATE:
console.log(`reducer for ${action.name} ${action.value}`);
return Object.assign({}, state, {
metadata: {
[action.name]: action.value,
},
2018-01-10 03:25:38 +01:00
});
case CLAIM_UPDATE:
return Object.assign({}, state, {
claim: action.value,
});
case CHANNEL_UPDATE:
return Object.assign({}, state, {
loggedInChannel: {
name : action.name,
shortId: action.shortId,
longId : action.longId,
},
});
case SET_PUBLISH_IN_CHANNEL:
return Object.assign({}, state, {
publishInChannel: action.value,
});
2018-01-09 02:06:31 +01:00
default:
return state;
}
}