From 7db4ddff5646e38bc563fd51c10a49049b0ac672 Mon Sep 17 00:00:00 2001 From: fmtabbara Date: Tue, 12 Mar 2024 10:20:26 +0000 Subject: [PATCH] use url as unique nav selection state --- explorer/src/components/MobileNav.tsx | 7 +++---- explorer/src/components/Nav.tsx | 13 +++++-------- explorer/src/context/main.tsx | 6 +++--- explorer/src/context/nav.tsx | 15 +++++++-------- explorer/src/pages/ServiceProviders/index.tsx | 6 ++++-- 5 files changed, 22 insertions(+), 25 deletions(-) diff --git a/explorer/src/components/MobileNav.tsx b/explorer/src/components/MobileNav.tsx index 224bd69b0c..ac4b313467 100644 --- a/explorer/src/components/MobileNav.tsx +++ b/explorer/src/components/MobileNav.tsx @@ -8,7 +8,7 @@ import { useMainContext } from '../context/main'; import { MobileDrawerClose } from '../icons/MobileDrawerClose'; import { Footer } from './Footer'; import { ExpandableButton } from './Nav'; -import { ConnectKeplrWallet } from './ConnectKeplrWallet'; +import { ConnectKeplrWallet } from './Wallet/ConnectKeplrWallet'; import NetworkTitle from './NetworkTitle'; export const MobileNav: FCWithChildren = ({ children }) => { @@ -23,8 +23,8 @@ export const MobileNav: FCWithChildren = ({ children }) => { setDrawerOpen(!drawerOpen); }; - const handleClick = (id: number) => { - updateNavState(id); + const handleClick = (url: string) => { + updateNavState(url); toggleDrawer(); }; @@ -103,7 +103,6 @@ export const MobileNav: FCWithChildren = ({ children }) => { {navState.map((props) => ( void; isMobile: boolean; - setToActive: (num: number) => void; + setToActive: (url: string) => void; }; export const ExpandableButton: FCWithChildren = ({ - id, url, setToActive, isActive, @@ -110,7 +108,7 @@ export const ExpandableButton: FCWithChildren = ({ const { palette } = useTheme(); const handleClick = () => { - setToActive(id); + setToActive(url); if (title === 'Network Components' && nested) { openDrawer(); toggleNestedOptions(!nestedOptions); @@ -204,7 +202,6 @@ export const ExpandableButton: FCWithChildren = ({ {nestedOptions && nested?.map((each) => ( { const switchNetworkLink = environment === 'mainnet' ? 'https://sandbox-explorer.nymtech.net' : 'https://explorer.nymtech.net'; - const setToActive = (id: number) => { - updateNavState(id); + const setToActive = (url: string) => { + updateNavState(url); }; const fixDrawerOpen = () => { diff --git a/explorer/src/context/main.tsx b/explorer/src/context/main.tsx index ad01e36d44..c7a74a3d0d 100644 --- a/explorer/src/context/main.tsx +++ b/explorer/src/context/main.tsx @@ -35,7 +35,7 @@ interface StateApi { fetchMixnodes: (status?: MixnodeStatus) => Promise; filterMixnodes: (filters: any, status: any) => void; toggleMode: () => void; - updateNavState: (id: number) => void; + updateNavState: (title: string) => void; } type State = StateData & StateApi; @@ -185,10 +185,10 @@ export const MainContextProvider: FCWithChildren = ({ children }) => { } }; - const updateNavState = (id: number) => { + const updateNavState = (url: string) => { const updated = navState.map((option) => ({ ...option, - isActive: option.id === id, + isActive: option.url === url, })); updateNav(updated); }; diff --git a/explorer/src/context/nav.tsx b/explorer/src/context/nav.tsx index ad65e0e50b..6df749f585 100644 --- a/explorer/src/context/nav.tsx +++ b/explorer/src/context/nav.tsx @@ -1,11 +1,11 @@ import * as React from 'react'; +import { DelegateIcon } from '@src/icons/DelevateSVG'; import { BIG_DIPPER } from '../api/constants'; import { OverviewSVG } from '../icons/OverviewSVG'; import { NodemapSVG } from '../icons/NodemapSVG'; import { NetworkComponentsSVG } from '../icons/NetworksSVG'; export type NavOptionType = { - id: number; isActive?: boolean; url: string; title: string; @@ -16,46 +16,45 @@ export type NavOptionType = { export const originalNavOptions: NavOptionType[] = [ { - id: 0, isActive: false, url: '/', title: 'Overview', Icon: , }, { - id: 1, isActive: false, url: '/network-components', title: 'Network Components', Icon: , nested: [ { - id: 3, url: '/network-components/mixnodes', title: 'Mixnodes', }, { - id: 4, url: '/network-components/gateways', title: 'Gateways', }, { - id: 5, url: `${BIG_DIPPER}/validators`, title: 'Validators', }, { - id: 6, url: 'network-components/service-providers', title: 'Service Providers', }, ], }, { - id: 2, isActive: false, url: '/nodemap', title: 'Nodemap', Icon: , }, + { + isActive: false, + url: '/delegations', + title: 'Delegations', + Icon: , + }, ]; diff --git a/explorer/src/pages/ServiceProviders/index.tsx b/explorer/src/pages/ServiceProviders/index.tsx index 144f578e44..618aa72924 100644 --- a/explorer/src/pages/ServiceProviders/index.tsx +++ b/explorer/src/pages/ServiceProviders/index.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { Button, Card, FormControl, Grid, ListItem, Menu, SelectChangeEvent, Typography } from '@mui/material'; +import { Box, Button, Card, FormControl, Grid, ListItem, Menu, SelectChangeEvent, Typography } from '@mui/material'; import { GridColDef, GridRenderCellParams } from '@mui/x-data-grid'; import { TableToolbar } from '../../components/TableToolbar'; import { Title } from '../../components/Title'; @@ -90,7 +90,9 @@ export const ServiceProviders = () => { return ( <> - + <Box mb={2}> + <Title text="Service Providers" /> + </Box> <Grid container> <Grid item xs={12}> <Card