General improvements for non-Sai conlangs
This commit is contained in:
parent
010552a4fc
commit
eb46a87c8e
85
src/App.tsx
85
src/App.tsx
@ -5,6 +5,31 @@ import {declineSaimiar} from './saimiar_morphology';
|
|||||||
|
|
||||||
const backendUrl = 'https://kucinakobackend.ichigo.everydayimshuflin.com';
|
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) {
|
function makeRequest(queryString, jsonHandler) {
|
||||||
const effectiveUrl = `${backendUrl}/${queryString}`;
|
const effectiveUrl = `${backendUrl}/${queryString}`;
|
||||||
fetch(`${effectiveUrl}`)
|
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 Entry = (props) => {
|
||||||
const {conlang} = props;
|
const {conlang} = props;
|
||||||
if (conlang === 'saimiar') {
|
if (conlang === Conlang.Saimiar) {
|
||||||
return <SaiEntry entry={ props.entry } />;
|
return <SaiEntry entry={ props.entry } />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return <div>Unknown entry type for { conlang }</div>;
|
return <div>Conlang { conlang } not yet supported</div>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const SaiEntry = (props) => {
|
const SaiEntry = (props) => {
|
||||||
@ -80,7 +87,8 @@ const Results = (props) => {
|
|||||||
const content = () => {
|
const content = () => {
|
||||||
const {conlang} = props;
|
const {conlang} = props;
|
||||||
const num = props.searchResults.length;
|
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 searchType = (props.direction === 'toConlang') ? `English -> ${renderedName}` : `${renderedName} -> English`;
|
||||||
const header = (
|
const header = (
|
||||||
<div className="searchResultHeader" key="header">
|
<div className="searchResultHeader" key="header">
|
||||||
@ -102,7 +110,7 @@ const Results = (props) => {
|
|||||||
|
|
||||||
interface App {
|
interface App {
|
||||||
[x: string]: any;
|
[x: string]: any;
|
||||||
};
|
}
|
||||||
|
|
||||||
class App extends Component {
|
class App extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@ -112,17 +120,27 @@ class App extends Component {
|
|||||||
|
|
||||||
this.searchEng = this.searchEng.bind(this);
|
this.searchEng = this.searchEng.bind(this);
|
||||||
this.searchSaimiar = this.searchSaimiar.bind(this);
|
this.searchSaimiar = this.searchSaimiar.bind(this);
|
||||||
|
this.searchConlang = this.searchConlang.bind(this);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
searchResults: null,
|
searchResults: null,
|
||||||
conlang: 'saimiar',
|
conlang: Conlang.Saimiar,
|
||||||
direction: null,
|
direction: null,
|
||||||
searchTerm: null,
|
searchTerm: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
searchSaimiar(_evt) {
|
searchConlang(_evt) {
|
||||||
const searchTerm = this.input.current.value;
|
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}*`;
|
const request = `saimiar?sai=like.*${searchTerm}*`;
|
||||||
if (searchTerm === '') {
|
if (searchTerm === '') {
|
||||||
this.setState({searchResults: null, searchTerm: null, direction: null});
|
this.setState({searchResults: null, searchTerm: null, direction: null});
|
||||||
@ -146,11 +164,19 @@ class App extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleLangChange(evt) {
|
handleLangChange(evt) {
|
||||||
const conlang = evt.target.value;
|
const conlang: Conlang = evt.target.value as Conlang;
|
||||||
|
console.log('Conlang in handlelangchange', conlang);
|
||||||
this.setState({conlang});
|
this.setState({conlang});
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
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 (
|
return (
|
||||||
<main>
|
<main>
|
||||||
<div className="container">
|
<div className="container">
|
||||||
@ -160,13 +186,8 @@ class App extends Component {
|
|||||||
<input className="textInput" type="text" ref={ this.input } />
|
<input className="textInput" type="text" ref={ this.input } />
|
||||||
</div>
|
</div>
|
||||||
<br/>
|
<br/>
|
||||||
<select ref={ this.langSelection } onChange={ this.handleLangChange } defaultValue="saimiar">
|
{ langSelectDropdown }
|
||||||
<option value="saimiar">Saimiar</option>
|
<button onClick={ this.searchConlang } className="searchButton">{renderConlang(this.state.conlang)}</button>
|
||||||
<option value="elesu">Elesu</option>
|
|
||||||
<option value="tukvaysi">Tukvaysi</option>
|
|
||||||
<option value="juteyuji">Juteyuji</option>
|
|
||||||
</select>
|
|
||||||
<button onClick={ this.searchSaimiar } className="searchButton">Saimiar</button>
|
|
||||||
<button onClick={ this.searchEng } className="searchButton">English</button>
|
<button onClick={ this.searchEng } className="searchButton">English</button>
|
||||||
</div>
|
</div>
|
||||||
<Results
|
<Results
|
||||||
|
Loading…
Reference in New Issue
Block a user