import React, { Component } from "react"; import './App.scss'; const backendUrl = "https://kucinakobackend.ichigo.everydayimshuflin.com"; function makeRequest(queryString, jsonHandler) { const effectiveUrl = `${backendUrl}/${queryString}` fetch(`${effectiveUrl}`) .then((resp) => { return resp.json() }) .then((json) => { jsonHandler(json); }); } function testHandler(json) { console.log("JSON"); console.log(json); } class Results extends Component { constructor(props) { super(props); this.content = this.content.bind(this); } content() { const header = (
Searched for { this.props.searchTerm } search type: { this.props.searchType }
); const entries = this.props.searchResults.map((entry, idx) => { return (
{ entry.sai } - { entry.eng }
{ entry.syn_category }
Type: { entry.morph_type }
); }); return [header].concat(entries); } render() { const results = this.props.searchResults; return(
{ results ? this.content() : "No results" }
); } } class App extends Component { constructor(props) { super(props); this.input = React.createRef(); this.searchEng = this.searchEng.bind(this); this.searchSaimiar = this.searchSaimiar.bind(this); this.state = { searchResults: null, searchType: null, searchTerm: null }; } searchSaimiar(evt) { const searchTerm = this.input.current.value; const request = `saimiar?sai=like.*${searchTerm}*` makeRequest(request, (json) => { const searchResults = json.length === 0 ? null : json; this.setState({ searchResults, searchType: "saimiar", searchTerm }); }); } searchEng(evt) { const searchTerm = this.input.current.value; const request = `saimiar?eng=like.*${searchTerm}*` makeRequest(request, (json) => { const searchResults = json.length === 0 ? null : json; this.setState({ searchResults, searchType: "eng-saimiar", searchTerm }); }); } render() { return(

Kucinako


); } } export default App;