Skip to content

Commit

Permalink
Merge branch 'issue/#34' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ohinhyuk committed Sep 14, 2023
2 parents 83413d5 + f6815cd commit bc6d114
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 23 deletions.
27 changes: 22 additions & 5 deletions src/components/common/Drawer/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
clearSemester,
clearStudentName,
} from 'src/redux/slices/filter';
import { setOpen, setPinned } from 'src/redux/slices/drawer';

const drawerWidth = 240;

Expand Down Expand Up @@ -94,14 +95,30 @@ export default function MiniDrawer() {
dispatch(clearDepartment());
};
const theme = useTheme();
const [open, setOpen] = React.useState(false);

const pinned = useSelector((state) => state.drawer.pinned);
const open = useSelector((state) => state.drawer.open);
const drawerPinnedOff = () => dispatch(setPinned(false));
const drawerPinnedOn = () => dispatch(setPinned(true));
const drawerOpen = () => dispatch(setOpen(true));
const drawerClose = () => dispatch(setOpen(false));

const handleDrawerOpen = () => {
setOpen(true);
drawerOpen();
};

const handleDrawerClose = () => {
setOpen(false);
if (!pinned) drawerClose();
};

const handleDrawerPinOn = () => {
handleDrawerOpen();
drawerPinnedOn();
};

const handleDrawerPinOff = () => {
handleDrawerClose();
drawerPinnedOff();
};

const linkConverter = (num) => {
Expand Down Expand Up @@ -135,11 +152,11 @@ export default function MiniDrawer() {
<Box sx={{ display: 'flex' }}>
<CssBaseline />
{/* 메뉴 아이콘과 제목을 가지고 있는 헤더 */}
<MileageHeader open={open} handleDrawerOpen={handleDrawerOpen} />
<MileageHeader open={open} handleDrawerOpen={handleDrawerPinOn} />
{/* 사이드바 */}
<Drawer variant="permanent" open={open}>
<DrawerHeader>
<IconButton onClick={handleDrawerClose}>
<IconButton onClick={handleDrawerPinOff}>
{theme.direction === 'rtl' ? <ChevronRightIcon /> : <ChevronLeftIcon />}
</IconButton>
</DrawerHeader>
Expand Down
35 changes: 18 additions & 17 deletions src/layouts/main/MainLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Header from 'src/components/common/Header';
// @mui
import { Box } from '@mui/material';
import ExcelExport from 'src/components/excel/ExcelExport';
import { useSelector } from 'react-redux';
//

// const Header = dynamic(() => import('./Header'), { ssr: false });
Expand All @@ -19,25 +20,25 @@ MainLayout.propTypes = {
};

export default function MainLayout({ children }) {
// const { pathname } = useRouter();

// const isHome = pathname === '/';

return (
<Box sx={{}}>
<Box>
<Header />
<MiniDrawer />

<Box
component="main"
sx={{
pl: '100px',
mr: '40px',
}}
>
{children}

<ExcelExport />

<Box sx={{ display: 'flex', width: '100%' }}>
<MiniDrawer />

<Box
component="main"
sx={{
pt: '50px',
pr: '50px',
width: '100%',
}}
>
{children}

<ExcelExport />
</Box>
</Box>

{/* <Footer /> */}
Expand Down
4 changes: 3 additions & 1 deletion src/redux/rootReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import dataReducer from './slices/data';
import componentReducer from './slices/component';
import filterListReducer from './slices/filterList';
import chartReducer from './slices/chart';
import drawerReducer from './slices/drawer';

// ----------------------------------------------------------------------

Expand All @@ -38,7 +39,7 @@ export const rootPersistConfig = {
key: 'root',
storage,
keyPrefix: 'redux-',
blacklist: ['filter', 'modal', 'data'],
blacklist: ['filter', 'modal', 'data', 'drawer'],
whitelist: ['component', 'filterList'],
};

Expand All @@ -56,6 +57,7 @@ const rootReducer = combineReducers({
component: componentReducer,
filterList: filterListReducer,
chart: chartReducer,
drawer: drawerReducer,
});

export default rootReducer;
23 changes: 23 additions & 0 deletions src/redux/slices/drawer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { createSlice } from '@reduxjs/toolkit';

const initialState = {
pinned: false,
open: false,
};

const slice = createSlice({
name: 'drawer',
initialState,
reducers: {
setPinned: (state, action) => {
state.pinned = action.payload;
},
setOpen: (state, action) => {
state.open = action.payload;
},
},
});

// Reducer
export const { setPinned, setOpen } = slice.actions;
export default slice.reducer;

0 comments on commit bc6d114

Please sign in to comment.