From 102f5545cae7a8df23501ecc9970308d10505b42 Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 28 Jan 2019 22:13:08 -0800 Subject: [PATCH] Show conlang --- App.jsx | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/App.jsx b/App.jsx index 9bb95d3..60c70b2 100644 --- a/App.jsx +++ b/App.jsx @@ -15,11 +15,6 @@ function makeRequest(queryString, jsonHandler) { }); } -function testHandler(json) { - console.log("JSON"); - console.log(json); -} - function Entry(props) { const entry = props.entry; return ( @@ -42,9 +37,10 @@ class Results extends Component { content() { const num = this.props.searchResults.length; + const searchType = (this.props.direction === "toConlang") ? `English -> ${this.props.conlang}` : `${this.props.conlang} -> English`; const header = ( -
- Searched for { this.props.searchTerm } search type: { this.props.searchType }, found { num } result(s) +
+ Searched for { this.props.searchTerm }, { searchType }, found { num } result(s)
); const entries = this.props.searchResults.map( (entry, idx) => @@ -71,7 +67,8 @@ class App extends Component { this.state = { searchResults: null, - searchType: null, + conlang: null, + direction: null, searchTerm: null }; } @@ -80,10 +77,10 @@ class App extends Component { const searchTerm = this.input.current.value; const request = `saimiar?sai=like.*${searchTerm}*` if (searchTerm === "") { - this.setState({ searchResults: null, searchTerm: null, searchType: null }); + this.setState({ searchResults: null, searchTerm: null, conlang: null, direction: null }); } else { makeRequest(request, (json) => { - this.setState({ searchResults: json, searchType: "saimiar", searchTerm }); + this.setState({ searchResults: json, conlang: "Saimiar", searchTerm, direction: "toEnglish" }); }); } } @@ -92,10 +89,10 @@ class App extends Component { const searchTerm = this.input.current.value; const request = `saimiar?eng=like.*${searchTerm}*` if (searchTerm === "") { - this.setState({ searchResults: null, searchTerm: null, searchType: null }); + this.setState({ searchResults: null, searchTerm: null, conlang: null }); } else { makeRequest(request, (json) => { - this.setState({ searchResults: json, searchType: "eng-saimiar", searchTerm }); + this.setState({ searchResults: json, conlang: "Saimiar", searchTerm, direction: "toConlang" }); }); } } @@ -116,7 +113,8 @@ class App extends Component {