-
-
Notifications
You must be signed in to change notification settings - Fork 475
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(console): block page navigation when uploading custom ui assets
- Loading branch information
1 parent
c45a1a5
commit 04f0f9e
Showing
10 changed files
with
117 additions
and
24 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
48 changes: 48 additions & 0 deletions
48
packages/console/src/contexts/SignInExperienceContextProvider/index.tsx
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,48 @@ | ||
import { noop } from '@silverhand/essentials'; | ||
import { createContext, useMemo, useRef, useState } from 'react'; | ||
|
||
type SignInExperienceContextType = { | ||
isUploading: boolean; | ||
cancelUpload?: () => void; | ||
setIsUploading: (value: boolean) => void; | ||
setCancelUpload: (cancelFunction?: () => void) => void; | ||
}; | ||
|
||
type Props = { | ||
readonly children?: React.ReactNode; | ||
}; | ||
|
||
export const SignInExperienceContext = createContext<SignInExperienceContextType>({ | ||
isUploading: false, | ||
cancelUpload: noop, | ||
setIsUploading: noop, | ||
setCancelUpload: noop, | ||
}); | ||
|
||
function SignInExperienceContextProvider({ children }: Props) { | ||
const [isUploading, setIsUploading] = useState(false); | ||
const cancelUploadRef = useRef<() => void>(); | ||
|
||
const handleSetCancelUpload = (cancelFunction?: () => void) => { | ||
// eslint-disable-next-line @silverhand/fp/no-mutation | ||
cancelUploadRef.current = cancelFunction; | ||
}; | ||
|
||
const contextValue = useMemo( | ||
() => ({ | ||
isUploading, | ||
cancelUpload: cancelUploadRef.current, | ||
setIsUploading, | ||
setCancelUpload: handleSetCancelUpload, | ||
}), | ||
[isUploading] | ||
); | ||
|
||
return ( | ||
<SignInExperienceContext.Provider value={contextValue}> | ||
{children} | ||
</SignInExperienceContext.Provider> | ||
); | ||
} | ||
|
||
export default SignInExperienceContextProvider; |
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
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