import React, {useState} from 'react';
import './App.scss';
import {declineSaimiar} from './saimiar_morphology';
import {SaiEntryProps, JutEntryProps} from './dbtypes';
const backendUrl = 'https://kucinakobackend.ichigo.everydayimshuflin.com';
enum Conlang {
Saimiar = 'saimiar',
Elesu = 'elesu',
Tukvaysi = 'tukvaysi',
Juteyuji = 'juteyuji',
}
enum SearchDirection {
ToConlang,
ToEnglish
}
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) {
const effectiveUrl = `${backendUrl}/${queryString}`;
fetch(`${effectiveUrl}`)
.then((resp) => resp.json())
.then((json) => {
jsonHandler(json);
});
}
interface EntryProps {
conlang: Conlang;
entry: SaiEntryProps | JutEntryProps;
key: string;
}
const Entry = (props: EntryProps) => {
const {conlang} = props;
if (conlang === Conlang.Saimiar) {
return ;
}
if (conlang === Conlang.Juteyuji) {
return ;
}
return
Conlang { conlang } not yet supported
;
};
const SaiEntry = (props: {entry: SaiEntryProps}) => {
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 }
);
};
const JutEntry = (props: {entry: JutEntryProps}) => {
const {entry} = props;
return (
{ entry.jut } - { entry.eng }
{ entry.syn_category === 'noun' ? entry.gender : 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}
);
}
interface ResultsProps {
searchResults: Array;
searchTerm: string;
conlang: Conlang;
direction: SearchDirection;
}
const Results = (props: ResultsProps) => {
const content = () => {
const {conlang} = props;
const num = props.searchResults.length;
const renderedName = renderConlang(conlang);
const searchType = (props.direction === SearchDirection.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' }
);
};
const App = (_props) => {
const [searchResults, setSearchResults] = useState(null);
const [conlang, setConlang] = useState(Conlang.Saimiar);
const [direction, setDirection] = useState(null);
const [searchTerm, setSearchTerm] = useState(null);
const [searchBoxInput, setSearchBoxInput] = useState('');
const searchConlang = (_evt) => {
const searchTerm = searchBoxInput;
if (conlang === Conlang.Saimiar) {
searchSaimiar(searchTerm);
} else if (conlang === Conlang.Juteyuji) {
searchJuteyuji(searchTerm);
} else {
console.error(`Conlang ${conlang} not supported`);
}
};
const searchSaimiar = (searchTerm: string) => {
const request = `saimiar?sai=like.*${searchTerm}*`;
if (searchTerm === '') {
setSearchResults(null);
setSearchTerm(null);
setDirection(null);
} else {
makeRequest(request, (json) => {
setSearchResults(json);
setSearchTerm(searchTerm);
setDirection(SearchDirection.ToEnglish);
});
}
};
const searchJuteyuji = (searchTerm: string) => {
const request = `juteyuji?jut=like.*${searchTerm}*`;
if (searchTerm === '') {
setSearchResults(null);
setSearchTerm(null);
setDirection(null);
} else {
makeRequest(request, (json) => {
setSearchResults(json);
setSearchTerm(searchTerm);
setDirection(SearchDirection.ToEnglish);
});
}
};
const searchEng = (_evt) => {
const searchTerm = searchBoxInput;
const request = `${conlang}?eng=like.*${searchTerm}*`;
if (searchTerm === '') {
setSearchResults(null);
setSearchTerm(null);
} else {
makeRequest(request, (json) => {
setSearchResults(json);
setSearchTerm(searchTerm);
setDirection(SearchDirection.ToConlang);
});
}
};
const handleLangChange = (evt) => {
const conlang: Conlang = evt.target.value as Conlang;
setConlang(conlang);
setSearchResults(null);
};
const conlangs = [Conlang.Saimiar, Conlang.Elesu, Conlang.Tukvaysi, Conlang.Juteyuji];
const langSelectDropdown = (
);
return (
Kucinako - Wordbook of Arzhanai languages
Kucinako is a dictionary for searching for words in various languages of the world Arzhanø, and their English
equivalents.
{
setSearchBoxInput(evt.target.value);
} } />
{ langSelectDropdown }
);
};
export default App;