joyce/src/reducers/inputs.js

95 lines
2.0 KiB
JavaScript
Raw Normal View History

2018-11-30 07:37:36 +00:00
const initialState = {
documentTitle: '',
search: '',
colorPicker: '',
2019-08-10 15:28:32 +00:00
noteMediaSelection: [],
uploadFile: undefined,
s3Path: undefined
2018-11-30 07:37:36 +00:00
}
const inputs = (state=initialState, action) => {
switch(action.type) {
// Document Title
case 'GET_DOCUMENT_TEXT':
if (action.status === 'success' && action.state === 'currentDocument' && ['tags', 'media'].indexOf(action.docType) <= 0 ) {
2018-11-30 07:37:36 +00:00
return {
...state,
documentTitle: action.data.title
}
} else if (action.status === 'success' && action.docType === 'tags') {
return {
...state,
documentTitle: action.data.title,
colorPicker: action.data.color
}
} else if (action.status === 'success' && action.state === 'currentDocument' && action.docType === 'media') {
return {
...state,
documentTitle: action.data.title,
s3Path: action.data.s3Path
}
2018-11-30 07:37:36 +00:00
} else { return state }
case 'CREATE_DOCUMENT':
return {
...state,
documentTitle: ''
}
case 'UPDATE_DOCUMENT_TITLE':
return {
...state,
documentTitle: action.data
}
// Search
case 'UPDATE_SEARCH_INPUT':
return {
...state,
search: action.data
}
// Color Picker
2019-07-28 20:16:59 +00:00
case 'SAVE_DOCUMENT':
if (action.status === 'success' && action.docType === 'tags') {
return {
...state,
colorPicker: ''
}
} else { return state }
2018-11-30 07:37:36 +00:00
case 'CREATE_DOCUMENT':
return {
...state,
colorPicker: ''
}
case 'SELECT_COLOR_SWATCH':
return {
...state,
colorPicker: action.data
}
case 'UPDATE_COLOR_PICKER':
return {
...state,
colorPicker: action.data.toUpperCase()
}
2019-07-30 04:42:50 +00:00
// Media Upload
case 'UPDATE_MEDIA_INPUT':
return {
...state,
uploadFile: action.data
2019-07-30 04:42:50 +00:00
}
// S3 File
case 'UPLOAD_TO_S3_RESPONSE':
if (action.status === 'success') {
return {
...state,
s3Path: action.url
}
} else { return state }
2019-08-10 15:28:32 +00:00
case 'CLEAR_LOADED_MEDIA':
return {
...state,
s3Path: undefined
}
default:
return state
2018-11-30 07:37:36 +00:00
}
}
export default inputs