From 5bc2917e78c133cd8966a65aa200588eb6d7c0d6 Mon Sep 17 00:00:00 2001
From: Piotr Russ <mail@pruss.it>
Date: Fri, 27 Nov 2020 00:38:22 +0100
Subject: save language in login & admin apps

---
 client/src/login/jsx/App.jsx | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

(limited to 'client/src/login/jsx/App.jsx')

diff --git a/client/src/login/jsx/App.jsx b/client/src/login/jsx/App.jsx
index e33e6c2..58256a8 100644
--- a/client/src/login/jsx/App.jsx
+++ b/client/src/login/jsx/App.jsx
@@ -1,4 +1,4 @@
-import React, { useState } from 'react';
+import React, { useState, useEffect } from 'react';
 import ReactDOM from 'react-dom';
 
 import "../scss/index.scss";
@@ -13,18 +13,27 @@ const App = () => {
   const [lang, setLang] = useState(defaultLanguage);
   const [info, setInfo] = useState('login-info');
   const [hover, setHover] = useState('');
-  const [user, setUser] = useState(null);
+
+  const setLangHelper = (key) => {
+    setLang(key);
+    localStorage.setItem('language', key);
+  }
+
+  useEffect(() => {
+    const savedLang = localStorage.getItem('language');
+    if (savedLang) {
+      setLang(savedLang);
+    }
+  }, [])
 
   return (
     <Context.Provider value={{ lang, setHover, setInfo }}>
       <div className="main">
         <TopBar
           lang={lang}
-          setLang={setLang}
-        />
-        <LoginPanel
-          setUser={setUser}
+          setLang={setLangHelper}
         />
+        <LoginPanel/>
         <Info
           info={info}
           hover={hover}
-- 
cgit v1.2.3

