Use enum for search direction
This commit is contained in:
parent
9d52161957
commit
3ec15e30b3
13
src/App.tsx
13
src/App.tsx
@ -12,6 +12,11 @@ enum Conlang {
|
||||
Juteyuji = 'juteyuji',
|
||||
}
|
||||
|
||||
enum SearchDirection {
|
||||
ToConlang,
|
||||
ToEnglish
|
||||
}
|
||||
|
||||
const renderConlang = (conlang: Conlang): string => {
|
||||
if (conlang === Conlang.Saimiar) {
|
||||
return 'Saimiar';
|
||||
@ -107,7 +112,7 @@ const Results = (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)
|
||||
@ -167,7 +172,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 +183,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 +196,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});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user