Skip to content

Commit a6facc1

Browse files
committed
Update Date Picker
1 parent c52b33d commit a6facc1

File tree

10 files changed

+147
-74
lines changed

10 files changed

+147
-74
lines changed

packages/frontend/src/app/validator/[hash]/BlocksChart.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { CalendarIcon } from './../../../components/ui/icons'
77
import { ErrorMessageBlock } from '../../../components/Errors'
88
import { DateRangePicker } from '../../../components/calendar'
99
import './TimeframeSelector.scss'
10+
import './TimeframeMenu.scss'
1011
import './TabsChart.scss'
1112

1213
const chartConfig = {
@@ -50,10 +51,13 @@ const TimeframeSelector = ({ config, isActive, changeCallback, openStateCallback
5051
if (typeof openStateCallback === 'function') openStateCallback(menuIsOpen)
5152
}, [menuIsOpen])
5253

54+
const calendarHandler = (value) => {
55+
// console.log('calendarHandler', value)
56+
}
57+
5358
return (
5459
<div className={`TimeframeSelector ${menuIsOpen ? 'TimeframeSelector--MenuActive' : ''}`}>
5560
<div className={'TimeframeSelector__Menu TimeframeMenu'}>
56-
5761
<div className={'TimeframeMenu__ValuesContainer'}>
5862
<div className={'TimeframeMenu__ValuesTitle'}>
5963
Select a day, period or Timeframe:
@@ -82,6 +86,7 @@ const TimeframeSelector = ({ config, isActive, changeCallback, openStateCallback
8286
monthsToShow={7}
8387
noTopNavigation={true}
8488
noWeekDay={true}
89+
changeHandler={calendarHandler}
8590
/>
8691
</div>
8792
</div>

packages/frontend/src/app/validator/[hash]/TabsChart.scss

+18
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,21 @@
1414
}
1515
}
1616
}
17+
18+
.TabsChart .TimeframeSelector {
19+
&__Button {
20+
21+
}
22+
23+
@media screen and (max-width: 555px) {
24+
&__Button {
25+
top: 10px;
26+
right: 10px;
27+
z-index: 11;
28+
29+
&--Active {
30+
display: none;
31+
}
32+
}
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
@use '../../../styles/mixins.scss';
2+
@import '../../../styles/variables.scss';
3+
4+
.TimeframeMenu {
5+
padding: 12px;
6+
border-radius: 20px;
7+
8+
&__ValuesContainer {
9+
display: flex;
10+
align-items: center;
11+
justify-content: flex-end;
12+
}
13+
14+
&__ValuesTitle {
15+
font-family: $font-mono;
16+
color: #fff;
17+
opacity: .5;
18+
font-size: 0.75rem;
19+
}
20+
21+
&__Values {
22+
display: flex;
23+
flex-wrap: nowrap;
24+
justify-content: flex-end;
25+
}
26+
27+
&__ValueButton {
28+
margin-left: 10px;
29+
30+
&--Active {
31+
background-color: $color-brand-normal !important;
32+
color: #fff !important;
33+
}
34+
}
35+
36+
&__Calendar {
37+
width: 100%;
38+
height: 100%;
39+
}
40+
41+
@media screen and (max-width: 555px) {
42+
&__Values {
43+
flex-wrap: wrap;
44+
margin-bottom: -8px;
45+
}
46+
47+
&__ValueButton {
48+
margin-bottom: 8px;
49+
}
50+
}
51+
}

packages/frontend/src/app/validator/[hash]/TimeframeSelector.scss

-49
Original file line numberDiff line numberDiff line change
@@ -39,52 +39,3 @@
3939
}
4040
}
4141
}
42-
43-
.TimeframeMenu {
44-
padding: 12px;
45-
border-radius: 20px;
46-
47-
&__ValuesContainer {
48-
display: flex;
49-
align-items: center;
50-
justify-content: flex-end;
51-
}
52-
53-
&__ValuesTitle {
54-
font-family: $font-mono;
55-
color: #fff;
56-
opacity: .5;
57-
font-size: 0.75rem;
58-
}
59-
60-
&__Values {
61-
display: flex;
62-
flex-wrap: nowrap;
63-
justify-content: flex-end;
64-
}
65-
66-
&__ValueButton {
67-
margin-left: 10px;
68-
69-
&--Active {
70-
background-color: $color-brand-normal !important;
71-
color: #fff !important;
72-
}
73-
}
74-
75-
&__Calendar {
76-
width: 100%;
77-
height: 100%;
78-
}
79-
80-
@media screen and (max-width: 555px) {
81-
&__Values {
82-
flex-wrap: wrap;
83-
margin-bottom: -8px;
84-
}
85-
86-
&__ValueButton {
87-
margin-bottom: 8px;
88-
}
89-
}
90-
}

packages/frontend/src/app/validator/[hash]/Validator.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,20 @@ function Validator ({ hash }) {
6666

6767
useEffect(() => {
6868
if (!validator.data?.identity) return
69-
setTransactions(state => ({ ...state, loading: true }))
7069

71-
const identifier = validator.data.identity
72-
// const identifier = 'HVfqSPfdmiHsrajx7EmErGnV597uYdH3JGhvwpVDcdAT' // test
70+
setTransactions(state => ({ ...state, loading: true }))
7371

74-
Api.getTransactionsByIdentity(identifier, transactions.props.currentPage + 1, pageSize, 'desc')
72+
Api.getTransactionsByIdentity(validator.data.identity, transactions.props.currentPage + 1, pageSize, 'desc')
7573
.then(res => fetchHandlerSuccess(setTransactions, res))
7674
.catch(err => fetchHandlerError(setTransactions, err))
7775
}, [validator, transactions.props.currentPage])
7876

7977
useEffect(() => {
8078
if (!validator.data?.identity) return
81-
setTransfers(state => ({ ...state, loading: true }))
8279

83-
const identifier = validator.data.identity
80+
setTransfers(state => ({ ...state, loading: true }))
8481

85-
Api.getTransfersByIdentity(identifier, transfers.props.currentPage + 1, pageSize, 'desc')
82+
Api.getTransfersByIdentity(validator.data.identity, transfers.props.currentPage + 1, pageSize, 'desc')
8683
.then(res => fetchHandlerSuccess(setTransfers, res))
8784
.catch(err => fetchHandlerError(setTransfers, err))
8885
}, [validator, transfers.props.currentPage])
@@ -381,15 +378,15 @@ function Validator ({ hash }) {
381378
<Tab isDisabled>Reward Earned</Tab>
382379
</TabList>
383380
<TabPanels>
384-
<TabPanel height={'400px'} position={'relative'}>
381+
<TabPanel height={'350px'} position={'relative'}>
385382
<BlocksChart
386383
blockBorders={false}
387384
hash={hash}
388385
isActive={activeChartTab === 0}
389386
loading={validator.loading}
390387
/>
391388
</TabPanel>
392-
<TabPanel height={'400px'}>
389+
<TabPanel height={'350px'} position={'relative'}>
393390
Reward Earned
394391
</TabPanel>
395392
</TabPanels>

packages/frontend/src/components/calendar/DateRangePicker.js

+39-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react'
1+
import React, { useState, useEffect } from 'react'
22
import Calendar from 'react-calendar'
33
import 'react-calendar/dist/Calendar.css'
44
import './DateRangePicker.scss'
@@ -13,11 +13,22 @@ const DateRangePicker = ({
1313
}) => {
1414
const [range, setRange] = useState([null, null])
1515
const [currentMonthIndex, setCurrentMonthIndex] = useState(disableFutureDates ? -monthsToShow : 0)
16+
const [showSingleCalendar, setShowSingleCalendar] = useState(window.innerWidth < 600)
1617
const today = new Date()
1718

19+
useEffect(() => {
20+
const handleResize = () => {
21+
setShowSingleCalendar(window.innerWidth < 600)
22+
}
23+
window.addEventListener('resize', handleResize)
24+
return () => {
25+
window.removeEventListener('resize', handleResize)
26+
}
27+
}, [])
28+
1829
const generateMonthPairs = () => {
1930
const months = []
20-
for (let i = 0; i < monthsToShow; i += 2) {
31+
for (let i = 0; i < monthsToShow; i += showSingleCalendar ? 1 : 2) {
2132
const date1 = new Date(today.getFullYear(), today.getMonth() + currentMonthIndex + i, 1)
2233
const date2 = new Date(today.getFullYear(), today.getMonth() + currentMonthIndex + i + 1, 1)
2334

@@ -33,6 +44,16 @@ const DateRangePicker = ({
3344
return months
3445
}
3546

47+
// Получаем заголовки для диапазона
48+
const getHeaderLabel = (range) => {
49+
if (!range[0] || !range[1]) return ['', '']
50+
51+
const startLabel = range[0].toLocaleString('en-US', { month: 'long', year: 'numeric' })
52+
const endLabel = range[1].toLocaleString('en-US', { month: 'long', year: 'numeric' })
53+
54+
return [startLabel, endLabel]
55+
}
56+
3657
const monthPairs = generateMonthPairs()
3758

3859
const onDateChange = (dates) => {
@@ -44,11 +65,11 @@ const DateRangePicker = ({
4465
}
4566

4667
const handleNext = () => {
47-
setCurrentMonthIndex(prev => prev + 2)
68+
setCurrentMonthIndex(prev => prev + (showSingleCalendar ? 1 : 2))
4869
}
4970

5071
const handlePrev = () => {
51-
setCurrentMonthIndex(prev => prev - 2)
72+
setCurrentMonthIndex(prev => prev - (showSingleCalendar ? 1 : 2))
5273
}
5374

5475
const handleSetRange = (start1, end2) => {
@@ -60,19 +81,25 @@ const DateRangePicker = ({
6081
return false
6182
}
6283

84+
// Получаем заголовки на основе текущего выбранного диапазона
85+
const [headerStart, headerEnd] = getHeaderLabel(range)
86+
6387
return (
6488
<div className={'DateRangePicker ' +
6589
`${className || ''} ` +
6690
`${noTopNavigation ? 'DateRangePicker--NoTopNavigation' : ''} ` +
6791
`${noWeekDay ? 'DateRangePicker--NoWeekDay' : ''} `}
6892
>
93+
{/* Заголовки месяцев */}
6994
<div className={'DateRangePicker__Header'}>
7095
<div className={'DateRangePicker__HeaderMonth'}>
71-
{monthPairs[0].label.split(' - ')[0]}
72-
</div>
73-
<div className={'DateRangePicker__HeaderMonth'}>
74-
{monthPairs[0].label.split(' - ')[1]}
96+
{headerStart || monthPairs[0].label.split(' - ')[0]} {/* Отображаем выбранный месяц или месяц по умолчанию */}
7597
</div>
98+
{!showSingleCalendar && (
99+
<div className={'DateRangePicker__HeaderMonth'}>
100+
{headerEnd || monthPairs[0].label.split(' - ')[1]} {/* Отображаем выбранный месяц или месяц по умолчанию */}
101+
</div>
102+
)}
76103
</div>
77104

78105
<div className={'DateRangePicker__Calendar'}>
@@ -82,12 +109,12 @@ const DateRangePicker = ({
82109
onChange={onDateChange}
83110
value={range}
84111
tileDisabled={tileDisabled}
85-
showDoubleView={true}
112+
showDoubleView={!showSingleCalendar}
86113
/>
87114
</div>
88115

89116
<div className="DateRangePicker__MonthSelector">
90-
<button className={'DateRangePicker__Arrow DateRangePicker__Arrow--left'} onClick={handlePrev}>
117+
<button className={'DateRangePicker__Arrow DateRangePicker__Arrow--Left'} onClick={handlePrev}>
91118
&lt;
92119
</button>
93120

@@ -102,11 +129,11 @@ const DateRangePicker = ({
102129
onClick={() => handleSetRange(pair.start1, pair.end2)}
103130
disabled={disableFutureDates && pair.start1 > today}
104131
>
105-
{pair.labelShort}
132+
{showSingleCalendar ? pair.labelShort.split(' - ')[0] : pair.labelShort}
106133
</button>
107134
))}
108135

109-
<button className={'DateRangePicker__Arrow DateRangePicker__Arrow--right'} onClick={handleNext}>
136+
<button className={'DateRangePicker__Arrow DateRangePicker__Arrow--Right'} onClick={handleNext}>
110137
&gt;
111138
</button>
112139
</div>

packages/frontend/src/components/calendar/DateRangePicker.scss

+9
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,19 @@ $font-color: #fff;
7474
}
7575

7676
&__MonthButton {
77+
&--Active {
78+
background-color: $color-brand-normal;
79+
}
7780
}
7881

7982
&__Arrow {
83+
&--Left {
84+
margin-right: auto;
85+
}
8086

87+
&--Right {
88+
margin-left: auto;
89+
}
8190
}
8291

8392
.react-calendar {

packages/frontend/src/components/ui/containers/InfoContainer.scss

+17
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@
5959
padding: 0 24px;
6060
padding-bottom: 1px;
6161
}
62+
63+
.chakra-tabs__tab {
64+
padding: 8px;
65+
}
6266
}
6367
}
6468

@@ -79,4 +83,17 @@
7983
}
8084
}
8185
}
86+
87+
@media screen and (max-width: $breakpoint-sm) {
88+
&--Tabs {
89+
.chakra-tabs__tablist {
90+
padding: 0 16px;
91+
padding-bottom: 1px;
92+
}
93+
94+
.chakra-tabs__tab {
95+
padding: 8px 4px;
96+
}
97+
}
98+
}
8299
}

packages/frontend/src/components/validators/ValidatorCard.js

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import { HorisontalSeparator } from '../ui/separators'
55
import Link from 'next/link'
66

77
export default function ValidatorCard ({ validator, rate, className }) {
8-
console.log('validator', validator)
9-
108
return (
119
<div className={`InfoBlock InfoBlock--Gradient ValidatorCard ${validator.loading ? 'ValidatorCard--Loading' : ''} ${className || ''}`}>
1210
<div className={'ValidatorCard__Header'}>

packages/frontend/src/styles/components/InfoBlock.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
$border-radius: var(--chakra-radii-block);
55

66
.InfoBlock {
7-
@include mixins.Block();
7+
@include mixins.Block(true);
88
position: relative;
99
padding: 20px 32px 32px 32px !important;
1010

0 commit comments

Comments
 (0)