slate/scenes/SceneFilesFolder.js

98 lines
2.3 KiB
JavaScript
Raw Normal View History

2020-06-19 06:57:57 +03:00
import * as React from "react";
import * as Actions from "~/common/actions";
2020-06-19 06:57:57 +03:00
import * as System from "~/components/system";
2020-06-19 06:57:57 +03:00
import { css } from "@emotion/react";
2020-06-19 06:57:57 +03:00
import ScenePage from "~/components/core/ScenePage";
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";
const POLLING_INTERVAL = 10000;
export default class SceneFilesFolder extends React.Component {
_interval;
loop = async () => {
let jobs = [];
this.props.viewer.library[0].children.forEach((d) => {
if (d.networks && d.networks.includes("FILECOIN")) {
console.log(d);
jobs.push({
ipfs: d.ipfs,
cid: d.ipfs.replace("/ipfs/", ""),
job: d.job,
error: d.error,
});
}
});
console.log({ jobs });
if (jobs.length) {
const response = await Actions.checkCIDStatus(jobs);
console.log(response);
if (response && response.update) {
await this.props.onRehydrate();
}
}
2020-07-27 12:10:12 +03:00
if (this._interval) {
this._interval = window.setTimeout(this.loop, POLLING_INTERVAL);
}
};
componentDidMount() {
this._interval = this.loop();
}
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();
}
}
render() {
return (
<ScenePage>
2020-08-22 07:25:34 +03:00
<ScenePageHeader title="Data [WIP]">
This scene is currently a work in progress.
</ScenePageHeader>
2020-08-04 05:57:27 +03:00
2020-08-22 07:25:34 +03:00
<DataMeter
stats={this.props.viewer.stats}
2020-08-26 07:13:50 +03:00
style={{ margin: "48px 0 48px 0" }}
2020-08-22 07:25:34 +03:00
/>
2020-08-08 03:22:45 +03:00
<DataView
buttons={[
{
name: "Upload data",
2020-06-19 06:57:57 +03:00
type: "SIDEBAR",
value: "SIDEBAR_ADD_FILE_TO_BUCKET",
},
{
name: "Filecoin archive",
type: "SIDEBAR",
value: "SIDEBAR_FILECOIN_ARCHIVE",
},
]}
viewer={this.props.viewer}
items={this.props.viewer.library[0].children}
onAction={this.props.onAction}
onRehydrate={this.props.onRehydrate}
/>
</ScenePage>
);
}
}