From 1c8fdb4cdd3469d49fcd5a051d1e92111e87162d Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Wed, 3 May 2017 09:08:00 -0400 Subject: PLT-6277 Moved profile image cropping to server (#6269) * PLT-6277 Moved profile image cropping to server * Cosmetic refactoring of SettingPicture component --- webapp/components/setting_picture.jsx | 139 ++++++++------------- .../user_settings_general.jsx | 37 ++---- webapp/sass/routes/_settings.scss | 8 ++ 3 files changed, 70 insertions(+), 114 deletions(-) (limited to 'webapp') diff --git a/webapp/components/setting_picture.jsx b/webapp/components/setting_picture.jsx index 9c5913f3c..cc3ff8fbf 100644 --- a/webapp/components/setting_picture.jsx +++ b/webapp/components/setting_picture.jsx @@ -1,74 +1,63 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. +import React, {Component, PropTypes} from 'react'; import {FormattedMessage} from 'react-intl'; +import FormError from 'components/form_error.jsx'; + import loadingGif from 'images/load.gif'; -import React from 'react'; +export default class SettingPicture extends Component { + static propTypes = { + clientError: PropTypes.string, + serverError: PropTypes.string, + src: PropTypes.string, + file: PropTypes.object, + loadingPicture: PropTypes.bool, + submitActive: PropTypes.bool, + submit: PropTypes.func, + title: PropTypes.string, + onFileChange: PropTypes.func, + updateSection: PropTypes.func + }; -export default class SettingPicture extends React.Component { constructor(props) { super(props); - this.setPicture = this.setPicture.bind(this); - this.confirmImage = this.confirmImage.bind(this); + this.state = { + image: null + }; } - setPicture(file) { + componentWillReceiveProps(nextProps) { + if (nextProps.file !== this.props.file) { + this.setState({image: null}); + + this.setPicture(nextProps.file); + } + } + + setPicture = (file) => { if (file) { var reader = new FileReader(); reader.onload = (e) => { - const canvas = this.refs.profileImageCanvas; - const context = canvas.getContext('2d'); - const imageObj = new Image(); - - imageObj.onload = () => { - if (imageObj.width > imageObj.height) { - const side = imageObj.height; - const rem = imageObj.width - side; - const startX = parseInt(rem / 2, 10); - context.drawImage(imageObj, startX, 0, side, side, - 0, 0, canvas.width, canvas.height); - } else { - const side = imageObj.width; - const rem = imageObj.height - side; - const startY = parseInt(rem / 2, 10); - context.drawImage(imageObj, 0, startY, side, side, - 0, 0, canvas.width, canvas.height); - } - }; - imageObj.src = e.target.result; + this.setState({ + image: e.target.result + }); }; reader.readAsDataURL(file); } } - componentWillReceiveProps(nextProps) { - if (nextProps.picture) { - this.setPicture(nextProps.picture); - } - } - render() { - var clientError = null; - if (this.props.client_error) { - clientError =
; - } - var serverError = null; - if (this.props.server_error) { - serverError =
; - } - - var img = null; - if (this.props.picture) { + let img; + if (this.props.file) { img = ( - ); } else { @@ -81,7 +70,7 @@ export default class SettingPicture extends React.Component { ); } - var confirmButton; + let confirmButton; if (this.props.loadingPicture) { confirmButton = ( ); } else { - var confirmButtonClass = 'btn btn-sm'; + let confirmButtonClass = 'btn btn-sm'; if (this.props.submitActive) { confirmButtonClass += ' btn-primary'; } else { @@ -100,7 +89,7 @@ export default class SettingPicture extends React.Component { confirmButton = ( ); } - var helpText = ( - - ); - var self = this; return (