import React, {Component} from 'react';
import './App.scss';
import {declineSaimiar} from './saimiar_morphology';
const backendUrl = 'https://kucinakobackend.ichigo.everydayimshuflin.com';
function makeRequest(queryString, jsonHandler) {
const effectiveUrl = `${backendUrl}/${queryString}`;
fetch(`${effectiveUrl}`)
.then((resp) => resp.json())
.then((json) => {
jsonHandler(json);
});
}
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') {
return ;
}
return
Unknown entry type for { conlang }
;
};
const SaiEntry = (props) => {
const {entry} = props;
const synCategory = entry.syn_category;
const isNominal = synCategory === 'nominal';
return (
{ entry.sai } - { entry.eng }
{ entry.syn_category }
{ entry.morph_type ? `\t\t${entry.morph_type}` : null }
{ isNominal ? formatMorphology(entry) : null }
);
};
function formatMorphology(entry) {
const decl = declineSaimiar(entry);
if (!decl) {
return '';
}
return (
Abs: {decl.abs}, Erg: {decl.erg},
Adp: {decl.adp},
All: {decl.all},
Loc: {decl.loc},
Ell: {decl.ell},
Inst: {decl.inst},
Rel: {decl.rel}
);
}
const Results = (props) => {
const content = () => {
const {conlang} = props;
const num = props.searchResults.length;
const renderedName = renderConlangName(conlang);
const searchType = (props.direction === 'toConlang') ? `English -> ${renderedName}` : `${renderedName} -> English`;
const header = (
Searched for { props.searchTerm }, { searchType }, found { num } result(s)
);
const entries = props.searchResults.map(
(entry, _idx) => ,
);
return [header].concat(entries);
};
const results = props.searchResults;
return (
{ results ? content() : 'No search' }
);
};
interface App {
[x: string]: any;
};
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: 'saimiar',
direction: null,
searchTerm: null,
};
}
searchSaimiar(_evt) {
const searchTerm = this.input.current.value;
const request = `saimiar?sai=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}*`;
if (searchTerm === '') {
this.setState({searchResults: null, searchTerm: null});
} else {
makeRequest(request, (json) => {
this.setState({searchResults: json, searchTerm, direction: 'toConlang'});
});
}
}
handleLangChange(evt) {
const conlang = evt.target.value;
this.setState({conlang});
}
render() {
return (
);
}
}
export default App;