-
-
Save taggon/03d8cef3d35d0cc70b4a6067afefdf94 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, | |
}) | |
return request; | |
}) | |
.then(response => { | |
console.log('create post success', response) | |
dispatch({ | |
type: CREATE_POST_SUCCESS, | |
}); | |
}) | |
.catch(error => { | |
console.log('error: ', error) | |
dispatch({ | |
type: CREATE_POST_FAILED, | |
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_SUCCESS: | |
return { | |
...state, | |
status: POST_STATUS.POST_STATUS_SAVED, | |
}; | |
case CREATE_POST_FAILED: | |
return { | |
...state, | |
status: POST_STATE.POST_STATUS_FAILED, | |
action.error, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment