From 4f34b95ea36bce31efc4b2c571129387e258271e Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sat, 22 Sep 2018 20:02:16 +0200 Subject: thumbnail embed --- app/client/common/fileViewer.component.js | 32 ++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'app') diff --git a/app/client/common/fileViewer.component.js b/app/client/common/fileViewer.component.js index fcc4e9c..d9f3f4b 100644 --- a/app/client/common/fileViewer.component.js +++ b/app/client/common/fileViewer.component.js @@ -29,7 +29,7 @@ class FileViewer extends Component { } fetch() { - const { file, path } = this.props + const { file, path, thumbnail } = this.props if (!file) return if (this.state.loading) { this.setState({ stale: true }) @@ -39,16 +39,26 @@ class FileViewer extends Component { 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('fetched buffer') - const { stale } = this.state - this.setState({ buffer, loading: false, stale: false, }, () => { - if (stale) { - console.log('stale, fetching...') - this.fetch() - } - }) + + if (thumbnail) { + const size = parseInt(thumbnail) || 200 + actions.socket + .thumbnail({ module, fn, size }) + .then(this.loadBuffer.bind(this)) + } else { + actions.socket + .read_file({ module, fn }) + .then(this.loadBuffer.bind(this)) + } + } + loadBuffer(buffer) { + console.log('fetched buffer') + const { stale } = this.state + this.setState({ buffer, loading: false, stale: false, }, () => { + if (stale) { + console.log('stale, fetching...') + this.fetch() + } }) } -- cgit v1.2.3-70-g09d2