bbgo_origin/frontend/pages/index.tsx

98 lines
2.6 KiB
TypeScript
Raw Normal View History

import React, {useState} from 'react';
import { useRouter } from 'next/router';
2021-01-24 10:12:26 +00:00
2021-01-25 08:56:02 +00:00
import {makeStyles} from '@material-ui/core/styles';
2021-01-24 06:32:52 +00:00
import Typography from '@material-ui/core/Typography';
import Box from '@material-ui/core/Box';
2021-01-24 10:12:26 +00:00
import Grid from '@material-ui/core/Grid';
import Paper from '@material-ui/core/Paper';
2021-01-24 06:32:52 +00:00
2021-01-25 10:29:31 +00:00
import TotalAssetsPie from '../components/TotalAssetsPie';
import TotalAssetSummary from '../components/TotalAssetsSummary';
2021-01-28 10:51:35 +00:00
import TradingVolumePanel from '../components/TradingVolumePanel';
2021-01-25 10:29:31 +00:00
import ExchangeSessionTabPanel from '../components/ExchangeSessionTabPanel';
2021-01-24 06:07:44 +00:00
2021-02-01 09:13:27 +00:00
import DashboardLayout from '../layouts/DashboardLayout';
import {querySessions} from "../api/bbgo";
2021-01-24 10:12:26 +00:00
const useStyles = makeStyles((theme) => ({
2021-01-25 08:56:02 +00:00
paper: {
height: 140,
width: 200,
},
2021-01-25 10:29:31 +00:00
totalAssetsBox: {
2021-01-25 08:56:02 +00:00
height: 300,
},
2021-01-29 04:55:11 +00:00
totalAssetsSummary: {
padding: theme.spacing(2),
2021-01-26 10:10:08 +00:00
},
2021-01-25 08:56:02 +00:00
control: {
padding: theme.spacing(2),
},
2021-01-24 10:12:26 +00:00
}));
2021-02-01 09:13:27 +00:00
// props are pageProps passed from _app.tsx
export default function Home() {
2021-01-25 08:56:02 +00:00
const classes = useStyles();
const { push } = useRouter();
const [sessions, setSessions] = React.useState([])
React.useEffect(() => {
querySessions((sessions) => {
if (sessions.length == 0) {
push("/setup");
} else {
setSessions(sessions)
}
}).catch((err) => {
console.error(err);
})
}, [])
if (sessions.length == 0) {
return (
<DashboardLayout>
<Box m={4}>
<Typography variant="h4" component="h2" gutterBottom>
Loading
</Typography>
</Box>
</DashboardLayout>
);
}
2021-01-25 08:56:02 +00:00
2021-01-25 10:29:31 +00:00
return (
2021-02-01 09:13:27 +00:00
<DashboardLayout>
2021-01-29 04:55:11 +00:00
<Box m={4}>
<Paper className={classes.totalAssetsSummary}>
2021-01-25 10:29:31 +00:00
<Typography variant="h4" component="h2" gutterBottom>
Total Assets
</Typography>
<Grid container spacing={3}>
<Grid item xs={12} md={6}>
<TotalAssetSummary/>
</Grid>
2021-01-25 08:56:02 +00:00
2021-01-25 10:29:31 +00:00
<Grid item xs={12} md={6}>
<Box className={classes.totalAssetsBox}>
<TotalAssetsPie/>
</Box>
2021-01-25 08:56:02 +00:00
</Grid>
</Grid>
2021-01-29 04:55:11 +00:00
</Paper>
2021-01-25 08:56:02 +00:00
2021-01-29 04:55:11 +00:00
<TradingVolumePanel/>
2021-01-26 10:10:08 +00:00
2021-01-29 04:55:11 +00:00
<ExchangeSessionTabPanel/>
</Box>
2021-02-01 09:13:27 +00:00
</DashboardLayout>
2021-01-25 08:56:02 +00:00
);
2021-01-24 06:07:44 +00:00
}
2021-01-24 06:32:52 +00:00