Start supporting Juteyuji

This commit is contained in:
Greg Shuflin 2021-09-12 20:48:11 -07:00
parent eb46a87c8e
commit 9d52161957
1 changed files with 40 additions and 7 deletions

View File

@ -6,10 +6,10 @@ import {declineSaimiar} from './saimiar_morphology';
const backendUrl = 'https://kucinakobackend.ichigo.everydayimshuflin.com';
enum Conlang {
Saimiar = 'sai',
Elesu = 'ele',
Tukvaysi = 'tuk',
Juteyuji = 'jut',
Saimiar = 'saimiar',
Elesu = 'elesu',
Tukvaysi = 'tukvaysi',
Juteyuji = 'juteyuji',
}
const renderConlang = (conlang: Conlang): string => {
@ -45,6 +45,10 @@ const Entry = (props) => {
return <SaiEntry entry={ props.entry } />;
}
if (conlang === Conlang.Juteyuji) {
return <JutEntry entry={ props.entry } />;
}
return <div>Conlang { conlang } not yet supported</div>;
};
@ -66,6 +70,20 @@ const SaiEntry = (props) => {
);
};
const JutEntry = (props) => {
const {entry} = props;
console.log(props);
return (
<div className="searchResult" key={ entry.id }>
<b>{ entry.jut }</b> - { entry.eng }
<br/>
<span className="synclass">
{ entry.syn_category === 'noun' ? entry.gender : null }
</span>
</div>);
};
function formatMorphology(entry) {
const decl = declineSaimiar(entry);
if (!decl) {
@ -87,7 +105,7 @@ const Results = (props) => {
const content = () => {
const {conlang} = props;
const num = props.searchResults.length;
console.log(`Conlang is: ${conlang}`);
const renderedName = renderConlang(conlang);
const searchType = (props.direction === 'toConlang') ? `English -> ${renderedName}` : `${renderedName} -> English`;
const header = (
@ -120,6 +138,7 @@ class App extends Component {
this.searchEng = this.searchEng.bind(this);
this.searchSaimiar = this.searchSaimiar.bind(this);
this.searchJuteyuji = this.searchJuteyuji.bind(this);
this.searchConlang = this.searchConlang.bind(this);
this.state = {
@ -135,6 +154,8 @@ class App extends Component {
const {conlang} = this.state;
if (conlang === Conlang.Saimiar) {
this.searchSaimiar(searchTerm);
} else if (conlang == Conlang.Juteyuji) {
this.searchJuteyuji(searchTerm);
} else {
console.error(`Conlang ${conlang} not supported`);
}
@ -151,9 +172,21 @@ class App extends Component {
}
}
searchJuteyuji(searchTerm: string) {
const request = `juteyuji?jut=like.*${searchTerm}*`;
if (searchTerm === '') {
this.setState({searchResults: null, searchTerm: null, direction: null});
} else {
makeRequest(request, (json) => {
this.setState({searchResults: json, searchTerm, direction: 'toEnglish'});
});
}
}
searchEng(_evt) {
const searchTerm = this.input.current.value;
const request = `saimiar?eng=like.*${searchTerm}*`;
const {conlang} = this.state;
const request = `${conlang}?eng=like.*${searchTerm}*`;
if (searchTerm === '') {
this.setState({searchResults: null, searchTerm: null});
} else {
@ -166,7 +199,7 @@ class App extends Component {
handleLangChange(evt) {
const conlang: Conlang = evt.target.value as Conlang;
console.log('Conlang in handlelangchange', conlang);
this.setState({conlang});
this.setState({conlang, searchResults: null});
}
render() {