import React from 'react'; import FolderOpenSolid from '../icons/FolderOpenSolid'; import DirectoryTree from '../filesystem/DirectoryTree'; import File from '../icons/File'; const METHODS_TO_BIND = ['handleParentDirectoryClick']; export default class TorrentFiles extends React.Component { constructor() { super(); this.state = { expanded: true }; METHODS_TO_BIND.forEach((method) => { this[method] = this[method].bind(this); }); } constructDirectoryTree(tree = {}, directory, file, depth = 0) { if (depth < file.pathComponents.length - 1) { depth++; tree[directory] = this.constructDirectoryTree( tree[directory], file.pathComponents[depth], file, depth ); } else { if (!tree.files) { tree.files = []; } tree.files.push(file); } return tree; } getFileList(files) { let tree = {}; files.forEach((file) => { this.constructDirectoryTree(tree, file.pathComponents[0], file); }); return ; } getFileData(torrent, files) { } handleParentDirectoryClick() { this.setState({ expanded: !this.state.expanded }); } isLoaded() { if (this.props.files) { return true; } return false; } render() { let {files, torrent} = this.props; if (this.isLoaded()) { // We've received full file details from the client. let fileList = null; if (this.state.expanded) { fileList = this.getFileList(files); } return (
{torrent.directory}
{fileList}
); } else { // We've only received the top-level file details from the torrent list. return (
{torrent.directory}
{torrent.filename}
); } } }