import * as React from "react";
import * as Constants from "~/common/constants";
import * as Strings from "~/common/strings";
import * as System from "~/components/system";
import * as Actions from "~/common/actions";
import { css } from "@emotion/react";
import Section from "~/components/core/Section";
import SlateMediaObject from "~/components/core/SlateMediaObject";
const COLUMNS_SCHEMA = [
{ key: "cid", name: "CID", width: "100%" },
{
key: "size",
name: "Size",
width: "84px",
},
{ key: "type", name: "Type", type: "TEXT_TAG", width: "172px" },
{
key: "networks",
name: "Networks",
type: "NETWORK_TYPE",
},
{
key: "storage",
name: "Storage Deal Status",
width: "148px",
type: "STORAGE_DEAL_STATUS",
},
];
const STYLES_LINK = css`
font-family: ${Constants.font.semiBold};
font-weight: 400;
cursor: pointer;
transition: 200ms ease all;
:hover {
color: ${Constants.system.brand};
}
`;
const STYLES_LABEL = css`
letter-spacing: 0.1px;
font-size: 12px;
text-transform: uppercase;
font-family: ${Constants.font.semiBold};
font-weight: 400;
color: ${Constants.system.black};
`;
const STYLES_SECTION = css`
margin: 12px 0 16px 0;
`;
const delay = (ms) => new Promise((resolve) => window.setTimeout(resolve, ms));
/*
{this.state.loading || isOnNetwork ? null : (
this._handleMakeDeal(each)}>
Store on Filecoin
)}
*/
export default class DataView extends React.Component {
state = {
selectedRowId: null,
};
async componentDidMount() {
await this._handleUpdate();
}
_handleUpdate = async () => {
// NOTE(jim): Hack to handle some race conditions.
await delay(200);
System.dispatchCustomEvent({
name: "slate-global-create-carousel",
detail: {
slides: this.props.items.map((each) => {
const cid = each.ipfs.replace("/ipfs/", "");
return {
id: each.id,
cid,
data: each,
renderPlaceholder: true,
component: ,
};
}),
},
});
};
_handleSelect = (index) => {
System.dispatchCustomEvent({
name: "slate-global-open-carousel",
detail: { index },
});
};
_handleMakeDeal = (data) => {
this.props.onAction({
type: "SIDEBAR",
value: "SIDEBAR_FILE_STORAGE_DEAL",
data,
});
};
_handleDelete = async (cid) => {
this.setState({ loading: true });
if (!window.confirm("Are you sure you want to delete this? It will be removed from your Slates too.")) {
this.setState({ loading: false });
return null;
}
const response = await Actions.deleteBucketItem({ cid });
console.log(response);
if (!response) {
this.setState({ loading: false });
alert("TODO: Broken response error");
return;
}
if (response.error) {
this.setState({ loading: false });
alert("TODO: Bucket delete error");
return;
}
await this.props.onRehydrate();
await this._handleUpdate();
this.setState({ loading: false });
};
_handleClick = (e) => {
this.setState({ [e.target.name]: e.target.value });
};
render() {
const columns = COLUMNS_SCHEMA;
const rows = this.props.items.map((each, index) => {
const cid = each.ipfs.replace("/ipfs/", "");
const isOnNetwork = each.networks && each.networks.includes("FILECOIN");
return {
...each,
cid: (
this._handleSelect(index)}>
{cid}
),
size: {Strings.bytesToSize(each.size)},
children: (
Actions
this._handleDelete(cid)}>
Delete
{each.error ? (
Errors
{each.error}
) : null}
),
};
});
const data = {
columns,
rows,
};
return (
);
}
}