Compare commits

...

3 Commits

Author SHA1 Message Date
Greg Shuflin
146b8126a2 More typecheck, lint fixes 2021-09-12 21:35:46 -07:00
Greg Shuflin
cf975330f4 Fix eslint rules for typescript 2021-09-12 21:21:55 -07:00
Greg Shuflin
3ec15e30b3 Use enum for search direction 2021-09-12 21:11:52 -07:00
2 changed files with 50 additions and 12 deletions

View File

@ -21,6 +21,10 @@ module.exports = {
],
rules: {
"arrow-parens": ["error", "always"],
"indent": ["error", 4]
"indent": ["error", 4],
"unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
"no-redeclare": "off",
"@typescript-eslint/no-redeclare": ["error"]
},
};

View File

@ -12,6 +12,11 @@ enum Conlang {
Juteyuji = 'juteyuji',
}
enum SearchDirection {
ToConlang,
ToEnglish
}
const renderConlang = (conlang: Conlang): string => {
if (conlang === Conlang.Saimiar) {
return 'Saimiar';
@ -39,20 +44,34 @@ function makeRequest(queryString, jsonHandler) {
});
}
const Entry = (props) => {
interface EntryProps {
conlang: Conlang;
entry: SaiEntryProps | JutEntryProps;
key: string;
}
const Entry = (props: EntryProps) => {
const {conlang} = props;
if (conlang === Conlang.Saimiar) {
return <SaiEntry entry={ props.entry } />;
return <SaiEntry entry={ props.entry as SaiEntryProps } />;
}
if (conlang === Conlang.Juteyuji) {
return <JutEntry entry={ props.entry } />;
return <JutEntry entry={ props.entry as JutEntryProps } />;
}
return <div>Conlang { conlang } not yet supported</div>;
};
const SaiEntry = (props) => {
interface SaiEntryProps {
id: number;
sai: string;
eng: string;
syn_category: string;
morph_type: string;
}
const SaiEntry = (props: {entry: SaiEntryProps}) => {
const {entry} = props;
const synCategory = entry.syn_category;
const isNominal = synCategory === 'nominal';
@ -70,7 +89,15 @@ const SaiEntry = (props) => {
);
};
const JutEntry = (props) => {
interface JutEntryProps {
id: number;
jut: string;
eng: string;
syn_category: string;
gender: string;
}
const JutEntry = (props: {entry: JutEntryProps}) => {
const {entry} = props;
console.log(props);
@ -101,13 +128,20 @@ function formatMorphology(entry) {
</span>);
}
const Results = (props) => {
interface ResultsProps {
searchResults: any;
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 === 'toConlang') ? `English -> ${renderedName}` : `${renderedName} -> English`;
const searchType = (props.direction === SearchDirection.ToConlang) ? `English -> ${renderedName}` : `${renderedName} -> English`;
const header = (
<div className="searchResultHeader" key="header">
Searched for <b>{ props.searchTerm }</b>, { searchType }, found { num } result(s)
@ -154,7 +188,7 @@ class App extends Component {
const {conlang} = this.state;
if (conlang === Conlang.Saimiar) {
this.searchSaimiar(searchTerm);
} else if (conlang == Conlang.Juteyuji) {
} else if (conlang === Conlang.Juteyuji) {
this.searchJuteyuji(searchTerm);
} else {
console.error(`Conlang ${conlang} not supported`);
@ -167,7 +201,7 @@ class App extends Component {
this.setState({searchResults: null, searchTerm: null, direction: null});
} else {
makeRequest(request, (json) => {
this.setState({searchResults: json, searchTerm, direction: 'toEnglish'});
this.setState({searchResults: json, searchTerm, direction: SearchDirection.ToEnglish});
});
}
}
@ -178,7 +212,7 @@ class App extends Component {
this.setState({searchResults: null, searchTerm: null, direction: null});
} else {
makeRequest(request, (json) => {
this.setState({searchResults: json, searchTerm, direction: 'toEnglish'});
this.setState({searchResults: json, searchTerm, direction: SearchDirection.ToEnglish});
});
}
}
@ -191,7 +225,7 @@ class App extends Component {
this.setState({searchResults: null, searchTerm: null});
} else {
makeRequest(request, (json) => {
this.setState({searchResults: json, searchTerm, direction: 'toConlang'});
this.setState({searchResults: json, searchTerm, direction: SearchDirection.ToConlang});
});
}
}