aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/src/components/async/QueryOverlay.tsx
blob: 24b95ab189a171826c62f90ef67c7ce1787b8955 (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 { LoadingProvider } from "@/contexts";
import { LoadingOverlay } from "@mantine/core";
import { FunctionComponent, ReactNode } from "react";
import { UseQueryResult } from "react-query";

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;