-
Notifications
You must be signed in to change notification settings - Fork 199
feat: add pull down to refresh portfolio and tx history data #11314
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
Draft
NeOMakinG
wants to merge
4
commits into
develop
Choose a base branch
from
pull-down-refresh-accounts
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7113d30
feat: add pull down to refresh portfolio and tx history data
NeOMakinG 3f499c3
Merge branch 'develop' into pull-down-refresh-accounts
NeOMakinG 7e8356b
Merge branch 'develop' into pull-down-refresh-accounts
NeOMakinG 8f04415
fix: maybe better like this
NeOMakinG File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,124 @@ | ||
| import { | ||
| Box, | ||
| Flex, | ||
| Progress, | ||
| Spinner, | ||
| Text, | ||
| useColorModeValue, | ||
| } from '@chakra-ui/react' | ||
| import type { ReactNode } from 'react' | ||
| import { useMemo } from 'react' | ||
| import { FiRefreshCw } from 'react-icons/fi' | ||
| import { useTranslate } from 'react-polyglot' | ||
| import { usePullToRefresh } from 'use-pull-to-refresh' | ||
|
|
||
| type PullToRefreshListProps = { | ||
| children: ReactNode | ||
| onRefresh: () => void | Promise<void> | ||
| isRefreshing?: boolean | ||
| } | ||
|
|
||
| export const PullToRefreshList: React.FC<PullToRefreshListProps> = ({ | ||
| children, | ||
| onRefresh, | ||
| isRefreshing = false, | ||
| }) => { | ||
| const translate = useTranslate() | ||
| const progressColor = useColorModeValue('blue.500', 'blue.400') | ||
| const textColor = useColorModeValue('gray.700', 'gray.200') | ||
|
|
||
| const { isRefreshing: isPulling, pullPosition } = usePullToRefresh({ | ||
| onRefresh, | ||
| maximumPullLength: 150, | ||
| refreshThreshold: 100, | ||
| }) | ||
|
|
||
| const pullProgress = useMemo(() => { | ||
| return Math.min(pullPosition / 100, 1) | ||
| }, [pullPosition]) | ||
|
|
||
| const indicatorOpacity = useMemo(() => { | ||
| return Math.min(pullPosition / 40, 1) | ||
| }, [pullPosition]) | ||
|
|
||
| const displayText = useMemo(() => { | ||
| if (isRefreshing) return translate('pullToRefresh.refreshing') | ||
| if (pullProgress >= 1) return translate('pullToRefresh.releaseToRefresh') | ||
| if (pullProgress > 0.2) return translate('pullToRefresh.pullToRefresh') | ||
| return '' | ||
| }, [isRefreshing, pullProgress, translate]) | ||
|
|
||
| const iconRotation = useMemo(() => { | ||
| return isRefreshing ? 0 : pullProgress * 360 | ||
| }, [isRefreshing, pullProgress]) | ||
|
|
||
| const showIndicator = pullPosition > 0 || isRefreshing | ||
|
|
||
| return ( | ||
| <Box position='relative' height='100%' overflow='auto'> | ||
| {/* Pull indicator */} | ||
| {showIndicator && ( | ||
| <Box | ||
| position='absolute' | ||
| top={0} | ||
| left={0} | ||
| right={0} | ||
| height='90px' | ||
| display='flex' | ||
| alignItems='center' | ||
| justifyContent='center' | ||
| pointerEvents='none' | ||
| opacity={indicatorOpacity} | ||
| transform={`translateY(${Math.min(pullPosition - 90, 0)}px)`} | ||
| transition='opacity 0.2s ease-out' | ||
| zIndex={10} | ||
| > | ||
| <Flex direction='column' align='center' justify='center' gap={2}> | ||
| <Box> | ||
| {isRefreshing ? ( | ||
| <Spinner size='sm' color={progressColor} thickness='2px' speed='0.8s' /> | ||
| ) : ( | ||
| <Box | ||
| as={FiRefreshCw} | ||
| fontSize='24px' | ||
| color={progressColor} | ||
| transform={`rotate(${iconRotation}deg)`} | ||
| transition='transform 0.1s ease-out' | ||
| /> | ||
| )} | ||
| </Box> | ||
|
|
||
| <Box | ||
|
Check failure on line 91 in src/components/PullToRefresh/PullToRefreshList.tsx
|
||
| width='100%' | ||
| maxWidth='180px' | ||
| height='3px' | ||
| bg='whiteAlpha.200' | ||
| borderRadius='full' | ||
| > | ||
| {!isRefreshing && ( | ||
| <Box | ||
| height='100%' | ||
| bg={progressColor} | ||
| borderRadius='full' | ||
| width={`${pullProgress * 100}%`} | ||
| transition='width 0.1s ease-out' | ||
| boxShadow={pullProgress >= 1 ? `0 0 8px ${progressColor}` : 'none'} | ||
| /> | ||
| )} | ||
| {isRefreshing && <Progress isIndeterminate={true} size='xs' colorScheme='blue' />} | ||
| </Box> | ||
|
|
||
| {displayText && ( | ||
| <Text fontSize='xs' fontWeight='medium' color={textColor}> | ||
| {displayText} | ||
| </Text> | ||
| )} | ||
| </Flex> | ||
| </Box> | ||
| )} | ||
|
|
||
| {/* Content with dynamic padding to reveal indicator */} | ||
| <Box paddingTop={showIndicator ? `${Math.min(pullPosition, 90)}px` : 0}>{children}</Box> | ||
| </Box> | ||
| ) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Memoize the derived isRefreshing value.
The
isRefreshingvalue is computed from multiple state sources and recalculates on every render. Per coding guidelines, derived values should be wrapped inuseMemo.Apply this diff:
📝 Committable suggestion
🤖 Prompt for AI Agents