From 3ec15e30b35837c159b56a426c59799e1d19e982 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sun, 12 Sep 2021 21:11:52 -0700 Subject: [PATCH] Use enum for search direction --- src/App.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index d351e88..0329305 100644 --- a/src/App.tsx +++ b/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 = (
Searched for { props.searchTerm }, { 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}); }); } }