Created
August 25, 2019 18:15
-
-
Save Ifmr24/bceadfbf531668ba3e6b48a38947d0cd to your computer and use it in GitHub Desktop.
S3 Upload Redux Reducers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {STARTING_UPLOAD, SUCCESS_UPLOAD, ERROR_UPLOAD} from './actions'; | |
let INITIAL_STATE = { | |
starting: false, | |
success: false, | |
url: null, | |
error: null | |
}; | |
export let uploadReducer = (state = INITIAL_STATE, action) => { | |
switch (action.type) { | |
case STARTING_UPLOAD: | |
return Object.assign({}, state, { | |
starting: true, | |
success: false, | |
url: null, | |
error: null | |
}); | |
case SUCCESS_UPLOAD: | |
return Object.assign({}, state, { | |
starting: false, | |
success: true, | |
url: action.payload, | |
error: null | |
}); | |
case ERROR_UPLOAD: | |
return Object.assign({}, state, { | |
starting: false, | |
success: false, | |
url: null, | |
error: action.payload | |
}); | |
default: | |
return state | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment