From 024b4c11faffe19cf7a8038fdcbc2dca27ab692d Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Wed, 15 Sep 2021 03:59:06 -0700 Subject: [PATCH] Add function for converting special characters --- src/App.tsx | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 04da993..f9535c0 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -103,6 +103,19 @@ const Results = (props: ResultsProps) => { ); }; +const convertSearchBoxShorthand = (input: string, conlang: Conlang): string => { + if (conlang === Conlang.Saimiar) { + return input + .replaceAll(/ee/g, "ê") + .replaceAll(/oo/g, "ô") + .replaceAll(/o'/g, "ø") + .replaceAll(/c'/g, "ç") + .replaceAll(/n'/g, "ŋ"); + } + + return input; +}; + const App = (_props) => { const defaultConlang = window.sessionStorage.getItem("conlang") as Conlang || Conlang.Saimiar; const [searchResults, setSearchResults] = useState(null); @@ -117,33 +130,17 @@ const App = (_props) => { window.sessionStorage.setItem("conlang", conlang); }; - const searchConlang = (_evt) => { - const searchTerm = searchBoxInput; - if (searchTerm === "") { - setSearchResults(null); - setSearchTerm(null); - setDirection(null); - return; - } - - searchEntry(searchTerm, conlang, SearchDirection.ToEnglish, (json) => { - setSearchResults(json); - setSearchTerm(searchTerm); - setDirection(SearchDirection.ToEnglish); - }); - }; - - const searchEng = (_evt) => { - const searchTerm = searchBoxInput; + const handleSearch = (direction: SearchDirection) => { + const searchTerm = convertSearchBoxShorthand(searchBoxInput, conlang); if (searchTerm === "") { setSearchResults(null); setSearchTerm(null); setDirection(null); } else { - searchEntry(searchTerm, conlang, SearchDirection.ToConlang, (json) => { + searchEntry(searchTerm, conlang, direction, (json) => { setSearchResults(json); setSearchTerm(searchTerm); - setDirection(SearchDirection.ToConlang); + setDirection(direction); }); } }; @@ -181,8 +178,8 @@ const App = (_props) => {
{ langSelectDropdown } - - + +