From 2f2c1ef4029dee17be0d16acdd60b7d1718d519f Mon Sep 17 00:00:00 2001
From: Jules Laplace <julescarbon@gmail.com>
Date: Wed, 19 Jul 2017 02:06:56 +0200
Subject: refactor file browser stuff

---
 client/components/Browser/Files/FileListView.jsx | 68 ++++++++++++++++++++++++
 1 file changed, 68 insertions(+)
 create mode 100644 client/components/Browser/Files/FileListView.jsx

(limited to 'client/components/Browser/Files/FileListView.jsx')

diff --git a/client/components/Browser/Files/FileListView.jsx b/client/components/Browser/Files/FileListView.jsx
new file mode 100644
index 0000000..1c5f952
--- /dev/null
+++ b/client/components/Browser/Files/FileListView.jsx
@@ -0,0 +1,68 @@
+import { h, Component } from 'preact'
+
+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 function FileListView (props) {
+  console.log(props)
+
+  let file_list;
+  if (props.folder && props.folder.files) {
+    file_list = 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={props.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>{props.folder.name}</b>
+        <div class='buttons'>
+          <FileUploadButton folder={props.folder} addFiles={props.addFiles} />
+          <button onClick={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
-- 
cgit v1.2.3-70-g09d2

