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 Results({ actions, loading, success, error, match, results, added }) { if (!success && !error) { return (
) } if (loading) { return (
Loading...
) } if (error) { console.log(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, types.SIMILAR_THRESHOLD) actions.updateQuery({ image: url, blob: null, searchType: 'url', thresholdChanged: false, saveIfNotFound: false, threshold: types.SIMILAR_THRESHOLD, }) }} />

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