General improvements for non-Sai conlangs

This commit is contained in:
Greg Shuflin 2021-09-12 17:22:00 -07:00
parent 010552a4fc
commit eb46a87c8e

View File

@ -5,6 +5,31 @@ import {declineSaimiar} from './saimiar_morphology';
const backendUrl = 'https://kucinakobackend.ichigo.everydayimshuflin.com';
enum Conlang {
Saimiar = 'sai',
Elesu = 'ele',
Tukvaysi = 'tuk',
Juteyuji = 'jut',
}
const renderConlang = (conlang: Conlang): string => {
if (conlang === Conlang.Saimiar) {
return 'Saimiar';
}
if (conlang === Conlang.Elesu) {
return 'Elésu';
}
if (conlang === Conlang.Juteyuji) {
return 'Juteyuji';
}
if (conlang === Conlang.Tukvaysi) {
return 'Tukvaysi';
}
};
function makeRequest(queryString, jsonHandler) {
const effectiveUrl = `${backendUrl}/${queryString}`;
fetch(`${effectiveUrl}`)
@ -14,31 +39,13 @@ function makeRequest(queryString, jsonHandler) {
});
}
function renderConlangName(name: string): string {
if (name === 'saimiar') {
return 'Saimiar';
}
if (name === 'elesu') {
return 'Elésu';
}
if (name === 'juteyuji') {
return 'Juteyuji';
}
if (name === 'tukvaysi') {
return 'Tukvaysi';
}
}
const Entry = (props) => {
const {conlang} = props;
if (conlang === 'saimiar') {
if (conlang === Conlang.Saimiar) {
return <SaiEntry entry={ props.entry } />;
}
return <div>Unknown entry type for { conlang }</div>;
return <div>Conlang { conlang } not yet supported</div>;
};
const SaiEntry = (props) => {
@ -80,7 +87,8 @@ const Results = (props) => {
const content = () => {
const {conlang} = props;
const num = props.searchResults.length;
const renderedName = renderConlangName(conlang);
console.log(`Conlang is: ${conlang}`);
const renderedName = renderConlang(conlang);
const searchType = (props.direction === 'toConlang') ? `English -> ${renderedName}` : `${renderedName} -> English`;
const header = (
<div className="searchResultHeader" key="header">
@ -102,7 +110,7 @@ const Results = (props) => {
interface App {
[x: string]: any;
};
}
class App extends Component {
constructor(props) {
@ -112,17 +120,27 @@ class App extends Component {
this.searchEng = this.searchEng.bind(this);
this.searchSaimiar = this.searchSaimiar.bind(this);
this.searchConlang = this.searchConlang.bind(this);
this.state = {
searchResults: null,
conlang: 'saimiar',
conlang: Conlang.Saimiar,
direction: null,
searchTerm: null,
};
}
searchSaimiar(_evt) {
searchConlang(_evt) {
const searchTerm = this.input.current.value;
const {conlang} = this.state;
if (conlang === Conlang.Saimiar) {
this.searchSaimiar(searchTerm);
} else {
console.error(`Conlang ${conlang} not supported`);
}
}
searchSaimiar(searchTerm: string) {
const request = `saimiar?sai=like.*${searchTerm}*`;
if (searchTerm === '') {
this.setState({searchResults: null, searchTerm: null, direction: null});
@ -146,11 +164,19 @@ class App extends Component {
}
handleLangChange(evt) {
const conlang = evt.target.value;
const conlang: Conlang = evt.target.value as Conlang;
console.log('Conlang in handlelangchange', conlang);
this.setState({conlang});
}
render() {
const conlangs = [Conlang.Saimiar, Conlang.Elesu, Conlang.Tukvaysi, Conlang.Juteyuji];
const langSelectDropdown = (
<select ref={ this.langSelection } onChange={ this.handleLangChange } defaultValue={Conlang.Saimiar}>
{conlangs.map((conlang) => <option value={conlang} key={conlang}>{renderConlang(conlang)}</option>)}
</select>
);
return (
<main>
<div className="container">
@ -160,13 +186,8 @@ class App extends Component {
<input className="textInput" type="text" ref={ this.input } />
</div>
<br/>
<select ref={ this.langSelection } onChange={ this.handleLangChange } defaultValue="saimiar">
<option value="saimiar">Saimiar</option>
<option value="elesu">Elesu</option>
<option value="tukvaysi">Tukvaysi</option>
<option value="juteyuji">Juteyuji</option>
</select>
<button onClick={ this.searchSaimiar } className="searchButton">Saimiar</button>
{ langSelectDropdown }
<button onClick={ this.searchConlang } className="searchButton">{renderConlang(this.state.conlang)}</button>
<button onClick={ this.searchEng } className="searchButton">English</button>
</div>
<Results