ボトムナビゲーションの修正

feature-frontend-top
Haru.Kusano 4 months ago
parent d06f289193
commit 753d1ae9b2
  1. 38
      frontend/src/components/Layout.tsx

@ -2,7 +2,7 @@
* *
* AppBar * AppBar
*/ */
import React, { useState } from 'react'; import React, { useEffect, useState } from 'react';
import { import {
AppBar, AppBar,
Toolbar, Toolbar,
@ -35,7 +35,30 @@ const Layout: React.FC = () => {
const navigate = useNavigate(); const navigate = useNavigate();
const location = useLocation(); const location = useLocation();
const [drawerOpen, setDrawerOpen] = useState(false); const [drawerOpen, setDrawerOpen] = useState(false);
const [bottomNavi, setBottomNavi] = useState(1);
const getTabIndex = (pathname: string) => {
switch (pathname) {
case '/stock':
return 0;
case '/tasks':
return 1;
case '/recipeList':
return 2;
default:
return 0;
}
};
const [bottomNavi, setBottomNavi] = useState(getTabIndex(location.pathname));
useEffect(() => {
setBottomNavi(getTabIndex(location.pathname));
}, [location.pathname]);
/** /**
* *
@ -55,6 +78,8 @@ const Layout: React.FC = () => {
setDrawerOpen(!drawerOpen); setDrawerOpen(!drawerOpen);
}; };
return ( return (
<Box sx={{ display: 'flex', flexDirection: 'column', minHeight: '100vh' }}> <Box sx={{ display: 'flex', flexDirection: 'column', minHeight: '100vh' }}>
{/* ヘッダー部分 - アプリ名とログアウトボタンを表示 */} {/* ヘッダー部分 - アプリ名とログアウトボタンを表示 */}
@ -73,13 +98,13 @@ const Layout: React.FC = () => {
<Paper sx={{ position: 'fixed', bottom: 0, left: 0, right: 0 }} elevation={3}> <Paper sx={{ position: 'fixed', bottom: 0, left: 0, right: 0, zIndex: (theme) => theme.zIndex.drawer + 1 }} elevation={3}>
<BottomNavigation <BottomNavigation
showLabels showLabels
value={bottomNavi} value={bottomNavi}
onChange={(event, newValue) => { onChange={(event, newValue) => {
setBottomNavi(newValue); setBottomNavi(newValue);
switch(newValue) { switch (newValue) {
case 0: case 0:
navigate('stock'); navigate('stock');
break; break;
@ -108,6 +133,7 @@ const Layout: React.FC = () => {
</Box> </Box>
</Box> </Box>
); );
}; };
export default Layout; export default Layout;
Loading…
Cancel
Save