-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Fix: User navigates to many pages when quickly press them #34861
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
48d422a
fix: add singleExecution for menu items
tienifr b81373f
disable when is executing
tienifr 3a7ef96
Merge branch 'main' of https://github.com/tienifr/App into fix/32753
tienifr d2f5a1d
context approach
tienifr ddffc25
remove redundant imports
tienifr 5b440b7
fix lint
tienifr f96ae97
execute singleExecution
tienifr 14a1e91
Merge branch 'main' into fix/32753
tienifr 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 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,35 @@ | ||
import React, {createContext, useMemo} from 'react'; | ||
import useSingleExecution from '@hooks/useSingleExecution'; | ||
import type {Action} from '@hooks/useSingleExecution'; | ||
import useWaitForNavigation from '@hooks/useWaitForNavigation'; | ||
|
||
type MenuItemGroupContextProps = { | ||
isExecuting: boolean; | ||
singleExecution: <T extends unknown[]>(action?: Action<T> | undefined) => (...params: T) => void; | ||
waitForNavigate: ReturnType<typeof useWaitForNavigation>; | ||
}; | ||
|
||
const MenuItemGroupContext = createContext<MenuItemGroupContextProps | undefined>(undefined); | ||
|
||
type MenuItemGroupProps = { | ||
/* Actual content wrapped by this component */ | ||
children: React.ReactNode; | ||
|
||
/** Whether or not to use the single execution hook */ | ||
shouldUseSingleExecution?: boolean; | ||
}; | ||
|
||
function MenuItemGroup({children, shouldUseSingleExecution = true}: MenuItemGroupProps) { | ||
const {isExecuting, singleExecution} = useSingleExecution(); | ||
const waitForNavigate = useWaitForNavigation(); | ||
|
||
const value = useMemo( | ||
() => (shouldUseSingleExecution ? {isExecuting, singleExecution, waitForNavigate} : undefined), | ||
[shouldUseSingleExecution, isExecuting, singleExecution, waitForNavigate], | ||
); | ||
|
||
return <MenuItemGroupContext.Provider value={value}>{children}</MenuItemGroupContext.Provider>; | ||
} | ||
|
||
export {MenuItemGroupContext}; | ||
export default MenuItemGroup; |
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.
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.
When does this ever get set to false?
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.
This is just like what we did in MenuItemList here. I can remove it without any problem.