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',
|
Juteyuji = 'juteyuji',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum SearchDirection {
|
||||||
|
ToConlang,
|
||||||
|
ToEnglish
|
||||||
|
}
|
||||||
|
|
||||||
const renderConlang = (conlang: Conlang): string => {
|
const renderConlang = (conlang: Conlang): string => {
|
||||||
if (conlang === Conlang.Saimiar) {
|
if (conlang === Conlang.Saimiar) {
|
||||||
return 'Saimiar';
|
return 'Saimiar';
|
||||||
@ -107,7 +112,7 @@ const Results = (props) => {
|
|||||||
const num = props.searchResults.length;
|
const num = props.searchResults.length;
|
||||||
|
|
||||||
const renderedName = renderConlang(conlang);
|
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 = (
|
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)
|
||||||
@ -167,7 +172,7 @@ class App extends Component {
|
|||||||
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: SearchDirection.ToEnglish});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -178,7 +183,7 @@ class App extends Component {
|
|||||||
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: SearchDirection.ToEnglish});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -191,7 +196,7 @@ class App extends Component {
|
|||||||
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: SearchDirection.ToConlang});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user