Start supporting Juteyuji

This commit is contained in:
Greg Shuflin 2021-09-12 20:48:11 -07:00
parent eb46a87c8e
commit 9d52161957

View File

@ -6,10 +6,10 @@ import {declineSaimiar} from './saimiar_morphology';
const backendUrl = 'https://kucinakobackend.ichigo.everydayimshuflin.com'; const backendUrl = 'https://kucinakobackend.ichigo.everydayimshuflin.com';
enum Conlang { enum Conlang {
Saimiar = 'sai', Saimiar = 'saimiar',
Elesu = 'ele', Elesu = 'elesu',
Tukvaysi = 'tuk', Tukvaysi = 'tukvaysi',
Juteyuji = 'jut', Juteyuji = 'juteyuji',
} }
const renderConlang = (conlang: Conlang): string => { const renderConlang = (conlang: Conlang): string => {
@ -45,6 +45,10 @@ const Entry = (props) => {
return <SaiEntry entry={ props.entry } />; return <SaiEntry entry={ props.entry } />;
} }
if (conlang === Conlang.Juteyuji) {
return <JutEntry entry={ props.entry } />;
}
return <div>Conlang { conlang } not yet supported</div>; 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) { function formatMorphology(entry) {
const decl = declineSaimiar(entry); const decl = declineSaimiar(entry);
if (!decl) { if (!decl) {
@ -87,7 +105,7 @@ const Results = (props) => {
const content = () => { const content = () => {
const {conlang} = props; const {conlang} = props;
const num = props.searchResults.length; const num = props.searchResults.length;
console.log(`Conlang is: ${conlang}`);
const renderedName = renderConlang(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 = (
@ -120,6 +138,7 @@ 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.searchJuteyuji = this.searchJuteyuji.bind(this);
this.searchConlang = this.searchConlang.bind(this); this.searchConlang = this.searchConlang.bind(this);
this.state = { this.state = {
@ -135,6 +154,8 @@ class App extends Component {
const {conlang} = this.state; const {conlang} = this.state;
if (conlang === Conlang.Saimiar) { if (conlang === Conlang.Saimiar) {
this.searchSaimiar(searchTerm); this.searchSaimiar(searchTerm);
} else if (conlang == Conlang.Juteyuji) {
this.searchJuteyuji(searchTerm);
} else { } else {
console.error(`Conlang ${conlang} not supported`); 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) { searchEng(_evt) {
const searchTerm = this.input.current.value; const searchTerm = this.input.current.value;
const request = `saimiar?eng=like.*${searchTerm}*`; const {conlang} = this.state;
const request = `${conlang}?eng=like.*${searchTerm}*`;
if (searchTerm === '') { if (searchTerm === '') {
this.setState({searchResults: null, searchTerm: null}); this.setState({searchResults: null, searchTerm: null});
} else { } else {
@ -166,7 +199,7 @@ class App extends Component {
handleLangChange(evt) { handleLangChange(evt) {
const conlang: Conlang = evt.target.value as Conlang; const conlang: Conlang = evt.target.value as Conlang;
console.log('Conlang in handlelangchange', conlang); console.log('Conlang in handlelangchange', conlang);
this.setState({conlang}); this.setState({conlang, searchResults: null});
} }
render() { render() {