Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade react-router to v6 in dashboard #3007

Merged
merged 10 commits into from
Jun 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
"async-call-rpc": "^5.1.0",
"classnames": "^2.3.1",
"color": "^3.1.3",
"history": "^5.0.0",
"react-router": "^6.0.0-beta.0",
"react-router-dom": "^6.0.0-beta.0",
"json-stable-stringify": "^1.0.1",
"lodash-es": "^4.17.21",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-use": "^17.2.4",
"unstated-next": "^1.1.0",
"use-subscription": "^1.5.1"
Expand Down
37 changes: 25 additions & 12 deletions packages/dashboard/src/components/DashboardFrame/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,41 @@ import {
ListItemIcon,
Collapse,
Theme,
ListItemProps,
useMediaQuery,
experimentalStyled as styled,
listItemClasses,
listItemIconClasses,
ListItemProps,
} from '@material-ui/core'
import { Masks, AccountBalanceWallet, ExpandLess, ExpandMore, Settings } from '@material-ui/icons'
import { useContext } from 'react'
import { useRouteMatch } from 'react-router'
import { Link, LinkProps } from 'react-router-dom'
import { Routes } from '../../pages/routes'
import { useMatch, useNavigate } from 'react-router'
import { DashboardContext } from './context'
import { MaskNotSquareIcon } from '@dimensiondev/icons'
import { useDashboardI18N } from '../../locales'
import { MaskColorVar } from '@dimensiondev/maskbook-theme'
import { RoutePaths } from '../../pages/routes'

function ListItemLinkUnStyled({ nested, ...props }: LinkProps & ListItemProps & { nested?: boolean; to: string }) {
return <MuiListItem button component={Link} selected={!!useRouteMatch(props.to)} {...props} />
const ListItemLinkUnStyled = ({ to, ...props }: ListItemProps & { to: string; nested?: boolean }) => {
const navigate = useNavigate()
return (
<MuiListItem
{...props}
selected={!!useMatch(to)}
onClick={(event) => {
navigate(to)
props.onClick?.(event)
}}
/>
)
}

const ListItemLink = styled(ListItemLinkUnStyled)(({ theme, nested }) => {
return {
[`&.${listItemClasses.root}`]: {
color: theme.palette.mode === 'light' ? '' : 'rgba(255,255,255,.8)',
paddingLeft: nested ? theme.spacing(9) : theme.spacing(2),
cursor: 'pointer',
},
[`&.${listItemClasses.selected}`]: {
color: MaskColorVar.linkText,
Expand Down Expand Up @@ -82,30 +92,33 @@ export function Navigation({}: NavigationProps) {
<MaskNotSquareIcon />
</LogoItem>
)}
<ListItemLink to={Routes.Personas}>
<ListItemLink to={RoutePaths.Personas}>
<ListItemIcon>
<Masks />
</ListItemIcon>
<ListItemText primary={t.personas()} />
</ListItemLink>
<ListItem button selected={!!useRouteMatch(Routes.Wallets)} onClick={toggleNavigationExpand}>
<ListItemLink
to={RoutePaths.Wallets}
selected={!!useMatch(RoutePaths.Wallets)}
onClick={toggleNavigationExpand}>
<ListItemIcon>
<AccountBalanceWallet />
</ListItemIcon>
<ListItemText>{t.wallets()}</ListItemText>
{expanded ? <ExpandLess /> : <ExpandMore />}
</ListItem>
</ListItemLink>
<Collapse in={expanded}>
<List disablePadding>
<ListItemLink nested to={Routes.WalletsTransfer}>
<ListItemLink nested to={RoutePaths.WalletsTransfer}>
<ListItemText primary={t.wallets_transfer()} />
</ListItemLink>
<ListItemLink nested to={Routes.WalletsHistory}>
<ListItemLink nested to={RoutePaths.WalletsHistory}>
<ListItemText primary={t.wallets_history()} />
</ListItemLink>
</List>
</Collapse>
<ListItemLink to={Routes.Settings}>
<ListItemLink to={RoutePaths.Settings}>
<ListItemIcon>
<Settings />
</ListItemIcon>
Expand Down
21 changes: 10 additions & 11 deletions packages/dashboard/src/pages/routes.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Route, Switch, Redirect } from 'react-router'
import { Route, Routes, Navigate } from 'react-router'
import React, { lazy, Suspense } from 'react'
import { DashboardFrame } from '../components/DashboardFrame'
export enum Routes {
export enum RoutePaths {
Welcome = '/welcome',
Personas = '/personas',
Wallets = '/wallets',
Expand All @@ -21,15 +21,14 @@ const Plugins = lazy(() => import('./Plugins'))
export function Pages() {
return (
<Suspense fallback="loading...">
<Switch>
<Route path={Routes.Welcome} children={<Welcome />} />
<Route path={Routes.Personas} children={frame(<Personas />)} exact />
{/* This is intentional. Wallets has subroutes and we want to make it selected in the subroutes */}
<Route path={Routes.Wallets} children={frame(<Wallets />)} />
<Route path={Routes.Settings} children={frame(<Settings />)} exact />
<Route path={Routes.Plugins} children={frame(<Plugins />)} exact />
<Route children={<Redirect to={Routes.Personas} />} />
</Switch>
<Routes>
<Route path={RoutePaths.Welcome} element={<Welcome />} />
<Route path={RoutePaths.Personas} element={frame(<Personas />)} />
<Route path={`${RoutePaths.Wallets}/*`} element={frame(<Wallets />)} />
<Route path={RoutePaths.Settings} element={frame(<Settings />)} />
<Route path={RoutePaths.Plugins} element={frame(<Plugins />)} />
<Route element={<Navigate to={RoutePaths.Personas} />} />
</Routes>
</Suspense>
)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/icons/general/Search.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createIcon } from '../utils'
import { MaskColorVar } from '@dimensiondev/maskbook-theme'
import { MaskColorVar } from '@dimensiondev/maskbook-theme/constants'

export const SearchIcon = createIcon(
'Search',
Expand Down
5 changes: 2 additions & 3 deletions packages/maskbook/miscs/package-overrides/xhr2-cookies.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
module.exports = {
XMLHttpRequest,
}
export const XMLHttpRequest = globalThis.XMLHttpRequest
export default globalThis.XMLHttpRequest
2 changes: 1 addition & 1 deletion packages/maskbook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
},
"devDependencies": {
"@dimensiondev/webextension-shim": "0.0.3-20201120022530-b318b89",
"@pmmmwh/react-refresh-webpack-plugin": "^0.4.3",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.0-rc.0",
"@sinonjs/text-encoding": "^0.7.1",
"@testing-library/react-hooks": "^7.0.0",
"@types/elliptic": "^6.4.12",
Expand Down
3 changes: 2 additions & 1 deletion packages/maskbook/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ function config(opts: {
// By aliasing them to the original position, we can speed up the compile because there is no need to wait tsc build them to the dist folder.
'@dimensiondev/dashboard': require.resolve('../dashboard/src/entry.tsx'),
'@dimensiondev/maskbook-shared': require.resolve('../shared/src/index.ts'),
'@dimensiondev/maskbook-theme/constants': require.resolve('../theme/src/constants.ts'),
'@dimensiondev/maskbook-theme': require.resolve('../theme/src/theme.ts'),
'@dimensiondev/icons': require.resolve('../icons/index.ts'),
'@dimensiondev/mask-plugin-infra': require.resolve('../plugin-infra/src/index.ts'),
Expand Down Expand Up @@ -245,7 +246,7 @@ function config(opts: {
// overlay is not working in our environment
return [
new HotModuleReplacementPlugin(),
!disableReactHMR && new ReactRefreshWebpackPlugin({ overlay: false }),
!disableReactHMR && new ReactRefreshWebpackPlugin({ overlay: false, esModule: true }),
].filter(nonNullable)
}
}
Expand Down
79 changes: 57 additions & 22 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.