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(['date', 'size'])
class FileList extends Component {
constructor(props){
super()
}
render(){
const { files, linkFiles, title, onClick } = this.props
if (!files.length) return null
let fields = this.props.fields || defaultFields
const fileList = files.map(file => {
const size = util.hush_size(file.size)
const date = file.created_at
const username = file.username || ""
return (
{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 (
{title &&
{title}
}
{fileList}
)
}
}
const mapStateToProps = state => ({
})
const mapDispatchToProps = (dispatch, ownProps) => ({
// actions: bindActionCreators(liveActions, dispatch)
})
export default connect(mapStateToProps, mapDispatchToProps)(FileList)