From aa5638a1c31ce56d59696580f33733dcf0d7764c Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sun, 28 Apr 2019 15:54:41 +0200 Subject: refactor frontend, add threshold slider --- client/components/query.component.js | 103 +++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 client/components/query.component.js (limited to 'client/components/query.component.js') diff --git a/client/components/query.component.js b/client/components/query.component.js new file mode 100644 index 0000000..bd98ce8 --- /dev/null +++ b/client/components/query.component.js @@ -0,0 +1,103 @@ +import React, { Component } from 'react' +import { bindActionCreators } from 'redux' +import { connect } from 'react-redux' + +import * as actions from '../actions' + +import UploadImage from './uploadImage.component' +class Query extends Component { + state = { + image: null, + blob: null, + url: "", + threshold: 20, + } + + handleUpload(blob) { + const { image, threshold } = this.state + if (image) { + URL.revokeObjectURL(image) + } + const url = URL.createObjectURL(blob) + this.setState({ image: url, blob }) + this.props.actions.upload(blob, threshold) + } + + handleURL() { + const { url, threshold } = this.state + if (!url || url.indexOf('http') !== 0) return + this.setState({ image: url, blob: null }) + this.props.actions.submit(url, threshold) + } + + resubmit() { + const { image, blob } = this.state + if (blob) { + this.handleUpload(blob) + } else { + this.handleURL() + } + } + + render() { + const { url, image, threshold } = this.state + const style = {} + if (image) { + style.maxWidth = 200 + style.maxHeight = 200 + style.backgroundImage = 'url(' + image + ')' + style.backgroundSize = 'cover' + style.opacity = 1 + } + return ( +
+ + {/* + + */} + + {image &&
} +
+ ) + } +} + +const mapStateToProps = state => ({ + ...state.api, +}) +const mapDispatchToProps = dispatch => ({ + actions: bindActionCreators({ ...actions }, dispatch), +}) + +export default connect(mapStateToProps, mapDispatchToProps)(Query) -- cgit v1.2.3-70-g09d2