import React, { Component } from "react";
import './App.scss';
import { declineSaimiar } from './saimiar_morphology.js';
const backendUrl = "https://kucinakobackend.ichigo.everydayimshuflin.com";
function makeRequest(queryString, jsonHandler) {
const effectiveUrl = `${backendUrl}/${queryString}`
fetch(`${effectiveUrl}`)
.then((resp) => {
return resp.json()
})
.then((json) => {
jsonHandler(json);
});
}
function renderConlangName(name) {
if (name == "saimiar") {
return "Saimiar";
}
if (name == "elesu") {
return "Elésu";
}
if (name === "juteyuji") {
return "Juteyuji";
}
if (name === "tukvaysi") {
return "Tukvaysi";
}
}
function Entry(props) {
const conlang = props.conlang;
if (conlang === "saimiar") {
return ;
}
return
Unknown entry type for { conlang }
;
}
function SaiEntry(props) {
const entry = props.entry;
const synCategory = entry.syn_category;
const isNominal = synCategory == 'nominal';
console.log(isNominal);
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}`;
}
class Results extends Component {
constructor(props) {
super(props);
this.content = this.content.bind(this);
}
content() {
const conlang = this.props.conlang;
const num = this.props.searchResults.length;
const renderedName = renderConlangName(conlang);
const searchType = (this.props.direction === "toConlang") ? `English -> ${renderedName}` : `${renderedName} -> English`;
const header = (
Searched for { this.props.searchTerm }, { searchType }, found { num } result(s)
);
const entries = this.props.searchResults.map(
(entry, idx) =>
);
return [header].concat(entries);
}
render() {
const results = this.props.searchResults;
return(
{ results ? this.content() : "No search" }
);
}
}
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;