blob: 74c266fdae7842dbe437b281e56ff0bdbecbd467 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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}>×</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'
}
|