From 4765d46df24561f306ce63693db01565aa4980b8 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sat, 2 Jun 2018 14:43:46 +0200 Subject: refactor file list --- app/client/common/fileList.component.js | 143 +++++++++++++++----------------- 1 file changed, 66 insertions(+), 77 deletions(-) (limited to 'app/client/common') diff --git a/app/client/common/fileList.component.js b/app/client/common/fileList.component.js index 87384b6..b4b5430 100644 --- a/app/client/common/fileList.component.js +++ b/app/client/common/fileList.component.js @@ -6,83 +6,72 @@ import moment from 'moment' import * as util from '../util' const defaultFields = new Set(['date', 'size']) -class FileList extends Component { - constructor(props){ - super() - } - render(){ - const { files, linkFiles, title, onClick, className="" } = this.props - if (!files || !files.length) return null - let fields = this.props.fields || defaultFields - if (typeof fields === 'string') { - fields = new Set(fields.split(' ')) - } else if (!(fields instanceof Set)) { - fields = new Set(fields) - } - const fileList = files.map(file => { - const size = util.hush_size(file.size) - const date = file.created_at - const username = file.username || "" - return ( -
-
- {(linkFiles && file.url) - ? {file.name || file.url} - : onClick(file)}>{file.name || file.url} - } -
- {fields.has('age') && -
{util.get_age(date)}
- } - {fields.has('username') && -
{username}
- } - {fields.has('date') && -
{moment(date).format("YYYY-MM-DD")}
- } - {fields.has('datetime') && -
{moment(date).format("YYYY-MM-DD h:mm a")}
- } - {fields.has('size') && -
{size[1]}
- } - {fields.has('epoch') && -
{file.epoch > 0 ? 'epoch ' + file.epoch : ' '}
- } - {(fields.has('activity') || fields.has('module')) && -
- {fields.has('activity') && file.activity} - {fields.has('module') && file.module} -
- } - {this.props.options && this.props.options(file)} -
- ) - }) - return ( -
-
- {files.length ? -

{title || Files}

: -

No files

} -
{(loading || error) && status}
-
- -
- {fileList} -
-
- ) - } -} - +export const FileList = (props) => { + const { files, fields, linkFiles, title, onClick, className="" } = props + const fileList = (files || []).map(file => + + ) + return ( +
+
+ {files.length + ? (title &&

{title}

) + :

No files

} +
{(loading || error) && status}
+
-const mapStateToProps = state => ({ -}) - -const mapDispatchToProps = (dispatch, ownProps) => ({ - // actions: bindActionCreators(liveActions, dispatch) -}) +
+ {fileList} +
+
+ ) +} -export default connect(mapStateToProps, mapDispatchToProps)(FileList) +export const FileRow = (props) => { + const { file, linkFiles, onClick } = props + const fields = props.fields || defaultFields + const size = util.hush_size(file.size) + const date = file.created_at + const username = file.username || "" + return ( +
+
+ {(linkFiles && file.url) + ? {file.name || file.url} + : onClick(file)}>{file.name || file.url} + } +
+ {fields.has('age') && +
{util.get_age(date)}
+ } + {fields.has('username') && +
{username}
+ } + {fields.has('date') && +
{moment(date).format("YYYY-MM-DD")}
+ } + {fields.has('datetime') && +
{moment(date).format("YYYY-MM-DD h:mm a")}
+ } + {fields.has('size') && +
{size[1]}
+ } + {fields.has('epoch') && +
{file.epoch > 0 ? 'epoch ' + file.epoch : ' '}
+ } + {(fields.has('activity') || fields.has('module')) && +
+ {fields.has('activity') && file.activity} + {fields.has('module') && file.module} +
+ } + {this.props.options && this.props.options(file)} +
+ ) +} -- cgit v1.2.3-70-g09d2