onFormSubmit(e){
e.preventDefault() // Stop form submit
this.fileUpload(this.state.file).then((response)=>{
console.log('getting new picture')
setTimeout(()=>{
this.props.onGetInfo(this.props.userID);
},500)
})
}
fileUpload(file){
console.log(file)
const url = 'http://localhost:8080/uploadavatar';
const formData = new FormData();
formData.append('file',file)
const config = {
headers: {
'content-type': 'multipart/form-data'
}
}
return post(url, formData,config)
}
onGetInfo: (name) => {
dispatch(fetchInfo(name));
}
export const fetchInfo = (name) => {
return (dispatch) => {
console.log(`${apiUrl}/userinfo/${name}`)
return axios.get(`${apiUrl}/userinfo/${name}`)
.then(response => {
console.log('new image url: '+response.data)
dispatch({type: 'USER_INFO', info: response.data})
})
.catch(error => {
throw(error);
});
};
};
onError(){
this.props.onGetInfo(this.props.userID);
}
render(){
{ this.props.info ?
image = <img onError={this.onError.bind(this)} src={`/images/upload/${this.props.userID}/${this.props.info[this.props.info.length-1]}`} alt=""/> : image = null
}
{image}
}
export default function postReducer(state = [], action) {
switch (action.type) {
case 'USER_INFO':
return [...state,action.info];
default:
return state;
}
}