-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix onboarding flash and progress animation (#2471)
* fix onboarding flash and progress animation * change provider name and add usememo
- Loading branch information
1 parent
48836b7
commit 7687292
Showing
9 changed files
with
143 additions
and
73 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React, { createContext, useCallback, useContext, useMemo, useState } from 'react'; | ||
|
||
import { ONBOARDING_PROGRESS_BAR_STEPS, StepName } from '~/components/Onboarding/constants'; | ||
|
||
type ProgressContextType = { | ||
from: number; | ||
to: number; | ||
setProgress: (stepName: StepName) => void; | ||
}; | ||
|
||
const ProgressContext = createContext<ProgressContextType | undefined>(undefined); | ||
|
||
export const OnboardingProgressProvider: React.FC<{ children: React.ReactNode }> = ({ | ||
children, | ||
}) => { | ||
const [progress, setProgressState] = useState({ from: 0, to: 0 }); | ||
|
||
const setProgress = useCallback((stepName: StepName) => { | ||
const step = ONBOARDING_PROGRESS_BAR_STEPS[stepName]; | ||
if (step) { | ||
setProgressState({ from: step.from, to: step.to }); | ||
} | ||
}, []); | ||
|
||
const contextValue = useMemo(() => ({ ...progress, setProgress }), [progress, setProgress]); | ||
|
||
return <ProgressContext.Provider value={contextValue}>{children}</ProgressContext.Provider>; | ||
}; | ||
|
||
export const useProgress = () => { | ||
const context = useContext(ProgressContext); | ||
if (!context) { | ||
throw new Error('useProgress must be used within a OnboardingProgressProvider'); | ||
} | ||
return context; | ||
}; |
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.