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

Breadcrumb Implementation #309

Merged
merged 3 commits into from
Nov 27, 2024
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
10 changes: 10 additions & 0 deletions packages/frontend/src/app/validator/[hash]/Validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ import { ValidatorCard } from '../../../components/validators'
import { CircleIcon } from '../../../components/ui/icons'
import { RateTooltip } from '../../../components/ui/Tooltips'
import { networks } from '../../../constants/networks'
import { useBreadcrumbs } from '../../../contexts/BreadcrumbsContext'
import './ValidatorPage.scss'
import {
Badge,
Tabs, TabList, TabPanels, Tab, TabPanel
} from '@chakra-ui/react'

function Validator ({ hash }) {
const { setBreadcrumbs } = useBreadcrumbs()
const [validator, setValidator] = useState({ data: {}, loading: true, error: false })
const [rate, setRate] = useState({ data: {}, loading: true, error: false })
const [proposedBlocks, setProposedBlocks] = useState({ data: {}, props: { currentPage: 0 }, loading: true, error: false })
Expand All @@ -36,6 +38,14 @@ function Validator ({ hash }) {
const activeNetwork = networks.find(network => network.explorerBaseUrl === baseUrl)
const l1explorerBaseUrl = activeNetwork?.l1explorerBaseUrl || null

useEffect(() => {
setBreadcrumbs([
{ label: 'Home', path: '/' },
{ label: 'Validators', path: '/validators' },
{ label: hash, avatar: true }
])
}, [setBreadcrumbs, hash])

const poseStatusColor = (validator.data?.proTxInfo?.state?.PoSeBanHeight > 0 &&
validator.data?.proTxInfo?.state?.PoSeRevivedHeight === -1)
? 'red.default'
Expand Down
40 changes: 40 additions & 0 deletions packages/frontend/src/components/breadcrumbs/Breadcrumbs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import './Breadcrumbs.scss'
import Link from 'next/link'
import { ChevronIcon } from '../ui/icons'
import { useBreadcrumbs } from '../../contexts/BreadcrumbsContext'
import ImageGenerator from '../imageGenerator'

const Breadcrumbs = () => {
const { breadcrumbs } = useBreadcrumbs()

if (!breadcrumbs || breadcrumbs?.length === 0) return

const LinkContainer = ({ children, href, ...props }) => {
if (href) {
return <Link href={href} {...props}>{children}</Link>
}

return <span {...props}>{children}</span>
}

return (
<div className={'Breadcrumbs'}>
<ul className={'Breadcrumbs__LinksContainer'}>
{breadcrumbs.map((link, i) => (
<>
<li className={'Breadcrumbs__Link'}>
<LinkContainer href={i !== breadcrumbs.length - 1 ? link.path : null} key={i}>
{link.avatar &&
<ImageGenerator className={'Breadcrumbs__Avatar'} username={link.label} lightness={50} saturation={50} width={16} height={16} />}
{link.label}
</LinkContainer>
</li>
{i !== breadcrumbs.length - 1 && <div className={'Breadcrumbs__Separator'}><ChevronIcon color={'brand.normal'}/></div>}
</>
))}
</ul>
</div>
)
}

export default Breadcrumbs
68 changes: 68 additions & 0 deletions packages/frontend/src/components/breadcrumbs/Breadcrumbs.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
@use '../../styles/mixins.scss';
@import '../../styles/variables.scss';

.Breadcrumbs {
max-width: var(--chakra-sizes-container-maxPageW);
background: rgba(var(--chakra-colors-gray-675-rgb), .5);
border-radius: 0 0 20px 20px;
margin: -500px auto 0;
padding: 512px 12px 12px 12px;

&__LinksContainer {
display: flex;
align-items: center;
list-style: none;
margin: 0;
}

&__Link {
margin: 0;

a, span {
display: flex;
align-items: center;
padding: 9px 20px;
background: rgba(var(--chakra-colors-brand-normal-rgb), .2);
color: var(--chakra-colors-brand-normal);
transition: $transition-time-def;
border-radius: 10px;
font-size: 0.75rem;
font-family: $font-mono;
}

a {
background: rgba(var(--chakra-colors-brand-normal-rgb), .2);

&:hover {
background: rgba(var(--chakra-colors-brand-normal-rgb), .25);
}
}

span {
background: rgba(255, 255, 255, .1);
color: #ffffff;
cursor: default;
}
}

&__Avatar {
margin-right: 4px;
}

&__Separator {
margin: 0 10px;

svg {
width: 6px;
height: 10px;
}
}

@media screen and (max-width: 1440px) {
padding: 512px 24px 12px 24px;
}

@media screen and (max-width: $breakpoint-lg) {
display: none;
}
}
9 changes: 6 additions & 3 deletions packages/frontend/src/components/layout/RootComponent.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
'use client'

import { ChakraProvider, localStorageManager } from '@chakra-ui/react'
import { BreadcrumbsProvider } from '../../contexts/BreadcrumbsContext'
import { useEffect } from 'react'
import theme from '../../styles/theme'
import Navbar from './navbar/Navbar'
import Footer from './footer'
import Background from './Background'
import '../../styles/theme.scss'

export default function RootComponent ({ children, showHeaderLight }) {
export default function RootComponent ({ children }) {
useEffect(() => {
localStorage.setItem('chakra-ui-color-mode', theme.initialColorMode)
}, [])

return (
<ChakraProvider theme={theme} colorModeManager={localStorageManager}>
<Background/>
<Navbar/>
{children}
<BreadcrumbsProvider>
<Navbar/>
{children}
</BreadcrumbsProvider>
<Footer/>
</ChakraProvider>
)
Expand Down
8 changes: 6 additions & 2 deletions packages/frontend/src/components/layout/navbar/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
useDisclosure,
Stack
} from '@chakra-ui/react'
import Breadcrumbs from '../../breadcrumbs/Breadcrumbs'
import NetworkSelect from './NetworkSelect'
import { usePathname } from 'next/navigation'
import { useEffect } from 'react'
Expand Down Expand Up @@ -42,11 +43,13 @@ const NavLink = ({ children, to, isActive, className }) => {
function Navbar () {
const pathname = usePathname()
const { isOpen, onOpen, onClose } = useDisclosure()
const breadcrumbsActiveRoutes = ['/validator/']
const displayBreadcrumbs = breadcrumbsActiveRoutes.some(route => pathname.indexOf(route) !== -1)

useEffect(onClose, [pathname])
useEffect(onClose, [pathname, onClose])

return (
<Box px={3} position={'relative'}>
<Box position={'relative'}>
<div className={'NavbarStub'}></div>
<Flex
className={'Navbar'}
Expand Down Expand Up @@ -87,6 +90,7 @@ function Navbar () {
))}
</Stack>
</Box>
{displayBreadcrumbs && <Breadcrumbs/>}
</Box>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ $borderRadius: 20px;
&__BackLink {
position: relative;
z-index: 2;
display: block;
width: 32px;
height: 24px;
margin-right: 10px;
Expand Down Expand Up @@ -79,7 +78,6 @@ $borderRadius: 20px;
}

&__Header {
padding: 0 12px;
margin-bottom: 12px;

&::before {
Expand Down
15 changes: 15 additions & 0 deletions packages/frontend/src/contexts/BreadcrumbsContext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { createContext, useContext, useState } from 'react'

const BreadcrumbsContext = createContext({})
export const useBreadcrumbs = () => useContext(BreadcrumbsContext)

export const BreadcrumbsProvider = ({ children }) => {
const [breadcrumbs, setBreadcrumbs] = useState([])
const contextValue = { breadcrumbs, setBreadcrumbs }

return (
<BreadcrumbsContext.Provider value={contextValue}>
{children}
</BreadcrumbsContext.Provider>
)
}
3 changes: 2 additions & 1 deletion packages/frontend/src/styles/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const theme = extendTheme({
colors: {
brand: {
normal: '#008DE4',
'normal-rgb': '4, 147, 235',
'normal-rgb': '0, 141, 228',
deep: '#0E75B5',
shaded: '#165278',
light: '#2CBBFF',
Expand Down Expand Up @@ -79,6 +79,7 @@ export const theme = extendTheme({
600: '#62676a',
650: '#232C30',
675: '#21272C',
'675-rgb': '33, 39, 44',
700: '#494e51',
750: '#39454C',
800: '#2e393d',
Expand Down
Loading