App.js small refactor

This commit is contained in:
Mateusz Tylka 2023-05-22 10:19:25 +02:00
parent 2751eda1e8
commit 02a0f1435c

View File

@ -30,7 +30,7 @@ const App = () => {
const [popUpMessage, setPopUpMessage] = React.useState(''); const [popUpMessage, setPopUpMessage] = React.useState('');
const [confirmPopUpHandler, setConfirmPopUpHandler] = React.useState(null); const [confirmPopUpHandler, setConfirmPopUpHandler] = React.useState(null);
React.useEffect(() => { React.useMemo(() => {
if (sessionStorage.getItem('logout') === 'yes') { if (sessionStorage.getItem('logout') === 'yes') {
const pageName = window.location.pathname.split('/').at(-1); const pageName = window.location.pathname.split('/').at(-1);
if (LOGIN_REQUIRED_PAGES.includes(pageName)) { if (LOGIN_REQUIRED_PAGES.includes(pageName)) {
@ -60,7 +60,7 @@ const App = () => {
} }
} }
}, 1500); }, 1500);
}); }, []);
const popUpMessageHandler = (header, message, confirmHandler) => { const popUpMessageHandler = (header, message, confirmHandler) => {
setPopUpHeader(header); setPopUpHeader(header);
@ -85,19 +85,11 @@ const App = () => {
} }
}; };
const loggedBarVisibleHandler = () => { const loggedBarVisibleHandler = React.useCallback(() => {
if (loggedBarVisible === '0' && !loggedBarHover) if (loggedBarVisible === '0' && !loggedBarHover)
setLoggedBarVisible('100vw'); setLoggedBarVisible('100vw');
else setLoggedBarVisible('0'); else setLoggedBarVisible('0');
}; }, [loggedBarHover, loggedBarVisible]);
const loggedBarHoverTrue = () => {
setLoggedBarHover(true);
};
const loggedBarHoverFalse = () => {
setLoggedBarHover(false);
};
const renderApp = () => { const renderApp = () => {
return ( return (
@ -112,8 +104,8 @@ const App = () => {
<LoggedBar <LoggedBar
visible={loggedBarVisible} visible={loggedBarVisible}
loggedBarVisibleHandler={loggedBarVisibleHandler} loggedBarVisibleHandler={loggedBarVisibleHandler}
loggedBarHoverTrue={loggedBarHoverTrue} loggedBarHoverTrue={() => setLoggedBarHover(true)}
loggedBarHoverFalse={loggedBarHoverFalse} loggedBarHoverFalse={() => setLoggedBarHover(false)}
username={KeyCloakService.getUsername()} username={KeyCloakService.getUsername()}
/> />
) : ( ) : (