import React from 'react'; import Avatar from 'misago/components/avatar'; // jshint ignore:line import Button from 'misago/components/button'; // jshint ignore:line import Loader from 'misago/components/loader'; // jshint ignore:line import ajax from 'misago/services/ajax'; import snackbar from 'misago/services/snackbar'; export default class extends React.Component { constructor(props) { super(props); this.state = { 'isLoading': false }; } callApi(avatarType) { if (this.state.isLoading) { return false; } this.setState({ 'isLoading': true }); ajax.post(this.props.user.avatar_api_url, { avatar: avatarType }).then((response) => { this.setState({ 'isLoading': false }); snackbar.success(response.detail); this.props.onComplete(response.avatar_hash, response.options); }, (rejection) => { if (rejection.status === 400) { snackbar.error(rejection.detail); this.setState({ 'isLoading': false }); } else { this.props.showError(rejection); } }); } /* jshint ignore:start */ setGravatar = () => { this.callApi('gravatar'); }; setGenerated = () => { this.callApi('generated'); }; /* jshint ignore:end */ getGravatarButton() { if (this.props.options.gravatar) { /* jshint ignore:start */ return ; /* jshint ignore:end */ } else { return null; } } getCropButton() { if (this.props.options.crop_org) { /* jshint ignore:start */ return ; /* jshint ignore:end */ } else { return null; } } getUploadButton() { if (this.props.options.upload) { /* jshint ignore:start */ return ; /* jshint ignore:end */ } else { return null; } } getGalleryButton() { if (this.props.options.galleries) { /* jshint ignore:start */ return ; /* jshint ignore:end */ } else { return null; } } getAvatarPreview() { if (this.state.isLoading) { /* jshint ignore:start */ return
; /* jshint ignore:end */ } else { /* jshint ignore:start */ return
; /* jshint ignore:end */ } } render() { /* jshint ignore:start */ return
{this.getAvatarPreview()}
{this.getGravatarButton()} {this.getCropButton()} {this.getUploadButton()} {this.getGalleryButton()}
; /* jshint ignore:end */ } }