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';
function makeRequest(queryString, jsonHandler) {
const effectiveUrl = `${backendUrl}/${queryString}`;
fetch(`${effectiveUrl}`)
.then((resp) => resp.json())
.then((json) => {
jsonHandler(json);
});
const effectiveUrl = `${backendUrl}/${queryString}`;
fetch(`${effectiveUrl}`)
.then((resp) => resp.json())
.then((json) => {
jsonHandler(json);
});
}
function renderConlangName(name) {
if (name === 'saimiar') {
return 'Saimiar';
}
if (name === 'saimiar') {
return 'Saimiar';
}
if (name === 'elesu') {
return 'Elésu';
}
if (name === 'elesu') {
return 'Elésu';
}
if (name === 'juteyuji') {
return 'Juteyuji';
}
if (name === 'juteyuji') {
return 'Juteyuji';
}
if (name === 'tukvaysi') {
return 'Tukvaysi';
}
if (name === 'tukvaysi') {
return 'Tukvaysi';
}
}
const Entry = (props) => {
const {conlang} = props;
if (conlang === 'saimiar') {
return <SaiEntry entry={ props.entry } />;
}
const {conlang} = props;
if (conlang === 'saimiar') {
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 {entry} = props;
const synCategory = entry.syn_category;
const isNominal = synCategory === 'nominal';
return (
<div className="searchResult" key={ entry.id }>
<b>{ entry.sai }</b> - { entry.eng }
<br />
<span className="synclass">
<i>{ entry.syn_category }</i>
{ entry.morph_type ? `\t\t${entry.morph_type}` : null }
<br/>
{ isNominal ? formatMorphology(entry) : null }
</span>
</div>
);
const {entry} = props;
const synCategory = entry.syn_category;
const isNominal = synCategory === 'nominal';
return (
<div className="searchResult" key={ entry.id }>
<b>{ entry.sai }</b> - { entry.eng }
<br />
<span className="synclass">
<i>{ entry.syn_category }</i>
{ entry.morph_type ? `\t\t${entry.morph_type}` : null }
<br/>
{ isNominal ? formatMorphology(entry) : null }
</span>
</div>
);
};
function formatMorphology(entry) {
const decl = declineSaimiar(entry);
if (!decl) {
return '';
}
const decl = declineSaimiar(entry);
if (!decl) {
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>,
Adp: <i>{decl.adp}</i>,
All: <i>{decl.all}</i>,
@ -73,108 +73,108 @@ function formatMorphology(entry) {
Ell: <i>{decl.ell}</i>,
Inst: <i>{decl.inst}</i>,
Rel: <i>{decl.rel}</i>
</span>);
</span>);
}
const Results = (props) => {
const content = () => {
const {conlang} = props;
const num = props.searchResults.length;
const renderedName = renderConlangName(conlang);
const searchType = (props.direction === 'toConlang') ? `English -> ${renderedName}` : `${renderedName} -> English`;
const header = (
<div className="searchResultHeader" key="header">
const content = () => {
const {conlang} = props;
const num = props.searchResults.length;
const renderedName = renderConlangName(conlang);
const searchType = (props.direction === 'toConlang') ? `English -> ${renderedName}` : `${renderedName} -> English`;
const header = (
<div className="searchResultHeader" key="header">
Searched for <b>{ props.searchTerm }</b>, { searchType }, found { num } result(s)
</div>);
const entries = props.searchResults.map(
(entry, _idx) => <Entry entry={ entry } key= { entry.id } conlang={ conlang } />,
);
return [header].concat(entries);
};
</div>);
const entries = props.searchResults.map(
(entry, _idx) => <Entry entry={ entry } key= { entry.id } conlang={ conlang } />,
);
return [header].concat(entries);
};
const results = props.searchResults;
return (
<div className="results">
{ results ? content() : 'No search' }
</div>
);
const results = props.searchResults;
return (
<div className="results">
{ results ? content() : 'No search' }
</div>
);
};
class App extends Component {
constructor(props) {
super(props);
this.input = React.createRef();
this.handleLangChange = this.handleLangChange.bind(this);
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.searchEng = this.searchEng.bind(this);
this.searchSaimiar = this.searchSaimiar.bind(this);
this.state = {
searchResults: null,
conlang: 'saimiar',
direction: null,
searchTerm: null,
};
}
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'});
});
}
}
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'});
});
}
}
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});
}
handleLangChange(evt) {
const conlang = evt.target.value;
this.setState({conlang});
}
render() {
return (
<main>
<div className="container">
<div className="search">
<h1>Kucinako</h1>
<div className="textInput">
<input className="textInput" type="text" ref={ this.input } />
</div>
<br/>
<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>
<button onClick={ this.searchSaimiar } className="searchButton">Saimiar</button>
<button onClick={ this.searchEng } className="searchButton">English</button>
</div>
<Results
searchResults={ this.state.searchResults }
searchTerm= { this.state.searchTerm }
conlang={ this.state.conlang }
direction={ this.state.direction }
/>
</div>
</main>
);
}
render() {
return (
<main>
<div className="container">
<div className="search">
<h1>Kucinako</h1>
<div className="textInput">
<input className="textInput" type="text" ref={ this.input } />
</div>
<br/>
<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>
<button onClick={ this.searchSaimiar } className="searchButton">Saimiar</button>
<button onClick={ this.searchEng } className="searchButton">English</button>
</div>
<Results
searchResults={ this.state.searchResults }
searchTerm= { this.state.searchTerm }
conlang={ this.state.conlang }
direction={ this.state.direction }
/>
</div>
</main>
);
}
}
export default App;