refactor: move the router and layout directly to app.tsx (#188)
This commit is contained in:
+5
-2
@@ -7,6 +7,7 @@ import CssBaseline from '@material-ui/core/CssBaseline'
|
|||||||
import { SnackbarProvider } from 'notistack'
|
import { SnackbarProvider } from 'notistack'
|
||||||
|
|
||||||
import BaseRouter from './routes/routes'
|
import BaseRouter from './routes/routes'
|
||||||
|
import Dashboard from './layout/Dashboard'
|
||||||
import { lightTheme, darkTheme } from './theme'
|
import { lightTheme, darkTheme } from './theme'
|
||||||
import { Provider as StampsProvider } from './providers/Stamps'
|
import { Provider as StampsProvider } from './providers/Stamps'
|
||||||
import { Provider as PlatformProvider } from './providers/Platform'
|
import { Provider as PlatformProvider } from './providers/Platform'
|
||||||
@@ -43,12 +44,14 @@ const App = (): ReactElement => {
|
|||||||
<StampsProvider>
|
<StampsProvider>
|
||||||
<PlatformProvider>
|
<PlatformProvider>
|
||||||
<SnackbarProvider>
|
<SnackbarProvider>
|
||||||
|
<Router>
|
||||||
<>
|
<>
|
||||||
<CssBaseline />
|
<CssBaseline />
|
||||||
<Router>
|
<Dashboard>
|
||||||
<BaseRouter />
|
<BaseRouter />
|
||||||
</Router>
|
</Dashboard>
|
||||||
</>
|
</>
|
||||||
|
</Router>
|
||||||
</SnackbarProvider>
|
</SnackbarProvider>
|
||||||
</PlatformProvider>
|
</PlatformProvider>
|
||||||
</StampsProvider>
|
</StampsProvider>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { ReactElement } from 'react'
|
import { ReactElement } from 'react'
|
||||||
import { Link, RouteComponentProps } from 'react-router-dom'
|
import { Link, useLocation } from 'react-router-dom'
|
||||||
|
|
||||||
import { createStyles, Theme, makeStyles } from '@material-ui/core/styles'
|
import { createStyles, Theme, makeStyles } from '@material-ui/core/styles'
|
||||||
import { ListItemText, ListItemIcon, ListItem, Divider, List, Drawer, Link as MUILink } from '@material-ui/core'
|
import { ListItemText, ListItemIcon, ListItem, Divider, List, Drawer, Link as MUILink } from '@material-ui/core'
|
||||||
@@ -80,13 +80,14 @@ const useStyles = makeStyles((theme: Theme) =>
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
interface Props extends RouteComponentProps {
|
interface Props {
|
||||||
themeMode: string
|
themeMode: string
|
||||||
isOk: boolean
|
isOk: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function SideBar(props: Props): ReactElement {
|
export default function SideBar(props: Props): ReactElement {
|
||||||
const classes = useStyles()
|
const classes = useStyles()
|
||||||
|
const location = useLocation()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classes.root}>
|
<div className={classes.root}>
|
||||||
@@ -113,15 +114,15 @@ export default function SideBar(props: Props): ReactElement {
|
|||||||
<Link to={item.path} key={item.id} style={{ color: 'inherit', textDecoration: 'none' }}>
|
<Link to={item.path} key={item.id} style={{ color: 'inherit', textDecoration: 'none' }}>
|
||||||
<ListItem
|
<ListItem
|
||||||
button
|
button
|
||||||
selected={props.location.pathname === item.path}
|
selected={location.pathname === item.path}
|
||||||
className={props.location.pathname === item.path ? classes.activeSideBarItem : ''}
|
className={location.pathname === item.path ? classes.activeSideBarItem : ''}
|
||||||
>
|
>
|
||||||
<ListItemIcon className={props.location.pathname === item.path ? classes.activeSideBar : ''}>
|
<ListItemIcon className={location.pathname === item.path ? classes.activeSideBar : ''}>
|
||||||
<item.icon style={{ height: '20px' }} />
|
<item.icon style={{ height: '20px' }} />
|
||||||
</ListItemIcon>
|
</ListItemIcon>
|
||||||
<ListItemText
|
<ListItemText
|
||||||
primary={item.label}
|
primary={item.label}
|
||||||
className={props.location.pathname === item.path ? classes.activeSideBar : ''}
|
className={location.pathname === item.path ? classes.activeSideBar : ''}
|
||||||
/>
|
/>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ import NavBar from '../components/NavBar'
|
|||||||
|
|
||||||
import { Context } from '../providers/Bee'
|
import { Context } from '../providers/Bee'
|
||||||
|
|
||||||
import { RouteComponentProps } from 'react-router'
|
|
||||||
|
|
||||||
const useStyles = makeStyles((theme: Theme) =>
|
const useStyles = makeStyles((theme: Theme) =>
|
||||||
createStyles({
|
createStyles({
|
||||||
content: {
|
content: {
|
||||||
@@ -24,7 +22,7 @@ const useStyles = makeStyles((theme: Theme) =>
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
interface Props extends RouteComponentProps {
|
interface Props {
|
||||||
children?: ReactElement
|
children?: ReactElement
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +54,7 @@ const Dashboard = (props: Props): ReactElement => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<SideBar {...props} themeMode={themeMode} isOk={status.all} />
|
<SideBar themeMode={themeMode} isOk={status.all} />
|
||||||
<NavBar themeMode={themeMode} />
|
<NavBar themeMode={themeMode} />
|
||||||
<ErrorBoundary>
|
<ErrorBoundary>
|
||||||
<main className={classes.content}>
|
<main className={classes.content}>
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
import type { JSXElementConstructor, ReactElement } from 'react'
|
|
||||||
import { Route, RouteComponentProps } from 'react-router-dom'
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
component: JSXElementConstructor<RouteComponentProps>
|
|
||||||
layout: JSXElementConstructor<RouteComponentProps>
|
|
||||||
exact?: boolean
|
|
||||||
path: string
|
|
||||||
}
|
|
||||||
|
|
||||||
const AppRoute = ({ component: Component, layout: Layout, exact, path }: Props): ReactElement => (
|
|
||||||
<Route
|
|
||||||
exact={exact}
|
|
||||||
path={path}
|
|
||||||
render={props => (
|
|
||||||
<Layout {...props}>
|
|
||||||
<Component {...props} />
|
|
||||||
</Layout>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
|
|
||||||
export default AppRoute
|
|
||||||
+8
-12
@@ -1,12 +1,8 @@
|
|||||||
import type { ReactElement } from 'react'
|
import type { ReactElement } from 'react'
|
||||||
import { Switch } from 'react-router-dom'
|
import { Switch } from 'react-router-dom'
|
||||||
|
|
||||||
import AppRoute from './AppRoute'
|
import { Route } from 'react-router-dom'
|
||||||
|
|
||||||
// layouts
|
|
||||||
import Dashboard from '../layout/Dashboard'
|
|
||||||
|
|
||||||
// pages
|
|
||||||
import Info from '../pages/info'
|
import Info from '../pages/info'
|
||||||
import Status from '../pages/status'
|
import Status from '../pages/status'
|
||||||
import Files from '../pages/files'
|
import Files from '../pages/files'
|
||||||
@@ -17,13 +13,13 @@ import Stamps from '../pages/stamps'
|
|||||||
|
|
||||||
const BaseRouter = (): ReactElement => (
|
const BaseRouter = (): ReactElement => (
|
||||||
<Switch>
|
<Switch>
|
||||||
<AppRoute exact path="/" layout={Dashboard} component={Info} />
|
<Route exact path="/" component={Info} />
|
||||||
<AppRoute exact path="/files/" layout={Dashboard} component={Files} />
|
<Route exact path="/files/" component={Files} />
|
||||||
<AppRoute exact path="/peers/" layout={Dashboard} component={Peers} />
|
<Route exact path="/peers/" component={Peers} />
|
||||||
<AppRoute exact path="/accounting/" layout={Dashboard} component={Accounting} />
|
<Route exact path="/accounting/" component={Accounting} />
|
||||||
<AppRoute exact path="/settings/" layout={Dashboard} component={Settings} />
|
<Route exact path="/settings/" component={Settings} />
|
||||||
<AppRoute exact path="/stamps/" layout={Dashboard} component={Stamps} />
|
<Route exact path="/stamps/" component={Stamps} />
|
||||||
<AppRoute exact path="/status" layout={Dashboard} component={Status} />
|
<Route exact path="/status" component={Status} />
|
||||||
</Switch>
|
</Switch>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user