-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add market page filters and sort (#8006)
* feat: add market page filters and sort * fix: continue * fix: portals request * fix: portals request * feat: review feedbacks * feat: review feedbacks
- Loading branch information
Showing
15 changed files
with
549 additions
and
106 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { ChevronDownIcon } from '@chakra-ui/icons' | ||
import type { ButtonProps } from '@chakra-ui/react' | ||
import { | ||
Button, | ||
Flex, | ||
Menu, | ||
MenuButton, | ||
MenuItemOption, | ||
MenuList, | ||
MenuOptionGroup, | ||
Text, | ||
} from '@chakra-ui/react' | ||
import { useCallback, useMemo } from 'react' | ||
import { useTranslate } from 'react-polyglot' | ||
|
||
import { OrderDirection } from './types' | ||
|
||
type OrderDropdownProps = { | ||
value: OrderDirection | ||
onClick: (arg: OrderDirection) => void | ||
buttonProps?: ButtonProps | ||
} | ||
|
||
const width = { base: 'full', md: 'auto' } | ||
|
||
const chevronDownIcon = <ChevronDownIcon /> | ||
|
||
export const OrderDropdown: React.FC<OrderDropdownProps> = ({ onClick, value, buttonProps }) => { | ||
const translate = useTranslate() | ||
|
||
const renderOptions = useMemo(() => { | ||
return Object.values(OrderDirection).map(option => ( | ||
<MenuItemOption value={option} key={option}> | ||
{translate(`common.${option}`)} | ||
</MenuItemOption> | ||
)) | ||
}, [translate]) | ||
|
||
const onChange = useCallback( | ||
(value: string | string[]) => onClick(value as OrderDirection), | ||
[onClick], | ||
) | ||
|
||
const selectedLabel = useMemo(() => { | ||
const selectedOption = Object.values(OrderDirection).find(option => option === value) | ||
return selectedOption ? translate(`common.${selectedOption}`) : '' | ||
}, [translate, value]) | ||
|
||
return ( | ||
<Flex alignItems='center' mx={2}> | ||
<Text me={4}>{translate('common.orderBy')}</Text> | ||
<Menu> | ||
<MenuButton width={width} as={Button} rightIcon={chevronDownIcon} {...buttonProps}> | ||
{selectedLabel} | ||
</MenuButton> | ||
<MenuList zIndex='banner'> | ||
<MenuOptionGroup type='radio' value={value} onChange={onChange}> | ||
{renderOptions} | ||
</MenuOptionGroup> | ||
</MenuList> | ||
</Menu> | ||
</Flex> | ||
) | ||
} |
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,4 @@ | ||
export enum OrderDirection { | ||
Ascending = 'ascending', | ||
Descending = 'descending', | ||
} |
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,70 @@ | ||
import { ChevronDownIcon } from '@chakra-ui/icons' | ||
import type { ButtonProps } from '@chakra-ui/react' | ||
import { | ||
Button, | ||
Flex, | ||
Menu, | ||
MenuButton, | ||
MenuItemOption, | ||
MenuList, | ||
MenuOptionGroup, | ||
Text, | ||
} from '@chakra-ui/react' | ||
import { useCallback, useMemo } from 'react' | ||
import { useTranslate } from 'react-polyglot' | ||
|
||
import type { SortOptionsKeys } from './types' | ||
|
||
type SortDropdownProps = { | ||
value: SortOptionsKeys | ||
onClick: (arg: SortOptionsKeys) => void | ||
buttonProps?: ButtonProps | ||
options: SortOptionsKeys[] | ||
} | ||
|
||
const width = { base: 'full', md: 'auto' } | ||
|
||
const chevronDownIcon = <ChevronDownIcon /> | ||
|
||
export const SortDropdown: React.FC<SortDropdownProps> = ({ | ||
onClick, | ||
value, | ||
buttonProps, | ||
options, | ||
}) => { | ||
const translate = useTranslate() | ||
|
||
const renderOptions = useMemo(() => { | ||
return options.map(option => ( | ||
<MenuItemOption value={option} key={option}> | ||
{translate(`dashboard.portfolio.${option}`)} | ||
</MenuItemOption> | ||
)) | ||
}, [translate, options]) | ||
|
||
const onChange = useCallback( | ||
(value: string | string[]) => onClick(value as SortOptionsKeys), | ||
[onClick], | ||
) | ||
|
||
const selectedLabel = useMemo(() => { | ||
const selectedOption = options.find(option => option === value) | ||
return selectedOption ? translate(`dashboard.portfolio.${selectedOption}`) : '' | ||
}, [translate, value, options]) | ||
|
||
return ( | ||
<Flex alignItems='center' mx={2}> | ||
<Text me={4}>{translate('common.sortBy')}</Text> | ||
<Menu> | ||
<MenuButton width={width} as={Button} rightIcon={chevronDownIcon} {...buttonProps}> | ||
{selectedLabel} | ||
</MenuButton> | ||
<MenuList zIndex='banner'> | ||
<MenuOptionGroup type='radio' value={value} onChange={onChange}> | ||
{renderOptions} | ||
</MenuOptionGroup> | ||
</MenuList> | ||
</Menu> | ||
</Flex> | ||
) | ||
} |
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,6 @@ | ||
export enum SortOptionsKeys { | ||
Apy = 'apy', | ||
Volume = 'volume', | ||
MarketCap = 'marketCap', | ||
PriceChange = 'priceChange', | ||
} |
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
Oops, something went wrong.