aboutsummaryrefslogtreecommitdiff
path: root/src/app/(main)/websites/WebsiteProvider.tsx
blob: 75e8a3582f7317a53e376dbc412a19628c090257 (plain) (blame)
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
26
27
'use client';
import { Loading } from '@umami/react-zen';
import { createContext, type ReactNode } from 'react';
import { useWebsiteQuery } from '@/components/hooks/queries/useWebsiteQuery';
import type { Website } from '@/generated/prisma/client';

export const WebsiteContext = createContext<Website>(null);

export function WebsiteProvider({
  websiteId,
  children,
}: {
  websiteId: string;
  children: ReactNode;
}) {
  const { data: website, isFetching, isLoading } = useWebsiteQuery(websiteId);

  if (isFetching && isLoading) {
    return <Loading placement="absolute" />;
  }

  if (!website) {
    return null;
  }

  return <WebsiteContext.Provider value={website}>{children}</WebsiteContext.Provider>;
}