import React, {useState} from "react"; import "./App.scss"; import {SaiEntryProps, JutEntryProps, ElesuEntryProps, TukEntryProps, Conlang, SearchDirection} from "./types"; import {SaiEntry, JutEntry, ElesuEntry, TukEntry} from "./Entries"; import {setPassword, searchEntry} from "./requests"; const PasswordDialog = (_props) => { const [password, setPasswordStr] = useState(""); const modal = (): any => document.querySelector(".passwordDialog"); const save = () => { setPassword(password); modal().close(); location.reload(); // TODO this is a hack }; const cancel = () => { modal().close(); }; return ( setPasswordStr(evt.target.value) } /> ); }; 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"; } }; interface EntryProps { conlang: Conlang; entry: SaiEntryProps | JutEntryProps | ElesuEntryProps | TukEntryProps; key: string; } const Entry = (props: EntryProps) => { const {conlang} = props; if (conlang === Conlang.Saimiar) { return ; } if (conlang === Conlang.Juteyuji) { return ; } if (conlang === Conlang.Elesu) { return ; } if (conlang === Conlang.Tukvaysi) { return ; } }; 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 result = num === 1 ? "result" : "results"; const header = (
Searched for { props.searchTerm }, { searchType }, found { num } { result }
); const entries = props.searchResults.map( (entry, _idx) => , ); return [header].concat(entries); }; const results = props.searchResults; return (
{ results ? content() : "No search" }
); }; const convertSearchBoxShorthand = (input: string, conlang: Conlang): string => { if (conlang === Conlang.Saimiar) { return (input as any) .replaceAll(/ee/g, "ê") .replaceAll(/oo/g, "ô") .replaceAll(/o'/g, "ø") .replaceAll(/c'/g, "ç") .replaceAll(/n'/g, "ŋ"); } return input; }; const App = (_props) => { const defaultConlang = window.sessionStorage.getItem("conlang") as Conlang || Conlang.Saimiar; const [searchResults, setSearchResults] = useState(null); const [conlang, setConlangState] = useState(defaultConlang); const [direction, setDirection] = useState(null); const [searchTerm, setSearchTerm] = useState(null); const [searchBoxInput, setSearchBoxInput] = useState(""); const setConlang = (conlang: Conlang) => { setConlangState(conlang); window.sessionStorage.setItem("conlang", conlang); }; const handleSearch = (direction: SearchDirection) => { const searchTerm = convertSearchBoxShorthand(searchBoxInput, conlang); if (searchTerm === "") { setSearchResults(null); setSearchTerm(null); setDirection(null); } else { searchEntry(searchTerm, conlang, direction, (json) => { setSearchResults(json); setSearchTerm(searchTerm); setDirection(direction); }); } }; 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 = ( ); const showPasswordBox = () => { const modal: any = document.querySelector(".passwordDialog"); modal.showModal(); }; return (

Kucinako - Wordbook of Arzhanai languages

Kucinako is a dictionary of words in various languages of the world Arzhanø, and their English equivalents.

{ setSearchBoxInput(evt.target.value); } } />

{ langSelectDropdown }
); }; export default App;