Created
November 21, 2017 06:29
-
-
Save choipd/a2587fbd99aa27856706f8f1c59dd6e0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
shouldComponentUpdate(nextProps, nextState){ | |
console.log("component should update") | |
if(nextProps.status === POST_STATUS.POST_STATUS_SAVED) { | |
this._closePost() | |
} | |
return true | |
} | |
const mapStateToProps = (state, props) => { | |
const { status } = state.newPost | |
return { | |
...props, | |
state, | |
}; | |
}; | |
This file contains hidden or 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
export const createPost = (postData) => { | |
return dispatch => { | |
const { currentUser } = firebase.auth() | |
firebase.auth().currentUser.getIdToken(false) | |
.then((idToken)=>{ | |
console.log('token: ', idToken) | |
Axios.defaults.headers = { | |
'authorization': idToken, | |
'content-type': 'application/json' | |
} | |
const request = Axios.post(`https://.../createPost`, postData); | |
dispatch({ | |
type: CREATE_POST, | |
payload: request | |
}) | |
}) | |
.catch(error => { | |
dispatch({ | |
type: CREATE_POST_FAILED, | |
payload: error | |
}) | |
}) | |
} | |
} |
This file contains hidden or 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
case CREATE_POST: { | |
action.payload.then( | |
(response) => { | |
console.log('create post success', response) | |
return { | |
...state, | |
status: POST_STATUS.POST_STATUS_SAVED | |
} | |
}) | |
.catch((error)=>{ | |
console.log('error: ', error) | |
return { | |
...state, | |
status: POST_STATE.POST_STATUS_FAILED, | |
error | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment