diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2017-07-04 02:11:44 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2017-07-04 02:11:44 +0200 |
| commit | 2263f412817d6d2d36372e7617feb0d97fa57af8 (patch) | |
| tree | c5bc7fd177636a295a508c12e1cc2d703c252056 /client/components/Folder/Folder.jsx | |
| parent | 0075896decfe2ebf81c2610f4367929c0d51b1d8 (diff) | |
break out browser and tasks
Diffstat (limited to 'client/components/Folder/Folder.jsx')
| -rw-r--r-- | client/components/Folder/Folder.jsx | 80 |
1 files changed, 0 insertions, 80 deletions
diff --git a/client/components/Folder/Folder.jsx b/client/components/Folder/Folder.jsx deleted file mode 100644 index 4a2e4d2..0000000 --- a/client/components/Folder/Folder.jsx +++ /dev/null @@ -1,80 +0,0 @@ -import { h, Component } from 'preact' -import { Link } from 'react-router-dom' - -import Modal from '../Modal.jsx' - -import client from '../../client.js' - -import FileUploadButton from './FileUploadButton.jsx' - -export default class Folder extends Component { - constructor(props) { - super() - this.state = { - files: props.folder.files || [], - } - this.addFiles = this.addFiles.bind(this) - if (! props.folder.files) { - client.file.index({ folder_id: props.folder.id }).then( files => this.setState({ files }) ) - } - this.audio = document.createElement('audio') - } - addFiles(newFiles) { - console.log(newFiles) - if (! newFiles) return - const files = this.state.files.concat(newFiles).sort( (a,b) => { return b.id - a.id } ) - this.setState({ files }) - } - handleClick(file) { - console.log(file) - if (file.type === 'audio') { - this.audio.setAttribute('src', mp3path(file)) - this.audio.play() - console.log(pngpath(file)) - document.body.style.backgroundImage = 'url(' + pngpath(file) + ')' - } - } - render() { - console.log(this.props) - const files = (this.state.files).map(toFilenamePair).sort(sortByFilename).map(fromPair).map( (file, i) => { - if (! file) return - return ( - <div key={i}> - <span class='name' onClick={() => this.handleClick(file)}>{file.name}</span> - <span class='mime'>{file.mime}</span> - </div> - ) - }) - return ( - <div class='folders'> - <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' -}
\ No newline at end of file |
