<commit_before>// @flow
import React from 'react';
import Dialog from 'material-ui/Dialog';
import R from 'ramda';
import Dropzone from 'react-dropzone';
import Button from 'react-mdl/lib/Button';

import CropperWrapper from './CropperWrapper';
import type { ImageUploadState } from '../reducers/image_upload';

const onDrop = R.curry((startPhotoEdit, files) => startPhotoEdit(...files));

const dropZone = (startPhotoEdit, setPhotoError) => (
  <Dropzone
    onDrop={onDrop(startPhotoEdit)}
    style={{height: uploaderBodyHeight()}}
    className="photo-active-item photo-dropzone"
    activeClassName="photo-active-item photo-dropzone active"
    accept="image/*"
    onDropRejected={() => setPhotoError('Please select a valid photo')}
  >
    <div>
      Drag a photo here or click to select a photo.
    </div>
  </Dropzone>
);

const uploaderBodyHeight = (): number => (
  R.min(500, window.innerHeight / 2)
);

const imageError = err => <div className="img-error">{err}</div>;

type ImageUploadProps = {
  photoDialogOpen:      boolean;
  setDialogVisibility:  (b: boolean) => void;
  startPhotoEdit:       (p: File) => void;
  clearPhotoEdit:       () => void;
  imageUpload:          ImageUploadState;
  updateUserPhoto:      (i: string) => Promise<string>,
  updatePhotoEdit:      (b: Blob) => void;
  setPhotoError:        (s: string) => void;
};

const ProfileImageUploader = ({
  photoDialogOpen,
  setDialogVisibility,
  startPhotoEdit,
  clearPhotoEdit,
  updatePhotoEdit,
  imageUpload: { photo, error },
  updateUserPhoto,
  setPhotoError,
}: ImageUploadProps) => (
  <Dialog
    title="Upload a Profile Photo"
    titleClassName="dialog-title"
    contentClassName="dialog photo-upload-dialog"
    className="photo-upload-dialog-wrapper"
    onRequestClose={() => setDialogVisibility(false)}
    autoScrollBodyContent={true}
    contentStyle={{ maxWidth: '620px' }}
    open={photoDialogOpen}
    actions = {[
      <Button
        type='button'
        className='secondary-button cancel-button'
        key="cancel"
        onClick={() => {
          setDialogVisibility(false);
          clearPhotoEdit();
        }}>
        Cancel
      </Button>,
      <Button
        type='button'
        className={`save-button ${photo ? 'primary-button' : 'secondary-button disabled'}`}
        key="save"
        onClick={updateUserPhoto}>
        Save
      </Button><commit_msg>Fixed exception when clicking 'save' without adding a photo<commit_after>// @flow
import React from 'react';
import Dialog from 'material-ui/Dialog';
import R from 'ramda';
import Dropzone from 'react-dropzone';
import Button from 'react-mdl/lib/Button';

import CropperWrapper from './CropperWrapper';
import type { ImageUploadState } from '../reducers/image_upload';

const onDrop = R.curry((startPhotoEdit, files) => startPhotoEdit(...files));

const dropZone = (startPhotoEdit, setPhotoError) => (
  <Dropzone
    onDrop={onDrop(startPhotoEdit)}
    style={{height: uploaderBodyHeight()}}
    className="photo-active-item photo-dropzone"
    activeClassName="photo-active-item photo-dropzone active"
    accept="image/*"
    onDropRejected={() => setPhotoError('Please select a valid photo')}
  >
    <div>
      Drag a photo here or click to select a photo.
    </div>
  </Dropzone>
);

const uploaderBodyHeight = (): number => (
  R.min(500, window.innerHeight / 2)
);

const imageError = err => <div className="img-error">{err}</div>;

type ImageUploadProps = {
  photoDialogOpen:      boolean;
  setDialogVisibility:  (b: boolean) => void;
  startPhotoEdit:       (p: File) => void;
  clearPhotoEdit:       () => void;
  imageUpload:          ImageUploadState;
  updateUserPhoto:      (i: string) => Promise<string>,
  updatePhotoEdit:      (b: Blob) => void;
  setPhotoError:        (s: string) => void;
};

const ProfileImageUploader = ({
  photoDialogOpen,
  setDialogVisibility,
  startPhotoEdit,
  clearPhotoEdit,
  updatePhotoEdit,
  imageUpload: { photo, error },
  updateUserPhoto,
  setPhotoError,
}: ImageUploadProps) => (
  <Dialog
    title="Upload a Profile Photo"
    titleClassName="dialog-title"
    contentClassName="dialog photo-upload-dialog"
    className="photo-upload-dialog-wrapper"
    onRequestClose={() => setDialogVisibility(false)}
    autoScrollBodyContent={true}
    contentStyle={{ maxWidth: '620px' }}
    open={photoDialogOpen}
    actions = {[
      <Button
        type='button'
        className='secondary-button cancel-button'
        key="cancel"
        onClick={() => {
          setDialogVisibility(false);
          clearPhotoEdit();
        }}>
        Cancel
      </Button>,
      <Button
        type='button'
        className={`save-button ${photo ? 'primary-button' : 'secondary-button disabled'}`}
        key="save"
        onClick={photo ? updateUserPhoto : undefined}>
        Save
      </Button>
{'fraction_non_alphanumeric': 0.13561417971970322, 'fraction_numerical': 0.0028854080791426216, 'mean_word_length': 3.383920505871725, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5704584', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1429, 'n_words': 327}