-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): 🎸 show loader after remembered sheet click'
- Loading branch information
Thomas Clark
committed
Jun 23, 2023
1 parent
8425d30
commit 9bc6280
Showing
4 changed files
with
115 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { | ||
Modal, | ||
ModalContent, | ||
ModalOverlay, | ||
Spinner, | ||
Text, | ||
} from "@chakra-ui/react"; | ||
import { atom, useAtomValue, useSetAtom } from "jotai"; | ||
import { FC, useEffect } from "react"; | ||
|
||
const isGlobalLoadingAtom = atom(false); | ||
const globalLoadingMessageAtom = atom<string | undefined>(undefined); | ||
|
||
/** | ||
* To use this, just call `useGlobalLoading` in your component, | ||
* passing in a boolean for whether or not the global loader should | ||
* be shown and an optional message to display. | ||
*/ | ||
export const useGlobalLoading = (isLoading: boolean, message?: string) => { | ||
const setIsLoading = useSetAtom(isGlobalLoadingAtom); | ||
const setMessage = useSetAtom(globalLoadingMessageAtom); | ||
|
||
useEffect(() => { | ||
setIsLoading(isLoading); | ||
setMessage(message); | ||
}, [isLoading, message, setIsLoading, setMessage]); | ||
|
||
useEffect(() => { | ||
return () => { | ||
setIsLoading(false); | ||
setMessage(undefined); | ||
}; | ||
}, [setIsLoading, setMessage]); | ||
}; | ||
|
||
/** | ||
* Place this in your `_app.tsx` file | ||
*/ | ||
export const GlobalLoader: FC = () => { | ||
const isLoading = useAtomValue(isGlobalLoadingAtom); | ||
const message = useAtomValue(globalLoadingMessageAtom); | ||
|
||
return ( | ||
<Modal | ||
isOpen={isLoading} | ||
onClose={() => {}} | ||
closeOnOverlayClick={false} | ||
isCentered | ||
autoFocus={false} | ||
> | ||
<ModalOverlay /> | ||
<ModalContent | ||
bg="transparent" | ||
border="none" | ||
display="flex" | ||
flexDirection="column" | ||
alignItems="center" | ||
> | ||
<Spinner | ||
size="xl" | ||
emptyColor="gray.200" | ||
color="primary.500" | ||
thickness="4px" | ||
/> | ||
{message && ( | ||
<Text fontWeight="bold" mt="group"> | ||
{message} | ||
</Text> | ||
)} | ||
</ModalContent> | ||
</Modal> | ||
); | ||
}; |
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