summaryrefslogtreecommitdiff
path: root/app/client/common/fileList.component.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/client/common/fileList.component.js')
-rw-r--r--app/client/common/fileList.component.js143
1 files changed, 66 insertions, 77 deletions
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 (
- <div class='row file' key={file.name}>
- <div className="filename" title={file.name || file.url}>
- {(linkFiles && file.url)
- ? <a target='_blank' href={file.url}>{file.name || file.url}</a>
- : <span class='link' onClick={() => onClick(file)}>{file.name || file.url}</span>
- }
- </div>
- {fields.has('age') &&
- <div className={"age " + util.carbon_date(date)}>{util.get_age(date)}</div>
- }
- {fields.has('username') &&
- <div className={"username"}>{username}</div>
- }
- {fields.has('date') &&
- <div className={"date " + util.carbon_date(date)}>{moment(date).format("YYYY-MM-DD")}</div>
- }
- {fields.has('datetime') &&
- <div className={"datetime " + util.carbon_date(date)}>{moment(date).format("YYYY-MM-DD h:mm a")}</div>
- }
- {fields.has('size') &&
- <div className={"size " + size[0]}>{size[1]}</div>
- }
- {fields.has('epoch') &&
- <div className="epoch">{file.epoch > 0 ? 'epoch ' + file.epoch : ' '}</div>
- }
- {(fields.has('activity') || fields.has('module')) &&
- <div className='activity'>
- {fields.has('activity') && file.activity}
- {fields.has('module') && file.module}
- </div>
- }
- {this.props.options && this.props.options(file)}
- </div>
- )
- })
- return (
- <div className={'rows ' + className}>
- <div class='row heading'>
- {files.length ?
- <h3>{title || Files}</h3> :
- <h4>No files</h4>}
- <div>{(loading || error) && status}</div>
- </div>
-
- <div className={'filelist rows'}>
- {fileList}
- </div>
- </div>
- )
- }
-}
-
+export const FileList = (props) => {
+ const { files, fields, linkFiles, title, onClick, className="" } = props
+ const fileList = (files || []).map(file =>
+ <FileRow
+ file={file}
+ fields={fields || defaultFields}
+ linkFiles
+ onClick
+ />
+ )
+ return (
+ <div className={'rows ' + className}>
+ <div class='row heading'>
+ {files.length
+ ? (title && <h3>{title}</h3>)
+ : <h4>No files</h4>}
+ <div>{(loading || error) && status}</div>
+ </div>
-const mapStateToProps = state => ({
-})
-
-const mapDispatchToProps = (dispatch, ownProps) => ({
- // actions: bindActionCreators(liveActions, dispatch)
-})
+ <div className={'filelist rows'}>
+ {fileList}
+ </div>
+ </div>
+ )
+}
-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 (
+ <div class='row file' key={file.name}>
+ <div className="filename" title={file.name || file.url}>
+ {(linkFiles && file.url)
+ ? <a target='_blank' href={file.url}>{file.name || file.url}</a>
+ : <span class='link' onClick={() => onClick(file)}>{file.name || file.url}</span>
+ }
+ </div>
+ {fields.has('age') &&
+ <div className={"age " + util.carbon_date(date)}>{util.get_age(date)}</div>
+ }
+ {fields.has('username') &&
+ <div className={"username"}>{username}</div>
+ }
+ {fields.has('date') &&
+ <div className={"date " + util.carbon_date(date)}>{moment(date).format("YYYY-MM-DD")}</div>
+ }
+ {fields.has('datetime') &&
+ <div className={"datetime " + util.carbon_date(date)}>{moment(date).format("YYYY-MM-DD h:mm a")}</div>
+ }
+ {fields.has('size') &&
+ <div className={"size " + size[0]}>{size[1]}</div>
+ }
+ {fields.has('epoch') &&
+ <div className="epoch">{file.epoch > 0 ? 'epoch ' + file.epoch : ' '}</div>
+ }
+ {(fields.has('activity') || fields.has('module')) &&
+ <div className='activity'>
+ {fields.has('activity') && file.activity}
+ {fields.has('module') && file.module}
+ </div>
+ }
+ {this.props.options && this.props.options(file)}
+ </div>
+ )
+}