refactore: cleanup __root.tsx

This commit is contained in:
Prayag Prajapati committed 2024-12-03 18:13:36 +05:30
1 parent 561daa7d81
commit e049ce9ad6
10 files changed
+274 -256

No files matched your search

+34 -21
View File
@@ -1,27 +1,40 @@
import { LinearProgress } from "@mui/material";
import { useNProgress } from "@tanem/react-nprogress";
import React from "react";
import { useIsFetching, useIsMutating } from "@tanstack/react-query";
import { useRouterState } from "@tanstack/react-router";
import React, { useMemo } from "react";
import { createPortal } from "react-dom";
export default function NProgress() {
const isQueryFetching = useIsFetching();
const isMutating = useIsMutating();
const routeIsLoading = useRouterState().isLoading;
const isAnimating = useMemo(() => {
if (isQueryFetching || isMutating || routeIsLoading) {
return true;
}
return false;
}, [isQueryFetching, isMutating, routeIsLoading]);
const NProgress: React.FC<{ isAnimating: boolean | number }> = ({
isAnimating,
}) => {
const { animationDuration, isFinished, progress } = useNProgress({
isAnimating,
});
if (isAnimating) {
return (
<div
style={{
pointerEvents: "none",
transition: `opacity ${animationDuration}ms linear`,
position: "fixed",
top: "0",
left: "0",
right: "0",
zIndex: "10001",
}}
>
return createPortal(
<div
style={{
pointerEvents: "none",
transition: "opacity 250ms linear",
position: "fixed",
top: "0",
left: "0",
right: "0",
zIndex: "10001",
opacity: isFinished ? 0 : 1,
}}
>
{isAnimating && (
<LinearProgress
sx={{
height: 3,
@@ -30,9 +43,9 @@ const NProgress: React.FC<{ isAnimating: boolean | number }> = ({
value={progress * 100}
variant="determinate"
/>
</div>
);
}
)}
</div>,
document.body,
);
};
export default NProgress;