From 28d6dd9a097be3f76ede22f63c6c68a78607aec8 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sat, 22 Sep 2018 14:43:35 +0200 Subject: move fetch functionality into fileviweer --- app/client/common/fileViewer.component.js | 93 +++++++++++++++++++++++-------- 1 file changed, 69 insertions(+), 24 deletions(-) (limited to 'app/client/common/fileViewer.component.js') diff --git a/app/client/common/fileViewer.component.js b/app/client/common/fileViewer.component.js index bc71f20..72aebd4 100644 --- a/app/client/common/fileViewer.component.js +++ b/app/client/common/fileViewer.component.js @@ -1,4 +1,7 @@ import { h, Component } from 'preact' +import { connect } from 'react-redux' + +import actions from '../actions' const image_types = { 'jpg': 'image/jpeg', @@ -18,33 +21,69 @@ const video_types = { 'mp4': 'video/mp4', } -export default function FileViewer({ file }) { - const { - error, - name, path, - date, size, - buf, - } = file - if (error) { - return
{error}
+class FileViewer extends Component { + state = { + loading: true, + buffer: {} } - if (!buf) { - return
File empty
+ + fetch() { + const { file } = this.props + const fn = [file.path, file.name].join('/').replace('//','/') + console.log('fetch file', fn) + const { tool: module } = this.props.app + this.setState({ buffer: null, loading: true }) + actions.socket.read_file({ module, fn }).then(buffer => { + console.log(buffer) + this.setState({ buffer, loading: false }) + }) } - const ext = name.split('.').slice(-1)[0].toLowerCase() - let tag; - if (ext in image_types) { - tag = - } else if (ext in audio_types) { - tag =