summaryrefslogtreecommitdiff
path: root/client/components/Folder/Folder.jsx
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2017-07-02 22:49:26 +0200
committerJules Laplace <julescarbon@gmail.com>2017-07-02 22:49:26 +0200
commitdb3a5fcd8edaa45ef05a6250e7f9452f0ed87250 (patch)
tree871703028cef31309102d452197d737bc5cc76e8 /client/components/Folder/Folder.jsx
parentef0d6a05a1717b9cb9b52fca9285c9ba8c191b0c (diff)
resample to 16bit 44100hz aiff
Diffstat (limited to 'client/components/Folder/Folder.jsx')
-rw-r--r--client/components/Folder/Folder.jsx31
1 files changed, 29 insertions, 2 deletions
diff --git a/client/components/Folder/Folder.jsx b/client/components/Folder/Folder.jsx
index 88c937a..4a2e4d2 100644
--- a/client/components/Folder/Folder.jsx
+++ b/client/components/Folder/Folder.jsx
@@ -17,6 +17,7 @@ export default class Folder extends Component {
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)
@@ -24,13 +25,22 @@ export default class Folder extends Component {
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( (file, i) => {
+ const files = (this.state.files).map(toFilenamePair).sort(sortByFilename).map(fromPair).map( (file, i) => {
if (! file) return
return (
<div key={i}>
- <span class='name'>{file.name}</span>
+ <span class='name' onClick={() => this.handleClick(file)}>{file.name}</span>
<span class='mime'>{file.mime}</span>
</div>
)
@@ -51,3 +61,20 @@ export default class Folder extends Component {
)
}
}
+
+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