aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/src/components/async/QueryOverlay.tsx
blob: 2a5848cf2dc790ef21c5b61c97898b293c492ce0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { FunctionComponent, ReactNode } from "react";
import { LoadingOverlay } from "@mantine/core";
import { UseQueryResult } from "@tanstack/react-query";
import { LoadingProvider } from "@/contexts";

interface QueryOverlayProps {
  result: UseQueryResult<unknown, unknown>;
  global?: boolean;
  children: ReactNode;
}

const QueryOverlay: FunctionComponent<QueryOverlayProps> = ({
  children,
  global = false,
  result: { isLoading, isError, error },
}) => {
  return (
    <LoadingProvider value={isLoading}>
      <LoadingOverlay visible={global && isLoading}></LoadingOverlay>
      {children}
    </LoadingProvider>
  );
};

export default QueryOverlay;