2020-06-19 06:57:57 +03:00
|
|
|
import * as React from "react";
|
2020-07-24 10:45:21 +03:00
|
|
|
import * as Actions from "~/common/actions";
|
2020-06-19 06:57:57 +03:00
|
|
|
import * as System from "~/components/system";
|
2020-09-08 00:45:58 +03:00
|
|
|
import * as SVG from "~/common/svg";
|
|
|
|
import * as Constants from "~/common/constants";
|
2020-04-09 00:29:13 +03:00
|
|
|
|
2020-06-19 06:57:57 +03:00
|
|
|
import { css } from "@emotion/react";
|
2020-09-08 00:45:58 +03:00
|
|
|
import { TabGroup } from "~/components/core/TabGroup";
|
|
|
|
import { ButtonPrimary } from "~/components/system/components/Buttons";
|
2020-04-09 00:29:13 +03:00
|
|
|
|
2020-06-19 06:57:57 +03:00
|
|
|
import ScenePage from "~/components/core/ScenePage";
|
2020-08-12 11:22:28 +03:00
|
|
|
import DataView from "~/components/core/DataView";
|
2020-08-08 03:22:45 +03:00
|
|
|
import DataMeter from "~/components/core/DataMeter";
|
2020-08-22 07:25:34 +03:00
|
|
|
import ScenePageHeader from "~/components/core/ScenePageHeader";
|
2020-09-08 00:45:58 +03:00
|
|
|
|
|
|
|
const VIEW_LIMIT = 20;
|
|
|
|
|
|
|
|
const STYLES_ICON_BOX = css`
|
|
|
|
height: 32px;
|
|
|
|
width: 32px;
|
|
|
|
display: inline-flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
cursor: pointer;
|
|
|
|
margin-left: 16px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_HEADER_LINE = css`
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
margin-top: 80px;
|
|
|
|
margin-bottom: 42px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_ARROWS = css`
|
|
|
|
text-align: end;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_ICON_ELEMENT = css`
|
|
|
|
height: 40px;
|
|
|
|
width: 40px;
|
|
|
|
display: inline-flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
color: #565151;
|
|
|
|
user-select: none;
|
|
|
|
cursor: pointer;
|
|
|
|
pointer-events: auto;
|
|
|
|
margin: 16px 8px;
|
|
|
|
|
|
|
|
:hover {
|
|
|
|
color: ${Constants.system.brand};
|
|
|
|
}
|
|
|
|
|
|
|
|
svg {
|
|
|
|
transform: rotate(0deg);
|
|
|
|
transition: 200ms ease transform;
|
|
|
|
}
|
|
|
|
`;
|
2020-04-09 00:29:13 +03:00
|
|
|
|
2020-07-24 19:35:00 +03:00
|
|
|
const POLLING_INTERVAL = 10000;
|
|
|
|
|
2020-04-09 00:29:13 +03:00
|
|
|
export default class SceneFilesFolder extends React.Component {
|
2020-07-24 10:45:21 +03:00
|
|
|
_interval;
|
2020-04-09 00:29:13 +03:00
|
|
|
|
2020-09-08 00:45:58 +03:00
|
|
|
state = {
|
|
|
|
view: "list",
|
|
|
|
startIndex: 0,
|
|
|
|
};
|
|
|
|
|
2020-07-24 10:45:21 +03:00
|
|
|
loop = async () => {
|
|
|
|
let jobs = [];
|
|
|
|
|
|
|
|
this.props.viewer.library[0].children.forEach((d) => {
|
|
|
|
if (d.networks && d.networks.includes("FILECOIN")) {
|
2020-08-01 05:04:44 +03:00
|
|
|
console.log(d);
|
2020-07-24 10:45:21 +03:00
|
|
|
jobs.push({
|
|
|
|
ipfs: d.ipfs,
|
|
|
|
cid: d.ipfs.replace("/ipfs/", ""),
|
|
|
|
job: d.job,
|
2020-08-02 07:09:49 +03:00
|
|
|
error: d.error,
|
2020-07-24 10:45:21 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-07-24 19:35:00 +03:00
|
|
|
console.log({ jobs });
|
2020-08-02 09:00:04 +03:00
|
|
|
if (jobs.length) {
|
|
|
|
const response = await Actions.checkCIDStatus(jobs);
|
2020-07-24 10:45:21 +03:00
|
|
|
|
2020-08-02 09:00:04 +03:00
|
|
|
console.log(response);
|
2020-07-24 10:45:21 +03:00
|
|
|
|
2020-08-02 09:00:04 +03:00
|
|
|
if (response && response.update) {
|
|
|
|
await this.props.onRehydrate();
|
|
|
|
}
|
2020-07-24 10:45:21 +03:00
|
|
|
}
|
|
|
|
|
2020-07-27 12:10:12 +03:00
|
|
|
if (this._interval) {
|
|
|
|
this._interval = window.setTimeout(this.loop, POLLING_INTERVAL);
|
|
|
|
}
|
2020-04-09 00:29:13 +03:00
|
|
|
};
|
|
|
|
|
2020-07-24 10:45:21 +03:00
|
|
|
componentDidMount() {
|
2020-09-08 00:45:58 +03:00
|
|
|
this.loop();
|
2020-07-24 10:45:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
window.clearTimeout(this._interval);
|
|
|
|
this._interval = null;
|
|
|
|
}
|
|
|
|
|
2020-08-04 10:35:55 +03:00
|
|
|
componentDidUpdate(prevProps) {
|
|
|
|
if (!this._interval) {
|
|
|
|
console.log("Starting loop again");
|
|
|
|
this._interval = this.loop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-08 00:45:58 +03:00
|
|
|
_increment = (direction) => {
|
|
|
|
if (
|
|
|
|
direction > 0 &&
|
|
|
|
this.state.startIndex + VIEW_LIMIT <
|
|
|
|
this.props.viewer.library[0].children.length
|
|
|
|
) {
|
|
|
|
this.setState({ startIndex: this.state.startIndex + VIEW_LIMIT });
|
|
|
|
} else if (direction < 0 && this.state.startIndex - VIEW_LIMIT >= 0) {
|
|
|
|
this.setState({ startIndex: this.state.startIndex - VIEW_LIMIT });
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-04-09 00:29:13 +03:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<ScenePage>
|
2020-09-08 00:45:58 +03:00
|
|
|
<ScenePageHeader
|
|
|
|
title="Data"
|
|
|
|
actions={
|
|
|
|
<ButtonPrimary
|
|
|
|
onClick={() => {
|
|
|
|
this.props.onAction({
|
|
|
|
type: "SIDEBAR",
|
|
|
|
value: "SIDEBAR_ADD_FILE_TO_BUCKET",
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
>
|
2020-09-13 03:00:58 +03:00
|
|
|
Upload data
|
2020-09-08 00:45:58 +03:00
|
|
|
</ButtonPrimary>
|
|
|
|
}
|
2020-08-12 11:22:28 +03:00
|
|
|
/>
|
2020-09-08 00:45:58 +03:00
|
|
|
<TabGroup disabled tabs={["Usage"]} />
|
2020-09-08 01:16:02 +03:00
|
|
|
<DataMeter
|
|
|
|
stats={this.props.viewer.stats}
|
|
|
|
style={{ margin: "48px 0 48px 0" }}
|
|
|
|
/>
|
2020-09-08 00:45:58 +03:00
|
|
|
<div css={STYLES_HEADER_LINE}>
|
|
|
|
<TabGroup disabled tabs={["Uploads"]} style={{ margin: 0 }} />
|
|
|
|
<React.Fragment>
|
|
|
|
<div
|
|
|
|
css={STYLES_ICON_BOX}
|
|
|
|
onClick={() => {
|
|
|
|
this.setState({ view: "list" });
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<SVG.ListView
|
|
|
|
style={{
|
|
|
|
color:
|
|
|
|
this.state.view === "list"
|
|
|
|
? Constants.system.black
|
|
|
|
: "rgba(0,0,0,0.25)",
|
|
|
|
}}
|
|
|
|
height="24px"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
css={STYLES_ICON_BOX}
|
|
|
|
onClick={() => {
|
|
|
|
this.setState({ view: "grid" });
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<SVG.GridView
|
|
|
|
style={{
|
|
|
|
color:
|
|
|
|
this.state.view === "grid"
|
|
|
|
? Constants.system.black
|
|
|
|
: "rgba(0,0,0,0.25)",
|
|
|
|
}}
|
|
|
|
height="24px"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</React.Fragment>
|
|
|
|
</div>
|
2020-09-08 01:16:02 +03:00
|
|
|
<DataView
|
|
|
|
view={this.state.view}
|
|
|
|
viewer={this.props.viewer}
|
|
|
|
items={this.props.viewer.library[0].children.slice(
|
|
|
|
this.state.startIndex,
|
|
|
|
this.state.startIndex + VIEW_LIMIT
|
|
|
|
)}
|
|
|
|
onAction={this.props.onAction}
|
|
|
|
onRehydrate={this.props.onRehydrate}
|
|
|
|
/>
|
|
|
|
<div css={STYLES_ARROWS}>
|
|
|
|
<span
|
|
|
|
css={STYLES_ICON_ELEMENT}
|
|
|
|
style={
|
|
|
|
this.state.startIndex - VIEW_LIMIT >= 0
|
|
|
|
? null
|
|
|
|
: { cursor: "not-allowed", color: Constants.system.border }
|
|
|
|
}
|
|
|
|
onClick={() => this._increment(-1)}
|
|
|
|
>
|
|
|
|
<SVG.NavigationArrow
|
|
|
|
height="24px"
|
|
|
|
style={{ transform: `rotate(180deg)` }}
|
|
|
|
/>
|
|
|
|
</span>
|
|
|
|
<span
|
|
|
|
css={STYLES_ICON_ELEMENT}
|
|
|
|
style={
|
|
|
|
this.state.startIndex + VIEW_LIMIT <
|
|
|
|
this.props.viewer.library[0].children.length
|
|
|
|
? null
|
|
|
|
: { cursor: "not-allowed", color: Constants.system.border }
|
|
|
|
}
|
|
|
|
onClick={() => this._increment(1)}
|
|
|
|
>
|
|
|
|
<SVG.NavigationArrow height="24px" />
|
|
|
|
</span>
|
|
|
|
</div>
|
2020-04-09 00:29:13 +03:00
|
|
|
</ScenePage>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|