Skip to content

Commit

Permalink
Merge pull request #841 from alexstotsky/improve-time-frame-selection
Browse files Browse the repository at this point in the history
(improvements) Time frame selector
  • Loading branch information
ezewer authored Aug 8, 2024
2 parents ad4100d + 486cff9 commit eae42fe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
33 changes: 14 additions & 19 deletions src/ui/TimeFrameSelector/TimeFrameSelector.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,36 @@
import React from 'react'
import React, { memo, useMemo } from 'react'
import PropTypes from 'prop-types'
import { withTranslation } from 'react-i18next'
import { useTranslation } from 'react-i18next'

import Select from 'ui/Select'

import constants from './constants'

const {
DAY, WEEK, MONTH, YEAR,
} = constants
const getItems = (t) => [
{ value: constants.DAY, label: t('timeframe.day') },
{ value: constants.WEEK, label: t('timeframe.week') },
{ value: constants.MONTH, label: t('timeframe.month') },
{ value: constants.YEAR, label: t('timeframe.year') },
]

const TimeFrameSelector = (props) => {
const { onChange, t, value } = props

const items = [
{ value: DAY, label: t('timeframe.day') },
{ value: WEEK, label: t('timeframe.week') },
{ value: MONTH, label: t('timeframe.month') },
{ value: YEAR, label: t('timeframe.year') },
]
const TimeFrameSelector = ({ onChange, value }) => {
const { t } = useTranslation()
const items = useMemo(() => getItems(t), [t])

return (
<Select
className='bitfinex-select--timeframe'
popoverClassName='bitfinex-select-menu--timeframe'
value={value}
items={items}
onChange={onChange}
className='bitfinex-select--timeframe'
popoverClassName='bitfinex-select-menu--timeframe'
/>
)
}

TimeFrameSelector.propTypes = {
value: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
t: PropTypes.func.isRequired,
}
TimeFrameSelector.defaultProps = {}

export default withTranslation('translations')(TimeFrameSelector)
export default memo(TimeFrameSelector)
4 changes: 1 addition & 3 deletions src/ui/TimeFrameSelector/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
import TimeFrameSelector from './TimeFrameSelector'

export default TimeFrameSelector
export { default } from './TimeFrameSelector'

0 comments on commit eae42fe

Please sign in to comment.