import React, { Component } from 'react' import { bindActionCreators } from 'redux' import { connect } from 'react-redux' import * as actions from '../actions' import UploadImage from './uploadImage.component' const MATCH_THRESHOLD = 6 const SIMILAR_THRESHOLD = 20 class Query extends Component { state = { image: null, blob: null, url: "", threshold: SIMILAR_THRESHOLD, searchType: 'file', thresholdChanged: false, saveIfNotFound: false, } handleUpload(blob) { const { image, threshold } = this.state if (image) { URL.revokeObjectURL(image) } const url = URL.createObjectURL(blob) this.setState({ image: url, blob, thresholdChanged: false, }) this.props.actions.upload(blob, threshold) } handleURL() { const { url, threshold, saveIfNotFound } = this.state if (!url || url.indexOf('http') !== 0) return let newThreshold = threshold if (saveIfNotFound) { newThreshold = SIMILAR_THRESHOLD this.props.actions.match(url, threshold) } else { this.props.actions.submit(url, threshold) } this.setState({ image: url, blob: null, thresholdChanged: false, saveIfNotFound: false, threshold: newThreshold, }) } resubmit() { const { image, blob } = this.state if (blob) { this.handleUpload(blob) } else { this.handleURL() } } render() { const { url, image, threshold, thresholdChanged, searchType } = this.state const style = {} if (image) { style.backgroundImage = 'url(' + image + ')' } return (