2020-07-23 13:05:13 +03:00
|
|
|
import * as React from "react";
|
|
|
|
import * as Constants from "~/common/constants";
|
2020-09-09 11:41:25 +03:00
|
|
|
import * as Strings from "~/common/strings";
|
2020-07-23 13:05:13 +03:00
|
|
|
import * as System from "~/components/system";
|
2020-08-02 09:00:04 +03:00
|
|
|
import * as Validations from "~/common/validations";
|
2020-09-10 06:28:48 +03:00
|
|
|
import * as SVG from "~/common/svg";
|
2020-07-23 13:05:13 +03:00
|
|
|
|
|
|
|
import { css } from "@emotion/react";
|
2020-08-15 05:08:17 +03:00
|
|
|
import { DataMeterBar } from "~/components/core/DataMeter";
|
2020-09-04 01:42:08 +03:00
|
|
|
import { dispatchCustomEvent } from "~/common/custom-events";
|
2020-09-25 09:31:56 +03:00
|
|
|
import { SidebarWarningMessage } from "~/components/core/WarningMessage";
|
2020-07-23 13:05:13 +03:00
|
|
|
|
|
|
|
const STYLES_FILE_HIDDEN = css`
|
|
|
|
height: 1px;
|
|
|
|
width: 1px;
|
|
|
|
opacity: 0;
|
|
|
|
visibility: hidden;
|
|
|
|
position: fixed;
|
|
|
|
top: -1px;
|
|
|
|
left: -1px;
|
|
|
|
`;
|
|
|
|
|
2020-09-11 00:03:51 +03:00
|
|
|
const STYLES_FILE_LINE = css`
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: space-between;
|
|
|
|
width: 100%;
|
2020-09-16 22:16:38 +03:00
|
|
|
padding: 12px 16px;
|
|
|
|
background-color: ${Constants.system.white};
|
|
|
|
margin-bottom: 1px;
|
2020-09-11 00:03:51 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_FILE_NAME = css`
|
|
|
|
min-width: 10%;
|
|
|
|
width: 100%;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
overflow: hidden;
|
|
|
|
white-space: nowrap;
|
|
|
|
font-size: 0.9rem;
|
2020-09-16 22:16:38 +03:00
|
|
|
font-family: ${Constants.font.medium};
|
2020-09-11 00:03:51 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_FILE_STATUS = css`
|
|
|
|
flex-shrink: 0;
|
2020-09-16 22:16:38 +03:00
|
|
|
margin-right: 16px;
|
2020-09-11 00:03:51 +03:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
`;
|
|
|
|
|
2020-09-11 00:53:26 +03:00
|
|
|
const STYLES_BAR_CONTAINER = css`
|
|
|
|
background: ${Constants.system.white};
|
|
|
|
border-radius: 4px;
|
|
|
|
padding: 16px;
|
2020-07-23 13:05:13 +03:00
|
|
|
margin-top: 48px;
|
|
|
|
`;
|
|
|
|
|
2020-09-09 11:41:25 +03:00
|
|
|
const STYLES_PERFORMANCE = css`
|
|
|
|
font-family: ${Constants.font.code};
|
|
|
|
font-size: 12px;
|
|
|
|
display: block;
|
|
|
|
margin: 0 0 8px 0;
|
2020-08-15 05:08:17 +03:00
|
|
|
`;
|
|
|
|
|
2020-09-10 06:28:48 +03:00
|
|
|
const STYLES_ICONS = css`
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
justify-content: center;
|
|
|
|
margin: 64px 0;
|
|
|
|
`;
|
|
|
|
|
2020-07-23 13:05:13 +03:00
|
|
|
export default class SidebarAddFileToBucket extends React.Component {
|
2020-09-25 06:16:10 +03:00
|
|
|
_handleUpload = (e) => {
|
|
|
|
this.props.onUpload({
|
2020-09-20 21:31:08 +03:00
|
|
|
files: e.target.files,
|
|
|
|
slate:
|
2020-09-21 00:34:31 +03:00
|
|
|
this.props.current && this.props.current.slateId
|
|
|
|
? { id: this.props.current.slateId }
|
2020-09-20 21:31:08 +03:00
|
|
|
: null,
|
2020-09-03 09:00:02 +03:00
|
|
|
});
|
2020-09-25 06:16:10 +03:00
|
|
|
this.props.onCancel();
|
2020-07-23 13:05:13 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
2020-09-13 03:54:26 +03:00
|
|
|
let loaded = 0;
|
|
|
|
let total = 0;
|
2020-09-11 00:03:51 +03:00
|
|
|
if (this.props.fileLoading) {
|
2020-09-13 03:54:26 +03:00
|
|
|
for (let file of Object.values(this.props.fileLoading)) {
|
|
|
|
if (typeof file.loaded === "number" && typeof file.total === "number") {
|
2020-09-13 04:49:58 +03:00
|
|
|
total += file.total;
|
|
|
|
loaded += file.loaded;
|
2020-09-13 03:54:26 +03:00
|
|
|
}
|
|
|
|
}
|
2020-09-11 00:03:51 +03:00
|
|
|
}
|
2020-07-23 13:05:13 +03:00
|
|
|
return (
|
|
|
|
<React.Fragment>
|
2020-09-08 02:28:50 +03:00
|
|
|
<System.P
|
|
|
|
style={{
|
|
|
|
fontFamily: Constants.font.semiBold,
|
|
|
|
fontSize: Constants.typescale.lvl3,
|
2020-09-10 06:28:48 +03:00
|
|
|
marginBottom: "64px",
|
2020-09-08 02:28:50 +03:00
|
|
|
}}
|
|
|
|
>
|
2020-09-13 04:12:56 +03:00
|
|
|
Upload data
|
2020-08-27 02:24:43 +03:00
|
|
|
</System.P>
|
|
|
|
<input
|
|
|
|
css={STYLES_FILE_HIDDEN}
|
|
|
|
multiple
|
|
|
|
type="file"
|
|
|
|
id="file"
|
|
|
|
onChange={this._handleUpload}
|
|
|
|
/>
|
2020-09-10 06:28:48 +03:00
|
|
|
<div css={STYLES_ICONS}>
|
|
|
|
<SVG.Sound height="24px" style={{ margin: "0 16px" }} />
|
|
|
|
<SVG.Document height="24px" style={{ margin: "0 16px" }} />
|
|
|
|
<SVG.Image height="24px" style={{ margin: "0 16px" }} />
|
|
|
|
<SVG.Book height="24px" style={{ margin: "0 16px" }} />
|
|
|
|
<SVG.Video height="24px" style={{ margin: "0 16px" }} />
|
|
|
|
</div>
|
2020-09-09 22:35:39 +03:00
|
|
|
<System.P style={{ marginTop: 24 }}>
|
2020-09-10 06:28:48 +03:00
|
|
|
Click below or drop a file anywhere on the page to upload a file
|
2020-09-21 00:34:31 +03:00
|
|
|
{this.props.current &&
|
|
|
|
(this.props.current.slatename ||
|
|
|
|
(this.props.current.data && this.props.current.data.name)) ? (
|
2020-09-10 06:28:48 +03:00
|
|
|
<span>
|
|
|
|
{" "}
|
|
|
|
to{" "}
|
|
|
|
<strong>
|
2020-09-27 23:11:04 +03:00
|
|
|
{Strings.getPresentationSlateName(this.props.current)}
|
2020-09-10 06:28:48 +03:00
|
|
|
</strong>
|
|
|
|
</span>
|
|
|
|
) : (
|
|
|
|
""
|
|
|
|
)}
|
|
|
|
.
|
2020-09-09 22:35:39 +03:00
|
|
|
</System.P>
|
2020-09-12 01:25:33 +03:00
|
|
|
|
2020-09-25 09:31:56 +03:00
|
|
|
<SidebarWarningMessage />
|
2020-09-25 08:32:56 +03:00
|
|
|
|
2020-09-11 00:53:26 +03:00
|
|
|
<System.ButtonPrimary
|
|
|
|
full
|
|
|
|
type="label"
|
|
|
|
htmlFor="file"
|
|
|
|
style={{ marginTop: 24 }}
|
|
|
|
>
|
2020-09-13 03:00:58 +03:00
|
|
|
Add file
|
2020-09-11 00:53:26 +03:00
|
|
|
</System.ButtonPrimary>
|
2020-07-23 13:05:13 +03:00
|
|
|
|
2020-08-16 04:32:38 +03:00
|
|
|
<br />
|
2020-09-25 06:16:10 +03:00
|
|
|
{this.props.fileLoading &&
|
|
|
|
Object.keys(this.props.fileLoading).length ? (
|
2020-09-11 00:53:26 +03:00
|
|
|
<div css={STYLES_BAR_CONTAINER}>
|
2020-09-11 00:03:51 +03:00
|
|
|
<strong css={STYLES_PERFORMANCE}>
|
|
|
|
{Strings.bytesToSize(loaded)} / {Strings.bytesToSize(total)}
|
|
|
|
</strong>
|
2020-09-16 22:16:38 +03:00
|
|
|
<DataMeterBar bytes={loaded} maximumBytes={total} />
|
2020-09-11 00:53:26 +03:00
|
|
|
</div>
|
2020-09-11 00:03:51 +03:00
|
|
|
) : null}
|
2020-09-11 00:53:26 +03:00
|
|
|
<div style={{ marginTop: 24 }}>
|
|
|
|
{this.props.fileLoading
|
|
|
|
? Object.values(this.props.fileLoading).map((file) => (
|
2020-09-14 23:42:52 +03:00
|
|
|
<div css={STYLES_FILE_LINE} key={file.name}>
|
2020-09-11 00:53:26 +03:00
|
|
|
<div css={STYLES_FILE_STATUS}>
|
2020-09-20 21:31:08 +03:00
|
|
|
{file.failed ? (
|
2020-09-16 22:16:38 +03:00
|
|
|
<SVG.Alert
|
|
|
|
height="24px"
|
|
|
|
style={{ color: Constants.system.red }}
|
|
|
|
/>
|
2020-09-20 21:31:08 +03:00
|
|
|
) : file.loaded === file.total ? (
|
|
|
|
<SVG.CheckBox height="24px" />
|
2020-09-11 00:53:26 +03:00
|
|
|
) : (
|
|
|
|
<System.LoaderSpinner
|
|
|
|
style={{ width: "20px", height: "20px", margin: "2px" }}
|
|
|
|
/>
|
|
|
|
)}
|
2020-09-11 00:03:51 +03:00
|
|
|
</div>
|
2020-09-16 22:16:38 +03:00
|
|
|
<div
|
|
|
|
css={STYLES_FILE_NAME}
|
|
|
|
style={file.failed ? { color: Constants.system.red } : null}
|
|
|
|
>
|
|
|
|
{file.name}
|
|
|
|
</div>
|
2020-09-11 00:53:26 +03:00
|
|
|
</div>
|
|
|
|
))
|
|
|
|
: null}
|
|
|
|
</div>
|
2020-07-23 13:05:13 +03:00
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|