import React from 'react'; import './SkynetExport.css'; import CheckboxTree from 'react-checkbox-tree'; import {connect} from 'react-redux'; import IPCContainer from '../IPCContainer/IPCContainer'; import {notifyApplicationBusy} from '../../redux/actions/common_actions'; import {notifyError, notifyInfo} from '../../redux/actions/error_actions'; import Box from '../../components/UI/Box/Box'; import {displaySkynetExport} from '../../redux/actions/skynet_actions'; import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'; import { faCheckSquare, faChevronDown, faChevronRight, faFile, faFolder, faFolderOpen, faHSquare, faMinusSquare, faPlusSquare, faSquare } from '@fortawesome/free-solid-svg-icons'; import Button from '../../components/UI/Button/Button'; const Constants = require('../../constants'); const mapStateToProps = state => { return { AppBusy: state.common.AppBusy, }; }; const mapDispatchToProps = dispatch => { return { displaySkynetExport: display => dispatch(displaySkynetExport(display)), notifyApplicationBusy: busy => dispatch(notifyApplicationBusy(busy, true)), notifyError: msg => dispatch(notifyError(msg)), notifyInfo: (title, msg) => dispatch(notifyInfo(title, msg)), } }; export default connect(mapStateToProps, mapDispatchToProps)(class extends IPCContainer { state = { checked: [], clicked: {}, expanded: [], nodes: [], second_stage: false, } componentDidMount() { this.setRequestHandler(Constants.IPC_Grab_Skynet_Tree_Reply, this.onGrabSkynetTreeReply); this.setRequestHandler(Constants.IPC_Export_Skylinks_Reply, this.onExportSkylinksReply); this.sendRequest(Constants.IPC_Grab_Skynet_Tree, {Version: this.props.version}); } componentWillUnmount() { super.componentWillUnmount(); } createNodes = items => { /* { name: '', path: '', directory: true/false, children: [], } */ const ret = []; for (const item of items) { const treeItem = { label: item.name, path: item.path, value: item.name === '/' ? 0 : item.path ? item.path : JSON.stringify(item), }; if (item.directory) { treeItem.children = this.createNodes(item.children); } ret.push(treeItem); } return ret; } handleNavigation = () => { if (this.state.second_stage) { this.props.notifyApplicationBusy(true); this.sendRequest(Constants.IPC_Export_Skylinks, { Version: this.props.version, Paths: this.state.checked, }); } else { if (this.state.checked.length === 0) { this.props.notifyError('No files have been checked'); } else { this.setState({ second_stage: true, }); } } } onExportSkylinksReply = (_, arg) => { this.props.notifyApplicationBusy(false); if (arg.data.Success) { this.setState({ checked: [], clicked: {}, expanded: [], nodes: [], second_stage: false, }, () => { this.props.notifyInfo('Skylink Exports', '!alternate!!copyable!' + JSON.stringify(arg.data.Result.success, null, 2)); this.sendRequest(Constants.IPC_Grab_Skynet_Tree, {Version: this.props.version}); }); } else { this.props.notifyError(arg.data.Error); } } onGrabSkynetTreeReply = (_, arg) => { if (arg.data.Success) { this.setState({ checked: [], expanded: [0], nodes: this.createNodes(arg.data.Result), }); } else { this.setState({ checked: [], expanded: [], nodes: [], }, () => { this.props.notifyError(arg.data.Error); }); } } render() { return this.props.AppBusy ? (
) : (
this.props.displaySkynetExport(false)} style={{cursor: 'pointer'}}>X

{this.state.second_stage ? 'Verify Exports' : 'Export Files'}

{ this.state.second_stage ? this.state.checked.map(path => { return ( ); }) : ( , uncheck: , halfCheck: , expandClose: , expandOpen: , expandAll: , collapseAll: , parentClose: , parentOpen: , leaf: }} nodes={this.state.nodes} onClick={clicked => this.setState({clicked})} onCheck={checked => this.setState({checked})} onExpand={expanded => this.setState({expanded})}/> ) }
{ this.state.second_stage ? : null }
); } });