-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.jsx
56 lines (53 loc) · 1.46 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 ModalFlow from 'patchkit-modal/flow'
import Welcome from './welcome'
import ProfileName from 'patchkit-form-profile-name'
import ProfileImage from 'patchkit-form-profile-image'
import schemas from 'ssb-msg-schemas'
const FORMS = [Welcome, ProfileName, ProfileImage]
export default class SetupFlow extends React.Component {
static contextTypes = {
ssb: React.PropTypes.object
}
static propTypes = {
id: React.PropTypes.string.isRequired
}
onSubmitName(name, cb) {
// publish update message
this.context.ssb.publish(schemas.name(this.props.id, name), cb)
}
onSubmitImage(buffer, cb) {
// upload blob
this.context.ssb.patchwork.addFileToBlobs(buffer.toString('base64'), (err, hash) => {
if (err)
return cb(err)
// publish update message
const imageLink = {
link: hash,
size: buffer.length,
type: 'image/png',
width: 512,
height: 512
}
this.context.ssb.publish(schemas.image(this.props.id, imageLink), cb)
})
}
render() {
return <ModalFlow
className="fullheight"
Forms={FORMS}
formsProps={[
{},
{
className: 'text-center vertical-center',
onSubmit: this.onSubmitName.bind(this)
},
{
className: 'text-center',
onSubmit: this.onSubmitImage.bind(this)
},
]}
isOpen={this.props.isOpen}
onClose={this.props.onClose} />
}
}