Add function for converting special characters
This commit is contained in:
parent
a574747d96
commit
024b4c11fa
41
src/App.tsx
41
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 App = (_props) => {
|
||||||
const defaultConlang = window.sessionStorage.getItem("conlang") as Conlang || Conlang.Saimiar;
|
const defaultConlang = window.sessionStorage.getItem("conlang") as Conlang || Conlang.Saimiar;
|
||||||
const [searchResults, setSearchResults] = useState(null);
|
const [searchResults, setSearchResults] = useState(null);
|
||||||
@ -117,33 +130,17 @@ const App = (_props) => {
|
|||||||
window.sessionStorage.setItem("conlang", conlang);
|
window.sessionStorage.setItem("conlang", conlang);
|
||||||
};
|
};
|
||||||
|
|
||||||
const searchConlang = (_evt) => {
|
const handleSearch = (direction: SearchDirection) => {
|
||||||
const searchTerm = searchBoxInput;
|
const searchTerm = convertSearchBoxShorthand(searchBoxInput, conlang);
|
||||||
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;
|
|
||||||
if (searchTerm === "") {
|
if (searchTerm === "") {
|
||||||
setSearchResults(null);
|
setSearchResults(null);
|
||||||
setSearchTerm(null);
|
setSearchTerm(null);
|
||||||
setDirection(null);
|
setDirection(null);
|
||||||
} else {
|
} else {
|
||||||
searchEntry(searchTerm, conlang, SearchDirection.ToConlang, (json) => {
|
searchEntry(searchTerm, conlang, direction, (json) => {
|
||||||
setSearchResults(json);
|
setSearchResults(json);
|
||||||
setSearchTerm(searchTerm);
|
setSearchTerm(searchTerm);
|
||||||
setDirection(SearchDirection.ToConlang);
|
setDirection(direction);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -181,8 +178,8 @@ const App = (_props) => {
|
|||||||
</div>
|
</div>
|
||||||
<br/>
|
<br/>
|
||||||
{ langSelectDropdown }
|
{ langSelectDropdown }
|
||||||
<button onClick={ searchConlang } className="searchButton">{renderConlang(conlang)}</button>
|
<button onClick={ () => handleSearch(SearchDirection.ToEnglish) } className="searchButton">{renderConlang(conlang)}</button>
|
||||||
<button onClick={ searchEng } className="searchButton">English</button>
|
<button onClick={ () => handleSearch(SearchDirection.ToConlang) } className="searchButton">English</button>
|
||||||
<button onClick={ showPasswordBox } className="searchButton">Password</button>
|
<button onClick={ showPasswordBox } className="searchButton">Password</button>
|
||||||
</div>
|
</div>
|
||||||
<Results
|
<Results
|
||||||
|
Loading…
Reference in New Issue
Block a user