-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
frontend: DrawerModeSettings: Add drawer mode settings comp
Signed-off-by: Vincent T <[email protected]>
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
frontend/src/components/App/Settings/DrawerModeSettings.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { FormControlLabel, Switch } from '@mui/material'; | ||
import React from 'react'; | ||
import { useEffect } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useDispatch } from 'react-redux'; | ||
import { setDetailDrawerEnabled } from '../../../redux/drawerModeSlice'; | ||
import { useTypedSelector } from '../../../redux/reducers/reducers'; | ||
import { TooltipIcon } from '../../common'; | ||
|
||
export default function DrawerModeSettings() { | ||
const dispatch = useDispatch(); | ||
const { t } = useTranslation('translation'); | ||
|
||
const isDrawerEnabled = useTypedSelector(state => state.drawerMode.isDetailDrawerEnabled); | ||
|
||
if (isDrawerEnabled) { | ||
dispatch(setDetailDrawerEnabled(true)); | ||
} else { | ||
dispatch(setDetailDrawerEnabled(false)); | ||
} | ||
|
||
// the useEffect will run everytime the isDrawerEnabled state changes, which is everytime the user clicks the switch button because the switch button changes the state of isDrawerEnabled | ||
useEffect(() => { | ||
dispatch(setDetailDrawerEnabled(isDrawerEnabled)); | ||
}, [isDrawerEnabled]); | ||
|
||
// this function takes in the current changes and updates it, this kicks off the useEffect that is listening for changes to newDrawerEnabled | ||
function drawerModeToggle() { | ||
dispatch(setDetailDrawerEnabled(!isDrawerEnabled)); | ||
} | ||
|
||
// NOTICE THAT WE DO NOT USE isDrawerEnabled TO DETERMINE HOW THE SWITCH IS RENDERED UNDER THE CHECKED PROP, THIS IS BECAUSE THE USEEFFECT WILL RERENDER THE COMPONENT WITH THE NEW STATE | ||
return ( | ||
<FormControlLabel | ||
control={ | ||
<Switch | ||
checked={isDrawerEnabled} | ||
onClick={drawerModeToggle} | ||
name="drawerMode" | ||
color="primary" | ||
/> | ||
} | ||
label={ | ||
<> | ||
{t('translation|Drawer Mode')} | ||
<TooltipIcon> | ||
{t('translation|Enable details to render in side drawer window')} | ||
</TooltipIcon> | ||
</> | ||
} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters