import React, { useEffect, useRef, useState } from 'react'; import GridLayout, { Layout } from 'react-grid-layout'; import { Grid, useTheme } from '@mui/material'; import { apiClient } from '../services/api'; import { Book, LimitList, Maker, Robot, Info, Settings, Favorites, defaultMaker, defaultRobot, defaultInfo, } from '../models'; import { PlaceholderWidget, MakerWidget, BookWidget } from '../pro/Widgets'; import ToolBar from '../pro/ToolBar'; import LandingDialog from '../pro/LandingDialog'; const getWindowSize = function (fontSize: number) { // returns window size in EM units return { width: window.innerWidth / fontSize, height: window.innerHeight / fontSize, }; }; interface MainProps { settings: Settings; setSettings: (state: Settings) => void; } const Main = ({ settings, setSettings }: MainProps): JSX.Element => { const theme = useTheme(); const defaultLayout: Layout = [ { i: 'MakerWidget', w: 6, h: 13, x: 42, y: 0, minW: 6, maxW: 12, minH: 9, maxH: 18 }, { i: 'BookWidget', w: 27, h: 13, x: 21, y: 13, minW: 6, maxW: 40, minH: 9, maxH: 15 }, { i: 'robots', w: 33, h: 13, x: 0, y: 0, minW: 15, maxW: 48, minH: 8, maxH: 20 }, { i: 'history', w: 7, h: 9, x: 6, y: 13, minW: 6, maxW: 12, minH: 9, maxH: 15 }, { i: 'trade', w: 9, h: 13, x: 33, y: 0, minW: 6, maxW: 12, minH: 9, maxH: 15 }, { i: 'depth', w: 8, h: 9, x: 13, y: 13, minW: 6, maxW: 12, minH: 9, maxH: 15 }, { i: 'settings', w: 6, h: 13, x: 0, y: 13, minW: 6, maxW: 12, minH: 9, maxH: 15 }, { i: 'other', w: 15, h: 4, x: 6, y: 22, minW: 2, maxW: 30, minH: 4, maxH: 15 }, ]; // All app data structured const [book, setBook] = useState({ orders: [], loading: true }); const [limits, setLimits] = useState<{ list: LimitList; loading: boolean }>({ list: [], loading: true, }); const [robot, setRobot] = useState(defaultRobot); const [maker, setMaker] = useState(defaultMaker); const [info, setInfo] = useState(defaultInfo); const [fav, setFav] = useState({ type: null, currency: 0 }); const [layout, setLayout] = useState(defaultLayout); const [openLanding, setOpenLanding] = useState(true); const [windowSize, setWindowSize] = useState<{ width: number; height: number }>( getWindowSize(theme.typography.fontSize), ); useEffect(() => { if (typeof window !== undefined) { window.addEventListener('resize', onResize); } fetchLimits(); fetchBook(); return () => { if (typeof window !== undefined) { window.removeEventListener('resize', onResize); } }; }, []); const onResize = function () { setWindowSize(getWindowSize(theme.typography.fontSize)); }; const fetchLimits = async () => { setLimits({ ...limits, loading: true }); const data = apiClient.get('/api/limits/').then((data) => { setLimits({ list: data ?? [], loading: false }); return data; }); return await data; }; const fetchBook = function () { setBook({ ...book, loading: true }); apiClient.get('/api/book/').then((data: any) => setBook({ loading: false, orders: data.not_found ? [] : data, }), ); }; const bookRef = useRef(null); console.log(bookRef); return ( setOpenLanding(!openLanding)} /> setLayout(layout)} >
Robot Table Workspace History Trade Box (for selected order in Robot Table) Depth Chart Settings Other
); }; export default Main;