From 981fc00ccf629071527564d2b5c69333fa25c119 Mon Sep 17 00:00:00 2001 From: Matt Goldspink Date: Fri, 17 Jun 2022 06:30:59 -0700 Subject: Reverting back to a functional component and using useState instead. --- src/web/src/components/Shared/FileList.js | 144 ++++++++++++++---------------- 1 file changed, 68 insertions(+), 76 deletions(-) (limited to 'src') diff --git a/src/web/src/components/Shared/FileList.js b/src/web/src/components/Shared/FileList.js index b1db5ea7..64ef4f6a 100644 --- a/src/web/src/components/Shared/FileList.js +++ b/src/web/src/components/Shared/FileList.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, {useState} from 'react'; import { formatSeconds, formatBytes, getFileName, formatAttributes } from '../../lib/util'; @@ -10,85 +10,77 @@ import { Checkbox, } from 'semantic-ui-react'; -class FileList extends React.Component { - state = { - isFolded: false, - }; - toggleFolded = () => { - if (!this.props.locked) { - this.setState({'isFolded': !this.state.isFolded}); - } - }; +const FileList = ({ directoryName, files, locked, onSelectionChange, disabled, onClose }) => { + const [folded, setFolded] = useState(false); - render() { - return ( -
-
-
- this.toggleFolded()}/> - {this.props.directoryName} - - {!!this.props.onClose && this.props.onClose()} - />} -
-
- {!this.state.isFolded && this.props.files && this.props.files.length > 0 && - - - - - + return ( +
+
+
+ setFolded(!folded)}/> + {directoryName} + + {!!onClose && onClose()} + />} +
+
+ {!folded && files && files.length > 0 && + +
+ + + + files.map(f => onSelectionChange(f, data.checked))} + checked={files.filter(f => !f.selected).length === 0} + disabled={disabled} + /> + + File + Size + Attributes + Length + + + + {files.sort((a, b) => a.filename > b.filename ? 1 : -1).map((f, i) => + + this.props.files.map(f => - this.props.onSelectionChange(f, data.checked))} - checked={this.props.files.filter(f => !f.selected).length === 0} - disabled={this.props.disabled} + fitted + onChange={(event, data) => onSelectionChange(f, data.checked)} + checked={f.selected} + disabled={disabled} /> - - File - Size - Attributes - Length + + + {locked ? : ''}{getFileName(f.filename)} + + {formatBytes(f.size)} + {formatAttributes(f)} + {formatSeconds(f.length)} - - - {this.props.files.sort((a, b) => a.filename > b.filename ? 1 : -1).map((f, i) => - - - this.props.onSelectionChange(f, data.checked)} - checked={f.selected} - disabled={this.props.disabled} - /> - - - {this.props.locked ? : ''}{getFileName(f.filename)} - - {formatBytes(f.size)} - {formatAttributes(f)} - {formatSeconds(f.length)} - - )} - -
-
-
} -
); - } -} + )} + + + + } + + ); +}; export default FileList; -- cgit v1.2.3