import { h, Component } from 'preact' import { bindActionCreators } from 'redux' import { connect } from 'react-redux' import { Link } from 'react-router-dom'; import moment from 'moment' import * as util from '../util' const defaultFields = new Set(['name', 'date', 'size']) export const FileList = props => { const { files, fields, sort, title, linkFiles, onClick, orderBy='name asc', className='', fileListClassName='filelist', rowClassName='row file' } = props const { mapFn, sortFn } = util.sort.orderByFn(orderBy) const fileList = (files || []) .filter(f => !!f) .map(mapFn) .sort(sortFn) .map(pair => { return }) if (!fileList || !fileList.length) { return (

No files

) } return (
{title &&

{title}

}
}
{fileList}
) } export const fieldSet = fields => { if (fields) { if (fields instanceof Set) { return fields } return new Set(fields.split(' ')) } return defaultFields } export const FileRow = props => { const { file, linkFiles, onClick, className='row file', username='' } = props const fields = fieldSet(props.fields) const size = util.hush_size(file.size) const date = file.date || file.created_at const epoch = file.epoch || file.epochs || 0 return (
{fields.has('name') &&
{file.persisted === false ? {file.name || file.url} : (linkFiles && file.url) ? onClick && onClick(file, e)} href={file.url}>{file.name || file.url} : onClick && onClick(file, e)}>{file.name || file.url} }
} {fields.has('age') &&
{util.get_age(date)}
} {fields.has('username') &&
{username}
} {fields.has('epoch') &&
{epoch > 0 ? 'ep. ' + epoch : ''}
} {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('activity') || fields.has('module')) &&
{fields.has('activity') && file.activity} {fields.has('module') && file.module}
} {props.options && props.options(file)}
) }