-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Vincent T <[email protected]>
- Loading branch information
Showing
7 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
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
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,57 @@ | ||
import { FormControlLabel, Switch } from '@material-ui/core'; | ||
import React from 'react'; | ||
import { useEffect, useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useDispatch } from 'react-redux'; | ||
import { setDetailDrawerEnabled } from '../../../redux/drawerModeSlice'; | ||
import { useTypedSelector } from '../../../redux/reducers/reducers'; | ||
|
||
// const useStyles = makeStyles((theme: Theme) => ({ | ||
// buttonGroup: { | ||
// '& button': { | ||
// boxShadow: 'none', | ||
// borderRadius: '4px', | ||
// padding: '0.8rem 1.5rem', | ||
// }, | ||
// '& .MuiButton-contained': { | ||
// backgroundColor: theme.palette.type === 'dark' ? '' : 'rgba(0, 0, 0, 0.45)', | ||
// color: theme.palette.type === 'dark' ? '' : 'rgb(255, 255, 255)', | ||
// }, | ||
// }, | ||
// })); | ||
|
||
export default function DrawerModeButton() { | ||
const isDetailDrawerEnabled = useTypedSelector(state => state.drawerMode.isDetailDrawerEnabled); | ||
// localDetailDrawerEnabled is a string of either 'true' or 'false', if it does not exist yet it needs to be created | ||
const localDetailDrawerEnabled = Boolean(localStorage.getItem('detailDrawerEnabled')); | ||
|
||
const [newDrawerEnabled, changeDetailDrawerEnabled] = useState(localDetailDrawerEnabled); | ||
|
||
const dispatch = useDispatch(); | ||
const { t } = useTranslation('frequent'); | ||
|
||
useEffect(() => { | ||
dispatch(setDetailDrawerEnabled(newDrawerEnabled)); | ||
}, [newDrawerEnabled]); | ||
|
||
function drawerModeToggle() { | ||
console.log('drawerModeToggle'); | ||
changeDetailDrawerEnabled(!localDetailDrawerEnabled); | ||
} | ||
|
||
return ( | ||
<FormControlLabel | ||
control={ | ||
<Switch | ||
checked={localDetailDrawerEnabled} | ||
onChange={() => drawerModeToggle()} | ||
name="drawerMode" | ||
color="primary" | ||
/> | ||
} | ||
label={ | ||
isDetailDrawerEnabled ? t('Disable Detail Drawer Mode') : t('Enable Detail Drawer Mode') | ||
} | ||
/> | ||
); | ||
} |
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
62 changes: 62 additions & 0 deletions
62
frontend/src/components/common/DetailsDrawer/DetailDrawer.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,62 @@ | ||
import { Button } from '@material-ui/core'; | ||
import Box from '@material-ui/core/Box'; | ||
import Drawer from '@material-ui/core/Drawer'; | ||
import React from 'react'; | ||
import { useState } from 'react'; | ||
import { useEffect } from 'react'; | ||
import { useDispatch } from 'react-redux'; | ||
import { setDetailDrawerOpen } from '../../../redux/drawerModeSlice'; | ||
import { useTypedSelector } from '../../../redux/reducers/reducers'; | ||
|
||
export interface DetailDrawerProps { | ||
open: boolean; | ||
onClose?: () => void; | ||
children?: React.ReactNode; | ||
} | ||
|
||
export default function DetailDrawer({ open, onClose, children }: DetailDrawerProps) { | ||
const isDetailDrawerOpen = useTypedSelector(state => state.drawerMode.isDetailDrawerOpen); | ||
const [openDetailDrawer, changeOpenDetailDrawer] = useState(isDetailDrawerOpen); | ||
|
||
const dispatch = useDispatch(); | ||
|
||
useEffect(() => { | ||
dispatch(setDetailDrawerOpen(openDetailDrawer)); | ||
}, [openDetailDrawer]); | ||
|
||
function toggleOpenDrawer() { | ||
changeOpenDetailDrawer(!openDetailDrawer); | ||
} | ||
|
||
return ( | ||
<> | ||
{!isDetailDrawerOpen && ( | ||
<> | ||
<Drawer anchor="right" open={!open} onClose={onClose}> | ||
<Box width={200} p={2}> | ||
<Button onClick={() => toggleOpenDrawer()}>Open</Button> | ||
</Box> | ||
</Drawer> | ||
</> | ||
)} | ||
{isDetailDrawerOpen && ( | ||
<> | ||
<Drawer anchor="right" open={open} onClose={() => toggleOpenDrawer()}> | ||
<Box width={600} p={2}> | ||
<Button onClick={() => toggleOpenDrawer()}>Close</Button> | ||
{children} | ||
</Box> | ||
</Drawer> | ||
</> | ||
)} | ||
</> | ||
); | ||
} | ||
|
||
// FIX | ||
// * console log prints that the state resets? localStorage fix maybe | ||
// - maybe by adding the local storage save in the useEffect? | ||
// - if no local storage key exists, create one | ||
// * CREATE A LOCAL STORAGE FOR OPEN DRAWER SAME AS ENABLED DRAWER | ||
|
||
// * the drawer is not opening in minimized mode? persistent drawer fix maybe - https://mui.com/material-ui/react-drawer/#persistent-drawer |
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,29 @@ | ||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'; | ||
|
||
interface DrawerModeState { | ||
isDetailDrawerEnabled: boolean; | ||
isDetailDrawerOpen: boolean; | ||
} | ||
|
||
const initialState: DrawerModeState = { | ||
isDetailDrawerEnabled: false, | ||
isDetailDrawerOpen: false, | ||
}; | ||
|
||
const drawerModeSlice = createSlice({ | ||
name: 'drawerMode', | ||
initialState, | ||
reducers: { | ||
setDetailDrawerEnabled: (state, action: PayloadAction<boolean>) => { | ||
state.isDetailDrawerEnabled = action.payload; | ||
localStorage.setItem('detailDrawerEnabled', `${action.payload}`); | ||
}, | ||
setDetailDrawerOpen: (state, action: PayloadAction<boolean>) => { | ||
state.isDetailDrawerOpen = action.payload; | ||
localStorage.setItem('detailDrawerOpen', `${action.payload}`); | ||
}, | ||
}, | ||
}); | ||
|
||
export const { setDetailDrawerEnabled, setDetailDrawerOpen } = drawerModeSlice.actions; | ||
export default drawerModeSlice.reducer; |
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
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