Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #896 Perceived failure to save profile pic #911

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions common/components/common/FileInfo.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//@flow

export type FileInfo = {|
id: ?number,
key: string,
Expand Down
24 changes: 14 additions & 10 deletions common/components/common/upload/ImageCropUploadButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,25 @@ type Props = {|
iconClass: string,
aspect: ?number,
currentImage: FileInfo,
isCropping: boolean,
_onIsCroppingChanged: (boolean) => void,
|};

type State = {|
s3Key: string,
src: string,
croppedImageUrl: ?string,
crop: any
|};

let lastFileUploadUrl: string = null;
let lastFileUploadUrl: string = "";

class ImageCropUploadButton extends React.PureComponent<Props, State> {
constructor(props): void {
super(props);
this.state = {
s3Key: "",
src: null,
isCropping: false,
src: "",
croppedImageUrl: "",
crop: this.initializeCropSettings(),
};
Expand All @@ -40,9 +43,9 @@ class ImageCropUploadButton extends React.PureComponent<Props, State> {
const previewImage =
this.state.croppedImageUrl ||
(this.props.currentImage && this.props.currentImage.publicUrl);
return (
return (
<div className="ImageCropUploadButton-root">
{this.state.src && this.state.isCropping && (
{this.state.src && this.props.isCropping && (
<div className="ImageCropUploadButton-cropper">
<ReactCrop
src={this.state.src}
Expand All @@ -65,7 +68,7 @@ class ImageCropUploadButton extends React.PureComponent<Props, State> {
</div>
</div>
)}
{!this.state.isCropping && (
{!this.props.isCropping && (
<FileSelectButton
hasImagePreview="true"
previewImage={previewImage}
Expand All @@ -80,7 +83,8 @@ class ImageCropUploadButton extends React.PureComponent<Props, State> {
}

_handleDoneCropping(): void {
this.setState({ isCropping: false, crop: this.initializeCropSettings() });
this.setState({ crop: this.initializeCropSettings() });
this.props._onIsCroppingChanged(false);
if (this.fileBlob) {
this.launchPresignedUploadToS3(this.fileBlob);
}
Expand All @@ -89,17 +93,16 @@ class ImageCropUploadButton extends React.PureComponent<Props, State> {
_handleCancelCropping(): void {
if (lastFileUploadUrl) {
this.setState({
isCropping: false,
crop: this.initializeCropSettings(),
croppedImageUrl: lastFileUploadUrl,
});
} else {
this.setState({
isCropping: false,
crop: this.initializeCropSettings(),
croppedImageUrl: this.props.currentImage,
});
}
this.props._onIsCroppingChanged(false);
}

_onCropChange(crop): void {
Expand All @@ -116,7 +119,8 @@ class ImageCropUploadButton extends React.PureComponent<Props, State> {
}

_handleFileSelection(file): void {
this.setState({ src: file, isCropping: true });
this.setState({ src: file});
this.props._onIsCroppingChanged(true);
}

makeClientCrop(crop) {
Expand Down
2 changes: 2 additions & 0 deletions common/components/common/upload/S3Data.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//@flow

export type S3Data = {|
url: string,
fields: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Props = {|
type State = {|
showModal: boolean,
user_thumbnail: FileInfo,
isCropping: boolean,
|};

type FormFields = {|
Expand All @@ -37,6 +38,7 @@ class EditUserThumbnailModal extends React.Component<Props, State> {
this.state = {
showModal: false,
user_thumbnail: null,
isCropping: false,
};
}

Expand All @@ -49,6 +51,10 @@ class EditUserThumbnailModal extends React.Component<Props, State> {
state.user_thumbnail = FormFieldsStore.getFormFieldValue("user_thumbnail");
return state;
}

setIsCropping(isCropping) {
this.setState({isCropping});
}

componentWillReceiveProps(nextProps: Props): void {
if (!this.state.showModal && nextProps.showModal) {
Expand All @@ -72,11 +78,14 @@ class EditUserThumbnailModal extends React.Component<Props, State> {
user={this.props.user}
fields={["user_thumbnail"]}
onEditClose={this.props.onEditClose}
isInvalid={this.state.isCropping}
>
<ImageCropUploadFormElement
form_id="user_thumbnail"
buttonText="Upload Your Picture"
aspect={1 / 1}
isCropping={this.state.isCropping}
_onIsCroppingChanged={this.setIsCropping.bind(this)}
/>
</EditUserModal>
);
Expand Down
6 changes: 6 additions & 0 deletions common/components/forms/ImageCropUploadFormElement.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ type Props = {|
currentImage: FileInfo,
onSelection: ?(FileInfo) => void,
aspect: number,
isCropping: boolean,
_onIsCroppingChanged: (boolean) => void,
|};

type State = {|
currentImage: FileInfo,
initialized: boolean,
buttonText: string,
currentImage: string
|};

class ImageCropUploadFormElement extends React.Component<Props, State> {
Expand Down Expand Up @@ -73,6 +77,8 @@ class ImageCropUploadFormElement extends React.Component<Props, State> {
aspect={this.props.aspect}
buttonText={this.props.buttonText || "Upload Image"}
onFileUpload={this._handleFileSelection.bind(this)}
isCropping={this.props.isCropping}
_onIsCroppingChanged={this.props._onIsCroppingChanged}
/>
{/*TODO: Use HiddenFormField component*/}
<input
Expand Down