Show conlang

This commit is contained in:
greg 2019-01-28 22:13:08 -08:00
parent 2f7202b644
commit 102f5545ca
1 changed files with 11 additions and 13 deletions

24
App.jsx
View File

@ -15,11 +15,6 @@ function makeRequest(queryString, jsonHandler) {
}); });
} }
function testHandler(json) {
console.log("JSON");
console.log(json);
}
function Entry(props) { function Entry(props) {
const entry = props.entry; const entry = props.entry;
return ( return (
@ -42,9 +37,10 @@ class Results extends Component {
content() { content() {
const num = this.props.searchResults.length; const num = this.props.searchResults.length;
const searchType = (this.props.direction === "toConlang") ? `English -> ${this.props.conlang}` : `${this.props.conlang} -> English`;
const header = ( const header = (
<div className="searchResultHeader"> <div className="searchResultHeader" key="header">
Searched for <b>{ this.props.searchTerm }</b> search type: { this.props.searchType }, found { num } result(s) Searched for <b>{ this.props.searchTerm }</b>, { searchType }, found { num } result(s)
</div>); </div>);
const entries = this.props.searchResults.map( const entries = this.props.searchResults.map(
(entry, idx) => <Entry entry={ entry } key= { entry.id } /> (entry, idx) => <Entry entry={ entry } key= { entry.id } />
@ -71,7 +67,8 @@ class App extends Component {
this.state = { this.state = {
searchResults: null, searchResults: null,
searchType: null, conlang: null,
direction: null,
searchTerm: null searchTerm: null
}; };
} }
@ -80,10 +77,10 @@ class App extends Component {
const searchTerm = this.input.current.value; const searchTerm = this.input.current.value;
const request = `saimiar?sai=like.*${searchTerm}*` const request = `saimiar?sai=like.*${searchTerm}*`
if (searchTerm === "") { if (searchTerm === "") {
this.setState({ searchResults: null, searchTerm: null, searchType: null }); this.setState({ searchResults: null, searchTerm: null, conlang: null, direction: null });
} else { } else {
makeRequest(request, (json) => { 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 searchTerm = this.input.current.value;
const request = `saimiar?eng=like.*${searchTerm}*` const request = `saimiar?eng=like.*${searchTerm}*`
if (searchTerm === "") { if (searchTerm === "") {
this.setState({ searchResults: null, searchTerm: null, searchType: null }); this.setState({ searchResults: null, searchTerm: null, conlang: null });
} else { } else {
makeRequest(request, (json) => { 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 {
<Results <Results
searchResults={ this.state.searchResults } searchResults={ this.state.searchResults }
searchTerm= { this.state.searchTerm } searchTerm= { this.state.searchTerm }
searchType={ this.state.searchType } conlang={ this.state.conlang }
direction={ this.state.direction }
/> />
</div> </div>
</main> </main>