diff --git a/App.jsx b/App.jsx index 60c70b2..f5643a2 100644 --- a/App.jsx +++ b/App.jsx @@ -15,7 +15,31 @@ function makeRequest(queryString, jsonHandler) { }); } +function renderConlangName(name) { + if (name == "saimiar") { + return "Saimiar"; + } + if (name == "elesu") { + return "Elésu"; + } + + if (name === "juteyuji") { + return "Juteyuji"; + } + if (name === "tukvaysi") { + return "Tukvaysi"; + } +} + function Entry(props) { + const conlang = props.conlang; + if (conlang === "saimiar") { + return ; + } + return
Unknown entry type for { conlang }
; +} + +function SaiEntry(props) { const entry = props.entry; return (
@@ -36,14 +60,16 @@ class Results extends Component { } content() { + const conlang = this.props.conlang; const num = this.props.searchResults.length; - const searchType = (this.props.direction === "toConlang") ? `English -> ${this.props.conlang}` : `${this.props.conlang} -> English`; + const renderedName = renderConlangName(conlang); + const searchType = (this.props.direction === "toConlang") ? `English -> ${renderedName}` : `${renderedName} -> English`; const header = (
Searched for { this.props.searchTerm }, { searchType }, found { num } result(s)
); const entries = this.props.searchResults.map( - (entry, idx) => + (entry, idx) => ); return [header].concat(entries); } @@ -62,12 +88,14 @@ class App extends Component { constructor(props) { super(props); this.input = React.createRef(); + this.handleLangChange = this.handleLangChange.bind(this); + this.searchEng = this.searchEng.bind(this); this.searchSaimiar = this.searchSaimiar.bind(this); this.state = { searchResults: null, - conlang: null, + conlang: "saimiar", direction: null, searchTerm: null }; @@ -77,10 +105,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, conlang: null, direction: null }); + this.setState({ searchResults: null, searchTerm: null, direction: null }); } else { makeRequest(request, (json) => { - this.setState({ searchResults: json, conlang: "Saimiar", searchTerm, direction: "toEnglish" }); + this.setState({ searchResults: json, searchTerm, direction: "toEnglish" }); }); } } @@ -89,15 +117,21 @@ class App extends Component { const searchTerm = this.input.current.value; const request = `saimiar?eng=like.*${searchTerm}*` if (searchTerm === "") { - this.setState({ searchResults: null, searchTerm: null, conlang: null }); + this.setState({ searchResults: null, searchTerm: null, }); } else { makeRequest(request, (json) => { - this.setState({ searchResults: json, conlang: "Saimiar", searchTerm, direction: "toConlang" }); + this.setState({ searchResults: json, searchTerm, direction: "toConlang" }); }); } } + handleLangChange(evt) { + const conlang = evt.target.value; + this.setState({ conlang }); + } + render() { + return(
@@ -107,6 +141,12 @@ class App extends Component {

+