bbgo_origin/frontend/pages/_app.tsx

86 lines
2.9 KiB
TypeScript
Raw Normal View History

2021-01-24 06:32:52 +00:00
import React from 'react';
import PropTypes from 'prop-types';
import Head from 'next/head';
2021-01-24 10:12:26 +00:00
2021-02-01 09:13:27 +00:00
import {ThemeProvider} from '@material-ui/core/styles';
2021-01-24 06:32:52 +00:00
2021-02-21 10:08:22 +00:00
import Dialog from '@material-ui/core/Dialog';
import DialogContent from '@material-ui/core/DialogContent';
import DialogContentText from '@material-ui/core/DialogContentText';
import DialogTitle from '@material-ui/core/DialogTitle';
2021-01-24 10:12:26 +00:00
import CssBaseline from '@material-ui/core/CssBaseline';
2021-01-24 06:32:52 +00:00
import theme from '../src/theme';
2021-01-24 06:07:44 +00:00
import '../styles/globals.css'
2021-02-21 10:08:22 +00:00
import {querySyncStatus} from "../api/bbgo";
2021-01-24 06:07:44 +00:00
2021-01-24 06:32:52 +00:00
export default function MyApp(props) {
2021-01-24 10:12:26 +00:00
const {Component, pageProps} = props;
2021-02-21 10:08:22 +00:00
const [syncing, setSyncing] = React.useState(true)
2021-01-24 10:12:26 +00:00
React.useEffect(() => {
// Remove the server-side injected CSS.
const jssStyles = document.querySelector('#jss-server-side');
if (jssStyles) {
jssStyles.parentElement.removeChild(jssStyles);
}
2021-02-21 10:08:22 +00:00
let poller = null
const pollSyncStatus = () => {
querySyncStatus((status) => {
setSyncing(status)
if (!status) {
clearInterval(poller)
}
}).catch((err) => {
console.error(err)
})
}
poller = setInterval(pollSyncStatus, 1000)
2021-01-24 10:12:26 +00:00
}, []);
2021-02-21 10:08:22 +00:00
const handleClose = (e) => {}
2021-01-24 10:12:26 +00:00
return (
<React.Fragment>
<Head>
<title>BBGO</title>
<meta name="viewport" content="minimum-scale=1, initial-scale=1, width=device-width"/>
</Head>
<ThemeProvider theme={theme}>
{/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}
<CssBaseline/>
2021-02-21 10:08:22 +00:00
{
syncing ? (
<React.Fragment>
<Dialog
open={syncing}
aria-labelledby="alert-dialog-title"
aria-describedby="alert-dialog-description"
>
<DialogTitle id="alert-dialog-title">{"Syncing Trades"}</DialogTitle>
<DialogContent>
<DialogContentText id="alert-dialog-description">
The environment is syncing trades from the exchange sessions.
Please wait a moment...
</DialogContentText>
</DialogContent>
</Dialog>
</React.Fragment>
) : (
<Component {...pageProps}/>
)
}
2021-01-24 10:12:26 +00:00
</ThemeProvider>
</React.Fragment>
);
2021-01-24 06:07:44 +00:00
}
2021-01-24 06:32:52 +00:00
MyApp.propTypes = {
2021-01-24 10:12:26 +00:00
Component: PropTypes.elementType.isRequired,
pageProps: PropTypes.object.isRequired,
2021-01-24 06:32:52 +00:00
};