2023-02-24 19:17:13 +00:00
|
|
|
import React, { useEffect, useContext, useState } from 'react';
|
2022-10-22 14:32:33 +00:00
|
|
|
import GridLayout, { Layout } from 'react-grid-layout';
|
2022-10-25 08:37:25 +00:00
|
|
|
import { Grid, styled, useTheme } from '@mui/material';
|
2022-10-20 18:06:16 +00:00
|
|
|
|
2022-10-30 19:13:01 +00:00
|
|
|
import {
|
|
|
|
PlaceholderWidget,
|
|
|
|
MakerWidget,
|
|
|
|
BookWidget,
|
|
|
|
DepthChartWidget,
|
|
|
|
SettingsWidget,
|
|
|
|
} from '../pro/Widgets';
|
2022-10-22 14:32:33 +00:00
|
|
|
import ToolBar from '../pro/ToolBar';
|
|
|
|
import LandingDialog from '../pro/LandingDialog';
|
|
|
|
|
2023-04-20 14:52:03 +00:00
|
|
|
import { AppContext, UseAppStoreType } from '../contexts/AppContext';
|
2022-10-22 14:32:33 +00:00
|
|
|
|
2022-10-25 08:37:25 +00:00
|
|
|
// To Do. Add dotted grid when layout is not frozen
|
|
|
|
// ${freeze ?
|
|
|
|
// `background: radial-gradient(${theme.palette.text.disabled} 1px, transparent 0px);
|
|
|
|
// background-size: ${gridCellSize}em ${gridCellSize}em;
|
|
|
|
// background-position: left 1em bottom 1.5em;`
|
|
|
|
// :''}
|
|
|
|
|
|
|
|
const StyledRGL = styled(GridLayout)(
|
|
|
|
({ theme, gridCellSize, height, width, freeze }) => `
|
|
|
|
height: ${height}em;
|
|
|
|
width: ${width}px;
|
|
|
|
max-height: ${height}em;
|
|
|
|
`,
|
|
|
|
);
|
|
|
|
|
2023-02-24 19:17:13 +00:00
|
|
|
const defaultLayout: Layout = [
|
|
|
|
{ i: 'Maker', w: 10, h: 16, x: 67, y: 0, minW: 8, maxW: 22, minH: 10, maxH: 28 },
|
|
|
|
{ i: 'Book', w: 43, h: 15, x: 34, y: 16, minW: 6, maxW: 70, minH: 9, maxH: 25 },
|
|
|
|
{ i: 'DepthChart', w: 15, h: 10, x: 19, y: 16, minW: 6, maxW: 22, minH: 9, maxH: 25 },
|
|
|
|
{ i: 'Garage', w: 52, h: 16, x: 0, y: 0, minW: 15, maxW: 78, minH: 8, maxH: 30 },
|
|
|
|
{ i: 'History', w: 8, h: 10, x: 11, y: 16, minW: 6, maxW: 22, minH: 9, maxH: 25 },
|
|
|
|
{ i: 'Trade', w: 15, h: 16, x: 52, y: 0, minW: 6, maxW: 22, minH: 9, maxH: 25 },
|
|
|
|
{ i: 'Settings', w: 11, h: 15, x: 0, y: 16, minW: 6, maxW: 22, minH: 9, maxH: 25 },
|
|
|
|
{ i: 'Other', w: 23, h: 5, x: 11, y: 26, minW: 2, maxW: 50, minH: 4, maxH: 25 },
|
|
|
|
];
|
|
|
|
|
|
|
|
const Main = (): JSX.Element => {
|
|
|
|
const {
|
|
|
|
book,
|
|
|
|
fetchBook,
|
|
|
|
maker,
|
|
|
|
setMaker,
|
|
|
|
setSettings,
|
|
|
|
clearOrder,
|
|
|
|
torStatus,
|
|
|
|
settings,
|
|
|
|
limits,
|
|
|
|
fetchLimits,
|
|
|
|
robot,
|
|
|
|
setRobot,
|
|
|
|
fetchRobot,
|
|
|
|
setOrder,
|
|
|
|
setDelay,
|
|
|
|
info,
|
|
|
|
fav,
|
|
|
|
setFav,
|
|
|
|
baseUrl,
|
|
|
|
order,
|
|
|
|
currentOrder,
|
|
|
|
setCurrentOrder,
|
|
|
|
open,
|
|
|
|
setOpen,
|
|
|
|
windowSize,
|
|
|
|
badOrder,
|
|
|
|
setBadOrder,
|
2023-04-20 14:52:03 +00:00
|
|
|
} = useContext<UseAppStoreType>(AppContext);
|
2023-02-24 19:17:13 +00:00
|
|
|
|
2022-10-22 14:32:33 +00:00
|
|
|
const theme = useTheme();
|
2022-10-25 08:37:25 +00:00
|
|
|
const em: number = theme.typography.fontSize;
|
|
|
|
const toolbarHeight: number = 3;
|
|
|
|
const gridCellSize: number = 2;
|
2022-10-22 14:32:33 +00:00
|
|
|
|
|
|
|
const [openLanding, setOpenLanding] = useState<boolean>(true);
|
2023-02-24 19:17:13 +00:00
|
|
|
const [layout, setLayout] = useState<Layout>(defaultLayout);
|
2022-10-25 08:37:25 +00:00
|
|
|
|
2022-10-22 14:32:33 +00:00
|
|
|
return (
|
2022-10-23 18:29:39 +00:00
|
|
|
<Grid container direction='column' sx={{ width: `${windowSize.width}em` }}>
|
2022-10-22 14:32:33 +00:00
|
|
|
<Grid item>
|
2022-10-23 18:29:39 +00:00
|
|
|
<ToolBar height={`${toolbarHeight}em`} settings={settings} setSettings={setSettings} />
|
2022-10-22 14:32:33 +00:00
|
|
|
<LandingDialog open={openLanding} onClose={() => setOpenLanding(!openLanding)} />
|
|
|
|
</Grid>
|
|
|
|
|
2022-10-23 18:29:39 +00:00
|
|
|
<Grid item>
|
2022-10-25 08:37:25 +00:00
|
|
|
<StyledRGL
|
|
|
|
height={windowSize.height - toolbarHeight}
|
|
|
|
width={Number((windowSize.width / gridCellSize).toFixed()) * gridCellSize * em}
|
|
|
|
theme={theme}
|
|
|
|
freeze={!settings.freezeViewports}
|
|
|
|
gridCellSize={gridCellSize}
|
2022-10-22 14:32:33 +00:00
|
|
|
className='layout'
|
|
|
|
layout={layout}
|
2022-10-25 08:37:25 +00:00
|
|
|
cols={Number((windowSize.width / gridCellSize).toFixed())} // cols are 2em wide
|
2022-10-23 18:29:39 +00:00
|
|
|
margin={[0.5 * em, 0.5 * em]}
|
2022-10-22 14:32:33 +00:00
|
|
|
isDraggable={!settings.freezeViewports}
|
|
|
|
isResizable={!settings.freezeViewports}
|
2022-10-25 08:37:25 +00:00
|
|
|
rowHeight={gridCellSize * em} // rows are 2em high
|
2022-10-22 14:32:33 +00:00
|
|
|
autoSize={true}
|
|
|
|
onLayoutChange={(layout: Layout) => setLayout(layout)}
|
|
|
|
>
|
2022-10-23 18:29:39 +00:00
|
|
|
<div key='Maker'>
|
2023-02-24 19:17:13 +00:00
|
|
|
<MakerWidget />
|
2022-10-22 14:32:33 +00:00
|
|
|
</div>
|
2022-10-23 18:29:39 +00:00
|
|
|
<div key='Book'>
|
2023-02-24 19:17:13 +00:00
|
|
|
<BookWidget layout={layout[1]} gridCellSize={gridCellSize} />
|
2022-10-22 14:32:33 +00:00
|
|
|
</div>
|
2022-10-23 18:29:39 +00:00
|
|
|
<div key='DepthChart'>
|
2023-02-24 19:17:13 +00:00
|
|
|
<DepthChartWidget gridCellSize={gridCellSize} layout={layout[2]} />
|
2022-10-23 18:29:39 +00:00
|
|
|
</div>
|
2022-10-30 19:13:01 +00:00
|
|
|
<div key='Settings'>
|
2023-02-24 19:17:13 +00:00
|
|
|
<SettingsWidget />
|
2022-10-30 19:13:01 +00:00
|
|
|
</div>
|
2022-10-25 08:37:25 +00:00
|
|
|
<div key='Garage'>
|
2022-10-23 18:29:39 +00:00
|
|
|
<PlaceholderWidget label='Robot Garage' />
|
|
|
|
</div>
|
2022-10-25 08:37:25 +00:00
|
|
|
<div key='History'>
|
2022-10-23 18:29:39 +00:00
|
|
|
<PlaceholderWidget label='Garage History' />
|
|
|
|
</div>
|
2022-10-25 08:37:25 +00:00
|
|
|
<div key='Trade'>
|
2022-10-23 18:29:39 +00:00
|
|
|
<PlaceholderWidget label='Trade Box' />
|
|
|
|
</div>
|
2022-10-25 08:37:25 +00:00
|
|
|
<div key='Other'>
|
2022-10-23 18:29:39 +00:00
|
|
|
<PlaceholderWidget label='Other' />
|
|
|
|
</div>
|
2022-10-25 08:37:25 +00:00
|
|
|
</StyledRGL>
|
2022-10-22 14:32:33 +00:00
|
|
|
</Grid>
|
|
|
|
</Grid>
|
|
|
|
);
|
2022-10-20 18:06:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Main;
|