-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #272 from pshenmic/feat/validator-page
Implement a new design for the specific validator page on the frontend
- Loading branch information
Showing
67 changed files
with
2,698 additions
and
363 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 118 additions & 14 deletions
132
packages/frontend/src/app/validator/[hash]/BlocksChart.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,135 @@ | ||
import ProposedBlocksChart from './../../../components/charts/ProposedBlocksChart' | ||
import { useState, useEffect, useRef } from 'react' | ||
import { fetchHandlerSuccess, fetchHandlerError } from '../../../util' | ||
import { useState, useEffect } from 'react' | ||
import { LineChart, TimeframeMenu } from './../../../components/charts' | ||
import * as Api from '../../../util/Api' | ||
import { Button } from '@chakra-ui/react' | ||
import { CalendarIcon } from './../../../components/ui/icons' | ||
import { ErrorMessageBlock } from '../../../components/Errors' | ||
import './TimeframeSelector.scss' | ||
import './TabsChart.scss' | ||
|
||
const chartConfig = { | ||
timespan: { | ||
default: '1w', | ||
values: ['1h', '24h', '3d', '1w'] | ||
defaultIndex: 3, | ||
values: [ | ||
{ | ||
label: '1 hour', | ||
range: '1h' | ||
}, | ||
{ | ||
label: '24 hours', | ||
range: '24h' | ||
}, | ||
{ | ||
label: '3 days', | ||
range: '3d' | ||
}, | ||
{ | ||
label: '1 week', | ||
range: '1w' | ||
} | ||
] | ||
} | ||
} | ||
|
||
export default function BlocksChart ({ hash }) { | ||
const TimeframeSelector = ({ config, isActive, changeCallback, openStateCallback, menuRef }) => { | ||
const [timespan, setTimespan] = useState(chartConfig.timespan.values[chartConfig.timespan.defaultIndex]) | ||
const [menuIsOpen, setMenuIsOpen] = useState(false) | ||
|
||
const changeHandler = (value) => { | ||
setTimespan(value) | ||
if (typeof changeCallback === 'function') changeCallback(value) | ||
setMenuIsOpen(false) | ||
} | ||
|
||
useEffect(() => { | ||
if (!isActive) setMenuIsOpen(false) | ||
}, [isActive]) | ||
|
||
useEffect(() => { | ||
if (typeof openStateCallback === 'function') openStateCallback(menuIsOpen) | ||
}, [menuIsOpen]) | ||
|
||
return ( | ||
<div className={`TimeframeSelector ${menuIsOpen ? 'TimeframeSelector--MenuActive' : ''}`}> | ||
<TimeframeMenu | ||
ref={menuRef} | ||
className={'TimeframeSelector__Menu'} | ||
config={config} | ||
changeCallback={changeHandler} | ||
/> | ||
|
||
<Button | ||
className={`TimeframeSelector__Button ${menuIsOpen ? 'TimeframeSelector__Button--Active' : ''}`} | ||
onClick={() => setMenuIsOpen(state => !state)} | ||
> | ||
<CalendarIcon mr={'10px'}/> | ||
{timespan.label} | ||
</Button> | ||
</div> | ||
) | ||
} | ||
|
||
export default function BlocksChart ({ hash, isActive }) { | ||
const [blocksHistory, setBlocksHistory] = useState({ data: {}, loading: true, error: false }) | ||
const [blocksHistoryTimespan, setBlocksHistoryTimespan] = useState(chartConfig.timespan.default) | ||
const [timespan, setTimespan] = useState(chartConfig.timespan.values[chartConfig.timespan.defaultIndex]) | ||
const [menuIsOpen, setMenuIsOpen] = useState(false) | ||
const TimeframeMenuRef = useRef(null) | ||
const [selectorHeight, setSelectorHeight] = useState(0) | ||
|
||
useEffect(() => { | ||
Api.getBlocksStatsByValidator(hash, blocksHistoryTimespan) | ||
Api.getBlocksStatsByValidator(hash, timespan.range) | ||
.then(res => fetchHandlerSuccess(setBlocksHistory, { resultSet: res })) | ||
.catch(err => fetchHandlerError(setBlocksHistory, err)) | ||
}, [blocksHistoryTimespan]) | ||
}, [timespan]) | ||
|
||
useEffect(() => { | ||
if (menuIsOpen && TimeframeMenuRef.current) { | ||
const element = TimeframeMenuRef.current | ||
const height = element.getBoundingClientRect().height | ||
setSelectorHeight(height) | ||
} else { | ||
setSelectorHeight(0) | ||
} | ||
}, [menuIsOpen, TimeframeMenuRef]) | ||
|
||
if (blocksHistory.error || (!blocksHistory.loading && !blocksHistory.data?.resultSet)) { | ||
return (<ErrorMessageBlock/>) | ||
} | ||
|
||
return ( | ||
<ProposedBlocksChart | ||
height={'100%'} | ||
blocksHistory={blocksHistory} | ||
timespan={blocksHistoryTimespan} | ||
timespanChangeHandler={setBlocksHistoryTimespan} | ||
/> | ||
<div style={{ height: menuIsOpen ? `${Math.max(selectorHeight, 350)}px` : '350px' }} className={'TabsChart'}> | ||
{!blocksHistory.loading && | ||
<TimeframeSelector | ||
menuRef={TimeframeMenuRef} | ||
className={'TabsChart__TimeframeSelector'} | ||
config={chartConfig} | ||
changeCallback={setTimespan} | ||
isActive={isActive} | ||
openStateCallback={setMenuIsOpen} | ||
/> | ||
} | ||
<div className={`TabsChart__ChartContiner ${menuIsOpen ? 'TabsChart__ChartContiner--Hidden' : ''}`}> | ||
<LineChart | ||
data={blocksHistory.data?.resultSet?.map((item) => ({ | ||
x: new Date(item.timestamp), | ||
y: item.data.blocksCount | ||
})) || []} | ||
timespan={timespan.range} | ||
xAxis={{ | ||
type: (() => { | ||
if (timespan.range === '1h') return { axis: 'time' } | ||
if (timespan.range === '24h') return { axis: 'time' } | ||
if (timespan.range === '3d') return { axis: 'date', tooltip: 'datetime' } | ||
if (timespan.range === '1w') return { axis: 'date' } | ||
})() | ||
}} | ||
yAxis={{ | ||
type: 'number', | ||
abbreviation: 'blocks' | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
.TabsChart { | ||
height: 100%; | ||
transition: all .2s; | ||
|
||
&__ChartContiner { | ||
height: 100%; | ||
visibility: visible; | ||
opacity: 1; | ||
transition: all .2s; | ||
|
||
&--Hidden { | ||
visibility: hidden; | ||
opacity: 0; | ||
transition-delay: 0s; | ||
} | ||
} | ||
} | ||
|
||
.TabsChart .TimeframeSelector { | ||
&__Button { | ||
|
||
} | ||
|
||
@media screen and (max-width: 555px) { | ||
&__Button { | ||
top: 10px; | ||
right: 10px; | ||
z-index: 11; | ||
|
||
&--Active { | ||
display: none; | ||
} | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
packages/frontend/src/app/validator/[hash]/TimeframeSelector.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
@use '../../../styles/mixins.scss'; | ||
@import '../../../styles/variables.scss'; | ||
|
||
.TimeframeSelector { | ||
&--MenuActive & { | ||
&__Menu { | ||
visibility: visible; | ||
opacity: 1; | ||
transition-delay: .2s; | ||
} | ||
} | ||
|
||
&__Menu { | ||
padding: 0 12px !important; | ||
top: 12px; | ||
position: absolute; | ||
z-index: 10; | ||
width: 100%; | ||
// height: 100%; | ||
height: max-content; | ||
left: 0; | ||
backdrop-filter: $blockBackgroundBlur; | ||
visibility: hidden; | ||
opacity: 0; | ||
transition: all .2s; | ||
transition-delay: 0s; | ||
} | ||
|
||
&__Button { | ||
position: absolute !important; | ||
top: -36px; | ||
right: 10px; | ||
transition: all .2s; | ||
visibility: visible; | ||
opacity: 1; | ||
height: 28px !important; | ||
|
||
&--Active { | ||
background-color: #fff !important; | ||
color: $color-brand-normal !important; | ||
} | ||
} | ||
} |
Oops, something went wrong.