2019-01-22 00:41:13 -08:00
|
|
|
import React, { Component } from "react";
|
|
|
|
|
2019-01-25 02:19:22 -08:00
|
|
|
import './App.scss';
|
2019-07-23 02:54:10 -07:00
|
|
|
import { declineSaimiar } from './saimiar_morphology.js';
|
2019-01-25 02:19:22 -08:00
|
|
|
|
2019-01-24 02:56:41 -08:00
|
|
|
const backendUrl = "https://kucinakobackend.ichigo.everydayimshuflin.com";
|
|
|
|
|
|
|
|
function makeRequest(queryString, jsonHandler) {
|
|
|
|
const effectiveUrl = `${backendUrl}/${queryString}`
|
2019-01-26 01:18:27 -08:00
|
|
|
fetch(`${effectiveUrl}`)
|
2019-01-24 02:56:41 -08:00
|
|
|
.then((resp) => {
|
|
|
|
return resp.json()
|
|
|
|
})
|
|
|
|
.then((json) => {
|
|
|
|
jsonHandler(json);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-01-28 23:08:43 -08:00
|
|
|
function renderConlangName(name) {
|
|
|
|
if (name == "saimiar") {
|
|
|
|
return "Saimiar";
|
|
|
|
}
|
|
|
|
if (name == "elesu") {
|
|
|
|
return "Elésu";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name === "juteyuji") {
|
|
|
|
return "Juteyuji";
|
|
|
|
}
|
|
|
|
if (name === "tukvaysi") {
|
|
|
|
return "Tukvaysi";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-26 01:34:35 -08:00
|
|
|
function Entry(props) {
|
2019-01-28 23:08:43 -08:00
|
|
|
const conlang = props.conlang;
|
|
|
|
if (conlang === "saimiar") {
|
|
|
|
return <SaiEntry entry={ props.entry } />;
|
|
|
|
}
|
|
|
|
return <div>Unknown entry type for { conlang }</div>;
|
|
|
|
}
|
|
|
|
|
|
|
|
function SaiEntry(props) {
|
2019-01-26 01:34:35 -08:00
|
|
|
const entry = props.entry;
|
2019-07-23 02:54:10 -07:00
|
|
|
const synCategory = entry.syn_category;
|
|
|
|
const isNominal = synCategory == 'nominal';
|
|
|
|
console.log(isNominal);
|
2019-01-26 01:34:35 -08:00
|
|
|
return (
|
|
|
|
<div className="searchResult" key={ entry.id }>
|
|
|
|
<b>{ entry.sai }</b> - { entry.eng }
|
|
|
|
<br />
|
2019-01-26 01:55:19 -08:00
|
|
|
<span className="synclass">
|
|
|
|
<i>{ entry.syn_category }</i>
|
|
|
|
{ entry.morph_type ? `\t\t${entry.morph_type}` : null }
|
2019-07-23 02:54:10 -07:00
|
|
|
<br/>
|
|
|
|
{ isNominal ? formatMorphology(entry) : null }
|
2019-01-26 01:55:19 -08:00
|
|
|
</span>
|
2019-01-26 01:34:35 -08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-07-23 02:54:10 -07:00
|
|
|
function formatMorphology(entry) {
|
|
|
|
const decl = declineSaimiar(entry);
|
|
|
|
if (!decl) {
|
|
|
|
return '';
|
|
|
|
}
|
2021-09-11 20:14:59 -07:00
|
|
|
return (<span style={ {fontSize: 'medium', color: '#6a3131'} } >
|
|
|
|
Abs: <i>{decl.abs}</i>, Erg: <i>{decl.erg}</i>,
|
|
|
|
Adp: <i>{decl.adp}</i>,
|
|
|
|
All: <i>{decl.all}</i>,
|
|
|
|
Loc: <i>{decl.loc}</i>,
|
|
|
|
Ell: <i>{decl.ell}</i>,
|
|
|
|
Inst: <i>{decl.inst}</i>,
|
|
|
|
Rel: <i>{decl.rel}</i>
|
|
|
|
</span>);
|
2019-07-23 02:54:10 -07:00
|
|
|
}
|
|
|
|
|
2019-01-26 01:18:27 -08:00
|
|
|
class Results extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.content = this.content.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
content() {
|
2019-01-28 23:08:43 -08:00
|
|
|
const conlang = this.props.conlang;
|
2019-01-26 02:23:50 -08:00
|
|
|
const num = this.props.searchResults.length;
|
2019-01-28 23:08:43 -08:00
|
|
|
const renderedName = renderConlangName(conlang);
|
|
|
|
const searchType = (this.props.direction === "toConlang") ? `English -> ${renderedName}` : `${renderedName} -> English`;
|
2019-01-26 01:18:27 -08:00
|
|
|
const header = (
|
2019-01-28 22:13:08 -08:00
|
|
|
<div className="searchResultHeader" key="header">
|
|
|
|
Searched for <b>{ this.props.searchTerm }</b>, { searchType }, found { num } result(s)
|
2019-01-26 01:18:27 -08:00
|
|
|
</div>);
|
2019-01-26 01:34:35 -08:00
|
|
|
const entries = this.props.searchResults.map(
|
2019-01-28 23:08:43 -08:00
|
|
|
(entry, idx) => <Entry entry={ entry } key= { entry.id } conlang={ conlang } />
|
2019-01-26 01:34:35 -08:00
|
|
|
);
|
2019-01-26 01:18:27 -08:00
|
|
|
return [header].concat(entries);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const results = this.props.searchResults;
|
|
|
|
return(
|
|
|
|
<div className='results'>
|
2021-09-11 20:14:59 -07:00
|
|
|
{ results ? this.content() : "No search" }
|
2019-01-26 01:18:27 -08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-22 00:41:13 -08:00
|
|
|
class App extends Component {
|
2019-01-24 02:56:41 -08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.input = React.createRef();
|
2019-01-28 23:08:43 -08:00
|
|
|
this.handleLangChange = this.handleLangChange.bind(this);
|
|
|
|
|
2019-01-26 01:18:27 -08:00
|
|
|
this.searchEng = this.searchEng.bind(this);
|
|
|
|
this.searchSaimiar = this.searchSaimiar.bind(this);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
searchResults: null,
|
2019-01-28 23:08:43 -08:00
|
|
|
conlang: "saimiar",
|
2019-01-28 22:13:08 -08:00
|
|
|
direction: null,
|
2019-01-26 01:18:27 -08:00
|
|
|
searchTerm: null
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
searchSaimiar(evt) {
|
|
|
|
const searchTerm = this.input.current.value;
|
|
|
|
const request = `saimiar?sai=like.*${searchTerm}*`
|
2019-01-26 02:23:50 -08:00
|
|
|
if (searchTerm === "") {
|
2019-01-28 23:08:43 -08:00
|
|
|
this.setState({ searchResults: null, searchTerm: null, direction: null });
|
2019-01-26 02:23:50 -08:00
|
|
|
} else {
|
|
|
|
makeRequest(request, (json) => {
|
2019-01-28 23:08:43 -08:00
|
|
|
this.setState({ searchResults: json, searchTerm, direction: "toEnglish" });
|
2019-01-26 02:23:50 -08:00
|
|
|
});
|
|
|
|
}
|
2019-01-24 02:56:41 -08:00
|
|
|
}
|
|
|
|
|
2019-01-26 01:18:27 -08:00
|
|
|
searchEng(evt) {
|
|
|
|
const searchTerm = this.input.current.value;
|
|
|
|
const request = `saimiar?eng=like.*${searchTerm}*`
|
2019-01-26 02:23:50 -08:00
|
|
|
if (searchTerm === "") {
|
2019-01-28 23:08:43 -08:00
|
|
|
this.setState({ searchResults: null, searchTerm: null, });
|
2019-01-26 02:23:50 -08:00
|
|
|
} else {
|
|
|
|
makeRequest(request, (json) => {
|
2019-01-28 23:08:43 -08:00
|
|
|
this.setState({ searchResults: json, searchTerm, direction: "toConlang" });
|
2019-01-26 02:23:50 -08:00
|
|
|
});
|
|
|
|
}
|
2019-01-24 02:56:41 -08:00
|
|
|
}
|
|
|
|
|
2019-01-28 23:08:43 -08:00
|
|
|
handleLangChange(evt) {
|
|
|
|
const conlang = evt.target.value;
|
|
|
|
this.setState({ conlang });
|
|
|
|
}
|
|
|
|
|
2019-01-22 00:41:13 -08:00
|
|
|
render() {
|
2019-01-28 23:08:43 -08:00
|
|
|
|
2019-01-22 00:41:13 -08:00
|
|
|
return(
|
2019-01-25 02:19:22 -08:00
|
|
|
<main>
|
|
|
|
<div className='container'>
|
2019-01-26 01:18:27 -08:00
|
|
|
<div className='search'>
|
|
|
|
<h1>Kucinako</h1>
|
|
|
|
<div className='textInput'>
|
|
|
|
<input className='textInput' type="text" ref={ this.input } />
|
|
|
|
</div>
|
|
|
|
<br/>
|
2019-01-28 23:08:43 -08:00
|
|
|
<select ref={ this.langSelection } onChange={ this.handleLangChange } defaultValue="saimiar">
|
|
|
|
<option value="saimiar">Saimiar</option>
|
|
|
|
<option value="elesu">Elesu</option>
|
|
|
|
<option value="tukvaysi">Tukvaysi</option>
|
|
|
|
<option value="juteyuji">Juteyuji</option>
|
|
|
|
</select>
|
2019-01-26 01:18:27 -08:00
|
|
|
<button onClick={ this.searchSaimiar } className="searchButton">Saimiar</button>
|
|
|
|
<button onClick={ this.searchEng } className="searchButton">English</button>
|
2019-01-25 02:19:22 -08:00
|
|
|
</div>
|
2019-01-26 01:55:19 -08:00
|
|
|
<Results
|
|
|
|
searchResults={ this.state.searchResults }
|
|
|
|
searchTerm= { this.state.searchTerm }
|
2019-01-28 22:13:08 -08:00
|
|
|
conlang={ this.state.conlang }
|
|
|
|
direction={ this.state.direction }
|
2019-01-26 01:55:19 -08:00
|
|
|
/>
|
2019-01-25 02:19:22 -08:00
|
|
|
</div>
|
|
|
|
</main>
|
2019-01-22 00:41:13 -08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-26 01:18:27 -08:00
|
|
|
|
|
|
|
|
2019-01-22 00:41:13 -08:00
|
|
|
export default App;
|