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/auth/auth.gate.js | 20 ++--- app/client/auth/auth.reducer.js | 1 - app/client/common/browser.component.js | 18 ++--- app/client/common/fileViewer.component.js | 93 ++++++++++++++++------ app/client/index.jsx | 7 +- app/client/modules/pix2pixhd/pix2pixhd.actions.js | 6 +- .../modules/pix2pixhd/views/pix2pixhd.train.js | 23 +++++- .../modules/pix2pixhd/views/sequence.editor.js | 29 ++++--- app/client/system/system.reducer.js | 9 ++- 9 files changed, 139 insertions(+), 67 deletions(-) diff --git a/app/client/auth/auth.gate.js b/app/client/auth/auth.gate.js index 076ec54..40f244f 100644 --- a/app/client/auth/auth.gate.js +++ b/app/client/auth/auth.gate.js @@ -46,34 +46,36 @@ class AuthRouter extends Component { class AuthGate extends Component { render(){ - if (true && !this.props.auth.initialized) { + const { auth, env, actions } = this.props + if (env.production && !auth.initialized) { console.log('loading auth') return
Loading
} - if (true || this.props.auth.isAuthenticated) { - console.log('authenticated...') - if (this.props.auth.returnTo) { - let { returnTo } = this.props.auth + if (env.development || auth.isAuthenticated) { + if (auth.returnTo) { + let { returnTo } = auth if (!returnTo || returnTo.match(/(login|logout|signup)/i)) { returnTo = '/' } console.log('history.push', returnTo) - this.props.actions.setReturnTo(null) + actions.setReturnTo(null) history.push(returnTo) return
Launching app
} - console.log('rendering as normal') return
{this.props.children}
} return } componentDidMount(){ - this.props.actions.checkin() + if (this.props.env.production) { + this.props.actions.checkin() + } } } const mapStateToProps = (state) => ({ - auth: state.auth + env: state.system.env, + auth: state.auth, }); const mapDispatchToProps = (dispatch) => ({ diff --git a/app/client/auth/auth.reducer.js b/app/client/auth/auth.reducer.js index a56f94a..80b1ec5 100644 --- a/app/client/auth/auth.reducer.js +++ b/app/client/auth/auth.reducer.js @@ -11,7 +11,6 @@ const authInitialState = { } const auth = (state = authInitialState, action) => { - console.log(action) switch(action.type) { case types.auth.set_token: return { diff --git a/app/client/common/browser.component.js b/app/client/common/browser.component.js index 50b31cf..19cd0f6 100644 --- a/app/client/common/browser.component.js +++ b/app/client/common/browser.component.js @@ -11,19 +11,23 @@ class Browser extends Component { state = { dir: '/', files: [], + file: null, loading: true } + componentDidMount() { this.fetch(this.state.dir) } + handlePick(file) { console.log(file) if (file.dir) { this.fetch([this.state.dir, file.name].join('/').replace('//','/')) } else { - this.fetchFile([this.state.dir, file.name].join('/').replace('//','/')) + this.setState({ file: { ...file, path: this.state.dir } }) } } + fetch(dir) { console.log('fetch', dir) const { tool: module } = this.props.app @@ -33,15 +37,7 @@ class Browser extends Component { this.setState({ dir, files, loading: false }) }) } - fetchFile(fn) { - console.log('fetch file', fn) - const { tool: module } = this.props.app - this.setState({ file: null, loadingFile: true }) - actions.socket.read_file({ module, fn }).then(file => { - console.log(file) - this.setState({ file, loadingFile: false }) - }) - } + render() { const { app } = this.props const { @@ -68,7 +64,7 @@ class Browser extends Component { }} onClickParent={e => { console.log('navigate up') - this.fetch(this.state.dir.split('/').slice(0, -1).join('/') || '/') + this.fetch(dir.split('/').slice(0, -1).join('/') || '/') }} /> {loadingFile && } 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 =