2020-07-23 13:05:13 +03:00
|
|
|
import * as React from "react";
|
|
|
|
import * as Constants from "~/common/constants";
|
|
|
|
import * as System from "~/components/system";
|
2020-08-02 09:00:04 +03:00
|
|
|
import * as Validations from "~/common/validations";
|
2020-07-23 13:05:13 +03:00
|
|
|
|
|
|
|
import { css } from "@emotion/react";
|
|
|
|
|
|
|
|
const STYLES_FILE_HIDDEN = css`
|
|
|
|
height: 1px;
|
|
|
|
width: 1px;
|
|
|
|
opacity: 0;
|
|
|
|
visibility: hidden;
|
|
|
|
position: fixed;
|
|
|
|
top: -1px;
|
|
|
|
left: -1px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_FOCUS = css`
|
|
|
|
font-size: ${Constants.typescale.lvl1};
|
|
|
|
font-family: ${Constants.font.medium};
|
|
|
|
overflow-wrap: break-word;
|
|
|
|
width: 100%;
|
|
|
|
|
|
|
|
strong {
|
|
|
|
font-family: ${Constants.font.semiBold};
|
|
|
|
font-weight: 400;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_SUBTEXT = css`
|
|
|
|
margin-top: 8px;
|
|
|
|
font-size: 12px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_ITEM = css`
|
|
|
|
margin-top: 16px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_IMAGE_PREVIEW = css`
|
|
|
|
display: block;
|
|
|
|
width: 100%;
|
|
|
|
margin-top: 48px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
export default class SidebarAddFileToBucket extends React.Component {
|
|
|
|
_handleUpload = async (e) => {
|
|
|
|
e.persist();
|
|
|
|
let file = e.target.files[0];
|
|
|
|
|
|
|
|
if (!file) {
|
2020-08-02 09:00:04 +03:00
|
|
|
alert("TODO: Something went wrong");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-02 10:29:24 +03:00
|
|
|
console.log(file);
|
|
|
|
|
2020-08-02 09:00:04 +03:00
|
|
|
const isAllowed = Validations.isFileTypeAllowed(file.type);
|
|
|
|
if (!isAllowed) {
|
|
|
|
alert("TODO: File type is not allowed, yet.");
|
2020-07-23 13:05:13 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-27 11:33:39 +03:00
|
|
|
await this.props.onSetFile({
|
|
|
|
file,
|
2020-08-02 09:00:04 +03:00
|
|
|
slate: this.props.data && this.props.data.slateId ? { id: this.props.data.slateId } : null,
|
2020-07-27 11:33:39 +03:00
|
|
|
});
|
2020-07-23 13:05:13 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
2020-08-02 09:41:18 +03:00
|
|
|
<System.P style={{ fontFamily: Constants.font.semiBold }}>Upload data</System.P>
|
2020-08-02 09:00:04 +03:00
|
|
|
<input css={STYLES_FILE_HIDDEN} type="file" id="file" onChange={this._handleUpload} />
|
2020-07-23 13:05:13 +03:00
|
|
|
|
2020-07-27 11:33:39 +03:00
|
|
|
{this.props.data && this.props.data.decorator === "SLATE" ? (
|
|
|
|
<System.P style={{ marginTop: 24 }}>
|
2020-08-02 09:41:18 +03:00
|
|
|
This will add data to your Slate named <strong>{this.props.data.slatename}</strong>.
|
2020-07-27 11:33:39 +03:00
|
|
|
</System.P>
|
|
|
|
) : null}
|
|
|
|
|
2020-08-02 22:17:13 +03:00
|
|
|
<System.ButtonPrimary
|
|
|
|
full
|
2020-07-23 13:05:13 +03:00
|
|
|
type="label"
|
|
|
|
htmlFor="file"
|
|
|
|
style={{ marginTop: 24 }}
|
|
|
|
loading={this.props.fileLoading}
|
|
|
|
>
|
|
|
|
Add file
|
2020-08-02 22:17:13 +03:00
|
|
|
</System.ButtonPrimary>
|
2020-07-23 13:05:13 +03:00
|
|
|
|
|
|
|
{!this.props.fileLoading ? (
|
2020-08-02 22:17:13 +03:00
|
|
|
<System.ButtonSecondary
|
|
|
|
full
|
2020-07-23 13:05:13 +03:00
|
|
|
style={{ marginTop: 16 }}
|
|
|
|
onClick={this.props.onCancel}
|
|
|
|
>
|
|
|
|
Cancel
|
2020-08-02 22:17:13 +03:00
|
|
|
</System.ButtonSecondary>
|
2020-07-23 13:05:13 +03:00
|
|
|
) : null}
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|