summaryrefslogtreecommitdiff
path: root/client/components/Browser/Files/Files.jsx
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2017-07-07 21:18:33 +0200
committerJules Laplace <julescarbon@gmail.com>2017-07-07 21:18:33 +0200
commitf8b61281be84a6e4e7a44be5109e688a7c56c671 (patch)
tree43797c6b6cfa5c0f89c020f8c89e0da10f791a55 /client/components/Browser/Files/Files.jsx
parent3d3a7b80d34c100846c8ae130b424b63ba3c0784 (diff)
refactor files so list updates while processing
Diffstat (limited to 'client/components/Browser/Files/Files.jsx')
-rw-r--r--client/components/Browser/Files/Files.jsx82
1 files changed, 82 insertions, 0 deletions
diff --git a/client/components/Browser/Files/Files.jsx b/client/components/Browser/Files/Files.jsx
new file mode 100644
index 0000000..74c266f
--- /dev/null
+++ b/client/components/Browser/Files/Files.jsx
@@ -0,0 +1,82 @@
+import { h, Component } from 'preact'
+
+import { audioPlayFile } fromĀ '../../../actions'
+
+import client from '../../../client.js'
+
+import FileUploadButton from './FileUploadButton.jsx'
+import FileLink from '../../../containers/fileLink.js'
+import TaskContentLink from '../../../containers/taskContentLink.js'
+import TaskStyleLink from '../../../containers/taskStyleLink.js'
+
+export default class Files extends Component {
+ constructor(props) {
+ super()
+ this.state = {
+ selected: null,
+ }
+ this.addFiles = this.addFiles.bind(this)
+ }
+ addFiles(newFiles) {
+ if (! newFiles) return
+ const files = this.state.files.concat(newFiles).sort( (a,b) => { return b.id - a.id } )
+ this.setState({ files })
+ }
+ handleClick(file) {
+ this.setState({ selected: file })
+ }
+ render() {
+ let file_list;
+ if (this.props.folder && this.props.folder.files) {
+ file_list = this.props.folder.files
+ }
+ else {
+ file_list = []
+ }
+ const files = file_list.map(toFilenamePair).sort(sortByFilename).map(fromPair).map( (file, i) => {
+ if (! file) return
+ return (
+ <div key={i} class={this.state.selected === file ? 'selected' : ''}>
+ <span class='name'><FileLink file={file}>{file.name}</FileLink></span>
+ <span class='mime'>{file.processed ? file.mime : 'working...'}</span>
+ <span class='duration'>{file.duration ? (file.duration.toFixed(1) + 's') : ''}</span>
+ <span class='actions'>
+ <TaskContentLink file={file}>content</TaskContentLink>
+ <TaskStyleLink file={file}>style</TaskStyleLink>
+ </span>
+ </div>
+ )
+ })
+ return (
+ <div class='window'>
+ <div class='heading'>
+ <b>{this.props.folder.name}</b>
+ <div class='buttons'>
+ <FileUploadButton folder={this.props.folder} addFiles={this.addFiles} />
+ <button onClick={this.props.onClose}>&times;</button>
+ </div>
+ </div>
+ <div class='list'>
+ {files}
+ </div>
+ </div>
+ )
+ }
+}
+
+function toFilenamePair (file) { return [file.name.toLowerCase(), file] }
+function sortByFilename (a,b) { return a[0] < b[0] ? -1 : a[0] == b[0] ? 0 : 1 }
+function fromPair (pair) { return pair[1] }
+
+function filepath (file) {
+ return '/data/' + file.folder_id + '/' + encodeURIComponent(file.name)
+}
+function mp3path (file) {
+ if (file.mime !== 'audio/mp3') {
+ return filepath(file) + '.mp3'
+ }
+ return filepath(file)
+}
+function pngpath (file) {
+ return filepath(file) + '.png'
+} \ No newline at end of file