-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.jsx
56 lines (49 loc) · 1.63 KB
/
index.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import React from 'react'
import cls from 'classnames'
import ImageUploader from 'patchkit-image-uploader'
import t from 'patchwork-translations'
export default class ProfileSetup extends React.Component {
static propTypes = {
setIsValid: React.PropTypes.func.isRequired,
onSubmit: React.PropTypes.func.isRequired,
currentValue: React.PropTypes.string,
className: React.PropTypes.string
}
constructor(props) {
super(props)
this.state = { wasImageAdded: false }
}
getId() {
return this.props.id || app.user.id
}
componentDidMount() {
this.props.setIsValid(true)
}
onChangeImg() {
// note that the image was set so that vertical centering can be turned off
this.setState({ wasImageAdded: true })
}
submit(cb) {
const canvas = this.refs.imageInputContainer.querySelector('canvas')
if (!canvas)
return cb()
ImageUploader.canvasToPng(canvas, (err, buffer) => {
if (err)
return cb(err)
this.props.onSubmit(buffer, cb)
})
}
render() {
const currentValue = this.props.currentValue
const hasImg = !!currentValue || this.state.wasImageAdded
const useVerticalCentering = !hasImg // dont vertically center if an image is assigned
return <div className={cls(this.props.className, { 'vertical-center': useVerticalCentering })}>
<h1><span>{t('chooseProfilePicturePrompt')}</span></h1>
<form className="block" onSubmit={e=>e.preventDefault()}>
<fieldset>
<div ref="imageInputContainer"><ImageUploader current={currentValue} onChange={this.onChangeImg.bind(this)} /></div>
</fieldset>
</form>
</div>
}
}