2020-07-01 09:41:54 +03:00
|
|
|
import * as React from 'react';
|
|
|
|
import * as System from '~/components/system';
|
|
|
|
import * as Actions from '~/common/actions';
|
2020-04-09 00:29:13 +03:00
|
|
|
|
2020-07-01 09:41:54 +03:00
|
|
|
import { css } from '@emotion/react';
|
2020-04-09 00:29:13 +03:00
|
|
|
|
2020-07-01 09:41:54 +03:00
|
|
|
import ScenePage from '~/components/core/ScenePage';
|
|
|
|
import Avatar from '~/components/core/Avatar';
|
2020-06-08 09:45:53 +03:00
|
|
|
|
|
|
|
const STYLES_FILE_HIDDEN = css`
|
|
|
|
height: 1px;
|
|
|
|
width: 1px;
|
|
|
|
opacity: 0;
|
|
|
|
visibility: hidden;
|
|
|
|
position: fixed;
|
|
|
|
top: -1px;
|
|
|
|
left: -1px;
|
|
|
|
`;
|
2020-04-09 00:29:13 +03:00
|
|
|
|
|
|
|
export default class SceneEditAccount extends React.Component {
|
2020-07-01 09:41:54 +03:00
|
|
|
state = { name: this.props.viewer.name };
|
|
|
|
|
2020-06-08 09:45:53 +03:00
|
|
|
_handleUpload = async (e) => {
|
|
|
|
e.persist();
|
|
|
|
let file = e.target.files[0];
|
|
|
|
|
|
|
|
if (!file) {
|
2020-07-01 09:41:54 +03:00
|
|
|
alert('Something went wrong');
|
2020-06-08 09:45:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
let data = new FormData();
|
2020-07-01 09:41:54 +03:00
|
|
|
data.append('image', file);
|
2020-06-08 09:45:53 +03:00
|
|
|
|
|
|
|
const options = {
|
2020-07-01 09:41:54 +03:00
|
|
|
method: 'POST',
|
2020-06-08 09:45:53 +03:00
|
|
|
headers: {
|
2020-07-01 09:41:54 +03:00
|
|
|
Accept: 'application/json',
|
2020-06-08 09:45:53 +03:00
|
|
|
},
|
|
|
|
body: data,
|
|
|
|
};
|
|
|
|
|
2020-06-09 21:00:36 +03:00
|
|
|
await fetch(`/_/upload/avatar`, options);
|
2020-06-08 09:45:53 +03:00
|
|
|
};
|
|
|
|
|
2020-07-01 09:41:54 +03:00
|
|
|
_handleSave = async (e) => {
|
|
|
|
const options = {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
Accept: 'application/json',
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
},
|
|
|
|
credentials: 'include',
|
|
|
|
body: JSON.stringify({ local: { name: this.state.name } }),
|
|
|
|
};
|
|
|
|
|
|
|
|
await fetch(`/_/local-settings`, options);
|
|
|
|
};
|
|
|
|
|
2020-04-09 00:29:13 +03:00
|
|
|
_handleChange = (e) => {
|
2020-07-01 09:41:54 +03:00
|
|
|
e.persist();
|
|
|
|
this.setState({ [e.target.name]: e.target.value });
|
2020-04-09 00:29:13 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<ScenePage>
|
|
|
|
<System.H1>Account</System.H1>
|
|
|
|
|
|
|
|
<System.DescriptionGroup
|
|
|
|
style={{ marginTop: 48 }}
|
|
|
|
label="Avatar image"
|
|
|
|
description="This image will appear in various lists."
|
|
|
|
/>
|
|
|
|
|
2020-07-01 09:41:54 +03:00
|
|
|
<Avatar style={{ marginTop: 24 }} size={256} url={this.props.viewer.photoURL} />
|
2020-04-09 00:29:13 +03:00
|
|
|
|
|
|
|
<div style={{ marginTop: 24 }}>
|
2020-07-01 09:41:54 +03:00
|
|
|
<input css={STYLES_FILE_HIDDEN} type="file" id="file" onChange={this._handleUpload} />
|
|
|
|
<System.ButtonPrimary style={{ margin: '0 16px 16px 0' }} type="label" htmlFor="file">
|
2020-04-09 00:29:13 +03:00
|
|
|
Upload
|
|
|
|
</System.ButtonPrimary>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<System.Input
|
|
|
|
containerStyle={{ marginTop: 48 }}
|
|
|
|
label="Name"
|
|
|
|
description="The name of your Filecoin Client can be seen by your peers."
|
|
|
|
name="name"
|
2020-07-01 09:41:54 +03:00
|
|
|
value={this.state.name}
|
2020-04-09 00:29:13 +03:00
|
|
|
placeholder="Name"
|
|
|
|
onChange={this._handleChange}
|
|
|
|
/>
|
2020-07-01 09:41:54 +03:00
|
|
|
|
|
|
|
<div style={{ marginTop: 24 }}>
|
|
|
|
<System.ButtonPrimary onClick={this._handleSave}>Save</System.ButtonPrimary>
|
|
|
|
</div>
|
2020-04-09 00:29:13 +03:00
|
|
|
</ScenePage>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|