import React, { Component } from 'react' import UploadImage from './lib/uploadImage.component' import { post } from './util' const initialState = { image: null, url: "", res: null, loading: false, } export default class PhashApp extends Component { state = { ...initialState } upload(blob) { if (this.state.image) { URL.revokeObjectURL(this.state.image) } const url = URL.createObjectURL(blob) this.setState({ image: url, loading: true }) const fd = new FormData() fd.append('q', blob) post('/api/v1/match', fd) .then(res => { console.log(res) this.setState({ res, loading: false }) }) .catch(err => { console.log(err) this.setState({ loading: false }) }) } submit() { const { url } = this.state if (!url || url.indexOf('http') !== 0) return this.setState({ image: url, loading: true }) const fd = new FormData() fd.append('url', url) post('/api/v1/match', fd) .then(res => { console.log(res) this.setState({ res, loading: false }) }) .catch(err => { console.log(err) this.setState({ loading: false }) }) } render() { return (