mirror of
https://github.com/RoboSats/robosats.git
synced 2025-01-19 04:31:35 +00:00
NavBar update
This commit is contained in:
parent
886956c5a9
commit
bbe0ffa682
@ -1,44 +1,55 @@
|
|||||||
import React, { useContext, useEffect } from 'react';
|
import React, { useContext, useEffect } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useLocation, useNavigate } from 'react-router-dom';
|
import { useLocation, useNavigate } from 'react-router-dom';
|
||||||
import { Tabs, Tab, Paper, useTheme } from '@mui/material';
|
|
||||||
import MoreTooltip from './MoreTooltip';
|
|
||||||
|
|
||||||
import { type Page, isPage } from '.';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
SettingsApplications,
|
BottomNavigation,
|
||||||
SmartToy,
|
BottomNavigationAction,
|
||||||
Storefront,
|
Paper,
|
||||||
AddBox,
|
styled,
|
||||||
Assignment,
|
useTheme,
|
||||||
MoreHoriz,
|
useMediaQuery,
|
||||||
} from '@mui/icons-material';
|
} from '@mui/material';
|
||||||
import RobotAvatar from '../../components/RobotAvatar';
|
import SmartToyOutlinedIcon from '@mui/icons-material/SmartToyOutlined';
|
||||||
|
import StorefrontOutlinedIcon from '@mui/icons-material/StorefrontOutlined';
|
||||||
|
import AddBoxOutlinedIcon from '@mui/icons-material/AddBoxOutlined';
|
||||||
|
import AssignmentOutlinedIcon from '@mui/icons-material/AssignmentOutlined';
|
||||||
|
import SettingsOutlinedIcon from '@mui/icons-material/SettingsOutlined';
|
||||||
|
|
||||||
import { AppContext, type UseAppStoreType, closeAll } from '../../contexts/AppContext';
|
import { AppContext, type UseAppStoreType, closeAll } from '../../contexts/AppContext';
|
||||||
import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageContext';
|
import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageContext';
|
||||||
import { FederationContext, type UseFederationStoreType } from '../../contexts/FederationContext';
|
import { FederationContext, type UseFederationStoreType } from '../../contexts/FederationContext';
|
||||||
|
import { type Page, isPage } from '.';
|
||||||
|
|
||||||
|
const StyledBottomNavigation = styled(BottomNavigation)(({ theme }) => ({
|
||||||
|
width: '100%',
|
||||||
|
maxWidth: '100%',
|
||||||
|
padding: theme.spacing(0.5, 0),
|
||||||
|
borderRadius: 'inherit',
|
||||||
|
}));
|
||||||
|
|
||||||
|
const StyledBottomNavigationAction = styled(BottomNavigationAction)(({ theme }) => ({
|
||||||
|
minWidth: 'auto',
|
||||||
|
padding: theme.spacing(0.5, 0),
|
||||||
|
'& .MuiBottomNavigationAction-label': {
|
||||||
|
fontSize: '0.75rem',
|
||||||
|
},
|
||||||
|
'& .MuiSvgIcon-root': {
|
||||||
|
fontSize: '1.5rem',
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
const NavBar = (): JSX.Element => {
|
const NavBar = (): JSX.Element => {
|
||||||
const theme = useTheme();
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { page, setPage, settings, setSlideDirection, open, setOpen, windowSize, navbarHeight } =
|
const theme = useTheme();
|
||||||
|
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
|
||||||
|
const { page, setPage, setSlideDirection, open, setOpen } =
|
||||||
useContext<UseAppStoreType>(AppContext);
|
useContext<UseAppStoreType>(AppContext);
|
||||||
const { garage, robotUpdatedAt } = useContext<UseGarageStoreType>(GarageContext);
|
const { garage } = useContext<UseGarageStoreType>(GarageContext);
|
||||||
const { setCurrentOrderId } = useContext<UseFederationStoreType>(FederationContext);
|
const { setCurrentOrderId } = useContext<UseFederationStoreType>(FederationContext);
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const smallBar = windowSize?.width < 50;
|
const [value, setValue] = React.useState(page);
|
||||||
const color = settings.network === 'mainnet' ? 'primary' : 'secondary';
|
|
||||||
|
|
||||||
const tabSx = smallBar
|
|
||||||
? {
|
|
||||||
position: 'relative',
|
|
||||||
bottom: garage.getSlot()?.hashId ? '0.9em' : '0.13em',
|
|
||||||
minWidth: '1em',
|
|
||||||
}
|
|
||||||
: { position: 'relative', bottom: '1em', minWidth: '2em' };
|
|
||||||
|
|
||||||
const pagesPosition = {
|
const pagesPosition = {
|
||||||
robot: 1,
|
robot: 1,
|
||||||
@ -49,11 +60,6 @@ const NavBar = (): JSX.Element => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// re-render on orde rand robot updated at for latest orderId in tab
|
|
||||||
}, [robotUpdatedAt]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
// change tab (page) into the current route
|
|
||||||
const pathPage: Page | string = location.pathname.split('/')[1];
|
const pathPage: Page | string = location.pathname.split('/')[1];
|
||||||
if (pathPage === 'index.html') {
|
if (pathPage === 'index.html') {
|
||||||
navigate('/robot');
|
navigate('/robot');
|
||||||
@ -62,9 +68,10 @@ const NavBar = (): JSX.Element => {
|
|||||||
if (isPage(pathPage)) {
|
if (isPage(pathPage)) {
|
||||||
setPage(pathPage);
|
setPage(pathPage);
|
||||||
}
|
}
|
||||||
}, [location]);
|
setValue(pathPage as Page);
|
||||||
|
}, [location, navigate, setPage]);
|
||||||
|
|
||||||
const handleSlideDirection = function (oldPage: Page, newPage: Page): void {
|
const handleSlideDirection = (oldPage: Page, newPage: Page): void => {
|
||||||
const oldPos: number = pagesPosition[oldPage];
|
const oldPos: number = pagesPosition[oldPage];
|
||||||
const newPos: number = pagesPosition[newPage];
|
const newPos: number = pagesPosition[newPage];
|
||||||
setSlideDirection(
|
setSlideDirection(
|
||||||
@ -72,7 +79,7 @@ const NavBar = (): JSX.Element => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const changePage = function (mouseEvent: any, newPage: Page): void {
|
const changePage = (event: React.SyntheticEvent, newPage: Page): void => {
|
||||||
if (newPage !== 'none') {
|
if (newPage !== 'none') {
|
||||||
const slot = garage.getSlot();
|
const slot = garage.getSlot();
|
||||||
handleSlideDirection(page, newPage);
|
handleSlideDirection(page, newPage);
|
||||||
@ -95,102 +102,64 @@ const NavBar = (): JSX.Element => {
|
|||||||
setOpen(closeAll);
|
setOpen(closeAll);
|
||||||
}, [page, setOpen]);
|
}, [page, setOpen]);
|
||||||
|
|
||||||
const slot = garage.getSlot();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Paper
|
<Paper
|
||||||
elevation={6}
|
|
||||||
sx={{
|
sx={{
|
||||||
height: `${navbarHeight}em`,
|
|
||||||
width: `100%`,
|
|
||||||
position: 'fixed',
|
position: 'fixed',
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
borderRadius: 0,
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
zIndex: 1000,
|
||||||
|
...(isMobile
|
||||||
|
? {
|
||||||
|
boxShadow: 'none',
|
||||||
|
backgroundColor: theme.palette.background.paper,
|
||||||
|
borderTop: `2px solid black`,
|
||||||
|
borderRadius: '0',
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
bottom: theme.spacing(2),
|
||||||
|
left: '50%',
|
||||||
|
transform: 'translateX(-50%)',
|
||||||
|
width: '95%',
|
||||||
|
maxWidth: 600,
|
||||||
|
borderRadius: '8px',
|
||||||
|
boxShadow: '8px 8px 0px 0px rgba(0,0,0,1)',
|
||||||
|
border: `2px solid black`,
|
||||||
|
backgroundColor: theme.palette.background.paper,
|
||||||
|
overflow: 'hidden',
|
||||||
|
}),
|
||||||
}}
|
}}
|
||||||
|
elevation={isMobile ? 0 : 3}
|
||||||
>
|
>
|
||||||
<Tabs
|
<StyledBottomNavigation value={value} onChange={changePage} showLabels>
|
||||||
TabIndicatorProps={{ sx: { height: '0.3em', position: 'absolute', top: 0 } }}
|
<StyledBottomNavigationAction
|
||||||
variant='fullWidth'
|
label={t('Robot')}
|
||||||
value={page}
|
|
||||||
indicatorColor={color}
|
|
||||||
textColor={color}
|
|
||||||
onChange={changePage}
|
|
||||||
>
|
|
||||||
<Tab
|
|
||||||
sx={{ ...tabSx, minWidth: '2.5em', width: '2.5em', maxWidth: '4em' }}
|
|
||||||
value='none'
|
|
||||||
disabled={slot?.nickname === null}
|
|
||||||
onClick={() => {
|
|
||||||
setOpen({ ...closeAll, profile: !open.profile });
|
|
||||||
}}
|
|
||||||
icon={
|
|
||||||
slot?.hashId ? (
|
|
||||||
<RobotAvatar
|
|
||||||
style={{ width: '2.3em', height: '2.3em', position: 'relative', top: '0.2em' }}
|
|
||||||
avatarClass={theme.palette.mode === 'dark' ? 'navBarAvatarDark' : 'navBarAvatar'}
|
|
||||||
hashId={slot?.hashId}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<></>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Tab
|
|
||||||
label={smallBar ? undefined : t('Robot')}
|
|
||||||
sx={{ ...tabSx, minWidth: '1em' }}
|
|
||||||
value='robot'
|
value='robot'
|
||||||
icon={<SmartToy />}
|
icon={<SmartToyOutlinedIcon />}
|
||||||
iconPosition='start'
|
|
||||||
/>
|
/>
|
||||||
|
<StyledBottomNavigationAction
|
||||||
<Tab
|
label={t('Offers')}
|
||||||
sx={tabSx}
|
|
||||||
label={smallBar ? undefined : t('Offers')}
|
|
||||||
value='offers'
|
value='offers'
|
||||||
icon={<Storefront />}
|
icon={<StorefrontOutlinedIcon />}
|
||||||
iconPosition='start'
|
|
||||||
/>
|
/>
|
||||||
<Tab
|
<StyledBottomNavigationAction
|
||||||
sx={tabSx}
|
label={t('Create')}
|
||||||
label={smallBar ? undefined : t('Create')}
|
|
||||||
value='create'
|
value='create'
|
||||||
icon={<AddBox />}
|
icon={<AddBoxOutlinedIcon />}
|
||||||
iconPosition='start'
|
|
||||||
/>
|
/>
|
||||||
<Tab
|
<StyledBottomNavigationAction
|
||||||
sx={tabSx}
|
label={t('Orders')}
|
||||||
label={smallBar ? undefined : t('Order')}
|
|
||||||
value='order'
|
value='order'
|
||||||
disabled={!slot?.getRobot()?.activeOrderId}
|
icon={<AssignmentOutlinedIcon />}
|
||||||
icon={<Assignment />}
|
disabled={!garage.getSlot()?.getRobot()?.activeOrderId}
|
||||||
iconPosition='start'
|
|
||||||
/>
|
/>
|
||||||
<Tab
|
<StyledBottomNavigationAction
|
||||||
sx={tabSx}
|
label={t('Settings')}
|
||||||
label={smallBar ? undefined : t('Settings')}
|
|
||||||
value='settings'
|
value='settings'
|
||||||
icon={<SettingsApplications />}
|
icon={<SettingsOutlinedIcon />}
|
||||||
iconPosition='start'
|
|
||||||
/>
|
/>
|
||||||
|
</StyledBottomNavigation>
|
||||||
<Tab
|
|
||||||
sx={tabSx}
|
|
||||||
label={smallBar ? undefined : t('More')}
|
|
||||||
value='none'
|
|
||||||
onClick={() => {
|
|
||||||
setOpen((open) => {
|
|
||||||
return { ...open, more: !open.more };
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
icon={
|
|
||||||
<MoreTooltip>
|
|
||||||
<MoreHoriz />
|
|
||||||
</MoreTooltip>
|
|
||||||
}
|
|
||||||
iconPosition='start'
|
|
||||||
/>
|
|
||||||
</Tabs>
|
|
||||||
</Paper>
|
</Paper>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user