spee.ch/react/reducers/publish.js

81 lines
2.2 KiB
JavaScript
Raw Normal View History

import * as actions from 'constants/publish_action_types';
import { LOGIN } from 'constants/publish_channel_select_states';
2018-02-06 03:14:12 +01:00
const { publish } = require('../../config/speechConfig.js');
2018-01-18 18:33:26 +01:00
const initialState = {
disabled : publish.disabled,
publishInChannel : false,
selectedChannel : LOGIN,
showMetadataInputs: false,
status : {
2018-01-18 18:33:26 +01:00
status : null,
message: null,
},
error: {
file : null,
url : null,
channel : null,
2018-01-18 18:33:26 +01:00
publishSubmit: null,
},
file : null,
claim : '',
metadata: {
title : '',
description: '',
license : '',
nsfw : false,
},
thumbnailChannel : publish.thumbnailChannel,
thumbnailChannelId: publish.thumbnailChannelId,
thumbnail : null,
2018-01-18 18:33:26 +01:00
};
export default function (state = initialState, action) {
switch (action.type) {
case actions.FILE_SELECTED:
return Object.assign({}, initialState, { // note: clears to initial state
2018-02-06 21:11:44 +01:00
file: action.data,
2018-01-18 18:33:26 +01:00
});
case actions.FILE_CLEAR:
return initialState;
case actions.METADATA_UPDATE:
return Object.assign({}, state, {
metadata: Object.assign({}, state.metadata, {
2018-02-06 21:11:44 +01:00
[action.data.name]: action.data.value,
2018-01-18 18:33:26 +01:00
}),
});
case actions.CLAIM_UPDATE:
return Object.assign({}, state, {
2018-02-06 21:11:44 +01:00
claim: action.data,
2018-01-18 18:33:26 +01:00
});
case actions.SET_PUBLISH_IN_CHANNEL:
return Object.assign({}, state, {
publishInChannel: action.channel,
});
case actions.PUBLISH_STATUS_UPDATE:
return Object.assign({}, state, {
2018-02-06 21:11:44 +01:00
status: action.data,
2018-01-18 18:33:26 +01:00
});
case actions.ERROR_UPDATE:
return Object.assign({}, state, {
error: Object.assign({}, state.error, {
2018-02-06 21:11:44 +01:00
[action.data.name]: action.data.value,
2018-01-18 18:33:26 +01:00
}),
});
case actions.SELECTED_CHANNEL_UPDATE:
return Object.assign({}, state, {
2018-02-06 21:11:44 +01:00
selectedChannel: action.data,
});
case actions.TOGGLE_METADATA_INPUTS:
return Object.assign({}, state, {
2018-02-06 21:11:44 +01:00
showMetadataInputs: action.data,
});
case actions.THUMBNAIL_NEW:
2018-02-06 03:14:12 +01:00
return Object.assign({}, state, {
thumbnail: action.data,
2018-02-06 03:14:12 +01:00
});
2018-01-18 18:33:26 +01:00
default:
return state;
}
}