Fix indenting

This commit is contained in:
Greg Shuflin 2021-09-12 02:07:44 -07:00
parent 44156694a2
commit 3b2083fa27

View File

@ -6,66 +6,66 @@ import {declineSaimiar} from './saimiar_morphology.ts';
const backendUrl = 'https://kucinakobackend.ichigo.everydayimshuflin.com'; const backendUrl = 'https://kucinakobackend.ichigo.everydayimshuflin.com';
function makeRequest(queryString, jsonHandler) { function makeRequest(queryString, jsonHandler) {
const effectiveUrl = `${backendUrl}/${queryString}`; const effectiveUrl = `${backendUrl}/${queryString}`;
fetch(`${effectiveUrl}`) fetch(`${effectiveUrl}`)
.then((resp) => resp.json()) .then((resp) => resp.json())
.then((json) => { .then((json) => {
jsonHandler(json); jsonHandler(json);
}); });
} }
function renderConlangName(name) { function renderConlangName(name) {
if (name === 'saimiar') { if (name === 'saimiar') {
return 'Saimiar'; return 'Saimiar';
} }
if (name === 'elesu') { if (name === 'elesu') {
return 'Elésu'; return 'Elésu';
} }
if (name === 'juteyuji') { if (name === 'juteyuji') {
return 'Juteyuji'; return 'Juteyuji';
} }
if (name === 'tukvaysi') { if (name === 'tukvaysi') {
return 'Tukvaysi'; return 'Tukvaysi';
} }
} }
const Entry = (props) => { const Entry = (props) => {
const {conlang} = props; const {conlang} = props;
if (conlang === 'saimiar') { if (conlang === 'saimiar') {
return <SaiEntry entry={ props.entry } />; return <SaiEntry entry={ props.entry } />;
} }
return <div>Unknown entry type for { conlang }</div>; return <div>Unknown entry type for { conlang }</div>;
}; };
const SaiEntry = (props) => { const SaiEntry = (props) => {
const {entry} = props; const {entry} = props;
const synCategory = entry.syn_category; const synCategory = entry.syn_category;
const isNominal = synCategory === 'nominal'; const isNominal = synCategory === 'nominal';
return ( return (
<div className="searchResult" key={ entry.id }> <div className="searchResult" key={ entry.id }>
<b>{ entry.sai }</b> - { entry.eng } <b>{ entry.sai }</b> - { entry.eng }
<br /> <br />
<span className="synclass"> <span className="synclass">
<i>{ entry.syn_category }</i> <i>{ entry.syn_category }</i>
{ entry.morph_type ? `\t\t${entry.morph_type}` : null } { entry.morph_type ? `\t\t${entry.morph_type}` : null }
<br/> <br/>
{ isNominal ? formatMorphology(entry) : null } { isNominal ? formatMorphology(entry) : null }
</span> </span>
</div> </div>
); );
}; };
function formatMorphology(entry) { function formatMorphology(entry) {
const decl = declineSaimiar(entry); const decl = declineSaimiar(entry);
if (!decl) { if (!decl) {
return ''; return '';
} }
return (<span style={ {fontSize: 'medium', color: '#6a3131'} } > return (<span style={ {fontSize: 'medium', color: '#6a3131'} } >
Abs: <i>{decl.abs}</i>, Erg: <i>{decl.erg}</i>, Abs: <i>{decl.abs}</i>, Erg: <i>{decl.erg}</i>,
Adp: <i>{decl.adp}</i>, Adp: <i>{decl.adp}</i>,
All: <i>{decl.all}</i>, All: <i>{decl.all}</i>,
@ -73,108 +73,108 @@ function formatMorphology(entry) {
Ell: <i>{decl.ell}</i>, Ell: <i>{decl.ell}</i>,
Inst: <i>{decl.inst}</i>, Inst: <i>{decl.inst}</i>,
Rel: <i>{decl.rel}</i> Rel: <i>{decl.rel}</i>
</span>); </span>);
} }
const Results = (props) => { const Results = (props) => {
const content = () => { const content = () => {
const {conlang} = props; const {conlang} = props;
const num = props.searchResults.length; const num = props.searchResults.length;
const renderedName = renderConlangName(conlang); const renderedName = renderConlangName(conlang);
const searchType = (props.direction === 'toConlang') ? `English -> ${renderedName}` : `${renderedName} -> English`; const searchType = (props.direction === 'toConlang') ? `English -> ${renderedName}` : `${renderedName} -> English`;
const header = ( const header = (
<div className="searchResultHeader" key="header"> <div className="searchResultHeader" key="header">
Searched for <b>{ props.searchTerm }</b>, { searchType }, found { num } result(s) Searched for <b>{ props.searchTerm }</b>, { searchType }, found { num } result(s)
</div>); </div>);
const entries = props.searchResults.map( const entries = props.searchResults.map(
(entry, _idx) => <Entry entry={ entry } key= { entry.id } conlang={ conlang } />, (entry, _idx) => <Entry entry={ entry } key= { entry.id } conlang={ conlang } />,
); );
return [header].concat(entries); return [header].concat(entries);
}; };
const results = props.searchResults; const results = props.searchResults;
return ( return (
<div className="results"> <div className="results">
{ results ? content() : 'No search' } { results ? content() : 'No search' }
</div> </div>
); );
}; };
class App extends Component { class App extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.input = React.createRef(); this.input = React.createRef();
this.handleLangChange = this.handleLangChange.bind(this); this.handleLangChange = this.handleLangChange.bind(this);
this.searchEng = this.searchEng.bind(this); this.searchEng = this.searchEng.bind(this);
this.searchSaimiar = this.searchSaimiar.bind(this); this.searchSaimiar = this.searchSaimiar.bind(this);
this.state = { this.state = {
searchResults: null, searchResults: null,
conlang: 'saimiar', conlang: 'saimiar',
direction: null, direction: null,
searchTerm: null, searchTerm: null,
}; };
} }
searchSaimiar(_evt) { searchSaimiar(_evt) {
const searchTerm = this.input.current.value; const searchTerm = this.input.current.value;
const request = `saimiar?sai=like.*${searchTerm}*`; const request = `saimiar?sai=like.*${searchTerm}*`;
if (searchTerm === '') { if (searchTerm === '') {
this.setState({searchResults: null, searchTerm: null, direction: null}); this.setState({searchResults: null, searchTerm: null, direction: null});
} else { } else {
makeRequest(request, (json) => { makeRequest(request, (json) => {
this.setState({searchResults: json, searchTerm, direction: 'toEnglish'}); this.setState({searchResults: json, searchTerm, direction: 'toEnglish'});
}); });
} }
} }
searchEng(_evt) { searchEng(_evt) {
const searchTerm = this.input.current.value; const searchTerm = this.input.current.value;
const request = `saimiar?eng=like.*${searchTerm}*`; const request = `saimiar?eng=like.*${searchTerm}*`;
if (searchTerm === '') { if (searchTerm === '') {
this.setState({searchResults: null, searchTerm: null}); this.setState({searchResults: null, searchTerm: null});
} else { } else {
makeRequest(request, (json) => { makeRequest(request, (json) => {
this.setState({searchResults: json, searchTerm, direction: 'toConlang'}); this.setState({searchResults: json, searchTerm, direction: 'toConlang'});
}); });
} }
} }
handleLangChange(evt) { handleLangChange(evt) {
const conlang = evt.target.value; const conlang = evt.target.value;
this.setState({conlang}); this.setState({conlang});
} }
render() { render() {
return ( return (
<main> <main>
<div className="container"> <div className="container">
<div className="search"> <div className="search">
<h1>Kucinako</h1> <h1>Kucinako</h1>
<div className="textInput"> <div className="textInput">
<input className="textInput" type="text" ref={ this.input } /> <input className="textInput" type="text" ref={ this.input } />
</div> </div>
<br/> <br/>
<select ref={ this.langSelection } onChange={ this.handleLangChange } defaultValue="saimiar"> <select ref={ this.langSelection } onChange={ this.handleLangChange } defaultValue="saimiar">
<option value="saimiar">Saimiar</option> <option value="saimiar">Saimiar</option>
<option value="elesu">Elesu</option> <option value="elesu">Elesu</option>
<option value="tukvaysi">Tukvaysi</option> <option value="tukvaysi">Tukvaysi</option>
<option value="juteyuji">Juteyuji</option> <option value="juteyuji">Juteyuji</option>
</select> </select>
<button onClick={ this.searchSaimiar } className="searchButton">Saimiar</button> <button onClick={ this.searchSaimiar } className="searchButton">Saimiar</button>
<button onClick={ this.searchEng } className="searchButton">English</button> <button onClick={ this.searchEng } className="searchButton">English</button>
</div> </div>
<Results <Results
searchResults={ this.state.searchResults } searchResults={ this.state.searchResults }
searchTerm= { this.state.searchTerm } searchTerm= { this.state.searchTerm }
conlang={ this.state.conlang } conlang={ this.state.conlang }
direction={ this.state.direction } direction={ this.state.direction }
/> />
</div> </div>
</main> </main>
); );
} }
} }
export default App; export default App;