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 --- .../modules/pix2pixhd/views/sequence.editor.js | 29 ++++++++++++---------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'app/client/modules/pix2pixhd/views/sequence.editor.js') diff --git a/app/client/modules/pix2pixhd/views/sequence.editor.js b/app/client/modules/pix2pixhd/views/sequence.editor.js index 9693805..a749df9 100644 --- a/app/client/modules/pix2pixhd/views/sequence.editor.js +++ b/app/client/modules/pix2pixhd/views/sequence.editor.js @@ -3,9 +3,9 @@ import { bindActionCreators } from 'redux' import { connect } from 'react-redux' import { Route, Link } from 'react-router-dom' -import { Loading, FileList, FileViewer } from '../../common' +import { Loading, FileList, FileViewer } from '../../../common' -import actions from '../actions' +import actions from '../../../actions' class SequenceEditor extends Component { state = { @@ -14,7 +14,12 @@ class SequenceEditor extends Component { loading: true } componentDidMount() { - this.fetch(this.state.dir) + this.fetch(this.props.dataset) + } + componentDidUpdate(prevProps) { + if (this.props.dataset !== prevProps.dataset) { + this.fetch(this.props.dataset) + } } handlePick(file) { console.log(file) @@ -26,22 +31,13 @@ class SequenceEditor extends Component { } fetch(dir) { console.log('fetch', dir) - const { tool: module } = this.props.app + const { name: module } = this.props.module.name this.setState({ dir, file: null, loading: true }) actions.socket.list_directory({ module, dir }).then(files => { console.log(files) 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 { @@ -49,6 +45,13 @@ class SequenceEditor extends Component { loadingFile, file, } = this.state console.log(this.props, this.state) + return ( +
+
+
+
+
+ ) // return ( //
//

{dir}{dir[dir.length-1] !== '/' && '/'}

-- cgit v1.2.3-70-g09d2 From 960a7495f502d3f6a604a14828dd68bc61bed92e Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sat, 22 Sep 2018 16:32:46 +0200 Subject: preload sequence, dont overload fileviewer --- app/client/common/fileViewer.component.js | 32 +- .../modules/pix2pixhd/views/pix2pixhd.train.js | 5 +- .../modules/pix2pixhd/views/sequence.editor.js | 162 ++++-- package-lock.json | 545 +++++++++++++++++++++ package.json | 1 + 5 files changed, 682 insertions(+), 63 deletions(-) (limited to 'app/client/modules/pix2pixhd/views/sequence.editor.js') diff --git a/app/client/common/fileViewer.component.js b/app/client/common/fileViewer.component.js index 72aebd4..b1cabd4 100644 --- a/app/client/common/fileViewer.component.js +++ b/app/client/common/fileViewer.component.js @@ -23,19 +23,31 @@ const video_types = { class FileViewer extends Component { state = { - loading: true, + loading: false, + stale: false, buffer: {} } fetch() { - const { file } = this.props - const fn = [file.path, file.name].join('/').replace('//','/') + const { file, path } = this.props + if (!file) return + if (this.state.loading) { + this.setState({ stale: true }) + return + } + const fn = [path || 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 }) + console.log('fetched buffer') + const { stale } = this.state + this.setState({ buffer, loading: false, stale: false, }, () => { + if (stale) { + console.log('stale, fetching...') + this.fetch() + } + }) }) } @@ -50,6 +62,10 @@ class FileViewer extends Component { } render() { + const { file } = this.props + if (!file) { + return
+ } const { loading, buffer } = this.state if (loading) { return
Loading...
@@ -69,14 +85,14 @@ class FileViewer extends Component { if (!buf) { return
File empty
} - const ext = name.split('.').slice(-1)[0].toLowerCase() + const ext = extension(name) let tag; if (ext in image_types) { tag = } else if (ext in audio_types) { tag =