- Added LoadingContainer component to RootLayout for improved loading state management. - Refactored DebugPanel to include useEffect and removed unused code for better clarity and performance. These changes enhance user experience by providing a loading indicator and streamlining the debug interface. Signed-off-by: Innei <tukon479@gmail.com>
22 lines
577 B
TypeScript
22 lines
577 B
TypeScript
import { useSetAtom } from "jotai"
|
|
import { useCallback } from "react"
|
|
|
|
import { loadingAtom, loadingVisibleAtom } from "../atoms/app"
|
|
|
|
export const useLoadingCallback = () => {
|
|
const setLoadingCaller = useSetAtom(loadingAtom)
|
|
const setVisible = useSetAtom(loadingVisibleAtom)
|
|
|
|
return useCallback(
|
|
(thenable: Promise<any>, options: { finish: () => any; cancel: () => any }) => {
|
|
setLoadingCaller({
|
|
thenable,
|
|
finish: options.finish,
|
|
cancel: options.cancel,
|
|
})
|
|
setVisible(true)
|
|
},
|
|
[setLoadingCaller, setVisible],
|
|
)
|
|
}
|