Store language in browser session storage

This commit is contained in:
Greg Shuflin 2021-09-12 23:15:32 -07:00
parent f4e674c88f
commit e5b6d99f23

View File

@ -39,7 +39,7 @@ const renderConlang = (conlang: Conlang): string => {
function buildRequest(searchTerm: string, conlang: Conlang, direction: SearchDirection, jsonHandler: (json: Object) => void) { function buildRequest(searchTerm: string, conlang: Conlang, direction: SearchDirection, jsonHandler: (json: Object) => void) {
const specForConlang = { const specForConlang = {
[Conlang.Saimiar]: 'sai', [Conlang.Saimiar]: 'sai',
[Conlang.Juteyuji]: 'sai', [Conlang.Juteyuji]: 'jut',
[Conlang.Tukvaysi]: 'tuk', [Conlang.Tukvaysi]: 'tuk',
[Conlang.Elesu]: 'elesu', [Conlang.Elesu]: 'elesu',
}; };
@ -188,13 +188,19 @@ const Results = (props: ResultsProps) => {
}; };
const App = (_props) => { const App = (_props) => {
const defaultConlang = window.sessionStorage.getItem('conlang') as Conlang || Conlang.Saimiar;
const [searchResults, setSearchResults] = useState(null); const [searchResults, setSearchResults] = useState(null);
const [conlang, setConlang] = useState(Conlang.Saimiar); const [conlang, setConlangState] = useState(defaultConlang);
const [direction, setDirection] = useState(null); const [direction, setDirection] = useState(null);
const [searchTerm, setSearchTerm] = useState(null); const [searchTerm, setSearchTerm] = useState(null);
const [searchBoxInput, setSearchBoxInput] = useState(''); const [searchBoxInput, setSearchBoxInput] = useState('');
const setConlang = (conlang: Conlang) => {
setConlangState(conlang);
window.sessionStorage.setItem('conlang', conlang);
};
const searchConlang = (_evt) => { const searchConlang = (_evt) => {
const searchTerm = searchBoxInput; const searchTerm = searchBoxInput;
if (searchTerm === '') { if (searchTerm === '') {