diff options
Diffstat (limited to 'src/app/(main)/websites/WebsiteProvider.tsx')
| -rw-r--r-- | src/app/(main)/websites/WebsiteProvider.tsx | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/app/(main)/websites/WebsiteProvider.tsx b/src/app/(main)/websites/WebsiteProvider.tsx new file mode 100644 index 0000000..75e8a35 --- /dev/null +++ b/src/app/(main)/websites/WebsiteProvider.tsx @@ -0,0 +1,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>; +} |