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) {
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 = (
<div className="searchResultHeader">
Searched for <b>{ this.props.searchTerm }</b> search type: { this.props.searchType }, found { num } result(s)
<div className="searchResultHeader" key="header">
Searched for <b>{ this.props.searchTerm }</b>, { searchType }, found { num } result(s)
</div>);
const entries = this.props.searchResults.map(
(entry, idx) => <Entry entry={ entry } key= { entry.id } />
@ -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 {
<Results
searchResults={ this.state.searchResults }
searchTerm= { this.state.searchTerm }
searchType={ this.state.searchType }
conlang={ this.state.conlang }
direction={ this.state.direction }
/>
</div>
</main>