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 } - - + +