import React, { Component } from 'react' import { bindActionCreators } from 'redux' import { connect } from 'react-redux' import * as actions from '../actions' import * as types from '../types' function scoreClass(score) { if (score < 1) return 'exact' if (score <= 6) return 'good' if (score < 12) return 'ok' return 'bad' } function Results({ actions, query, similar }) { const { loading, success, error, match, results, added } = similar if (!success && !error) { return (
) } if (loading) { return (
Loading...
) } if (error) { return (
Error: {typeof error == 'string' ? error.replace(/_/g, ' ') : 'Server error'}
) } if (!match) { return (
{added ? "New image! Added URL to database" : "No match found" }
) } return (
{results.map(({ phash, score, sha256, url }) => (
{ let searchURL = url if (searchURL.indexOf('http') !== 0) { searchURL = window.location.origin + searchURL } actions.similar(searchURL, query.threshold) actions.updateQuery({ image: url, blob: null, searchType: 'url', thresholdChanged: false, saveIfNotFound: false, }) }} />

{score === 0 ? Exact match : Score: {score} }
{sha256} Phash: {phash.toString(16)}
))}
) } const mapStateToProps = state => state.api const mapDispatchToProps = dispatch => ({ actions: bindActionCreators({ ...actions }, dispatch), }) export default connect(mapStateToProps, mapDispatchToProps)(Results)