mirror of
https://github.com/umami-software/umami.git
synced 2026-02-20 20:45:39 +01:00
21 lines
678 B
TypeScript
21 lines
678 B
TypeScript
'use client';
|
|
import { Loading } from '@umami/react-zen';
|
|
import { createContext, type ReactNode } from 'react';
|
|
import { usePixelQuery } from '@/components/hooks/queries/usePixelQuery';
|
|
import type { Pixel } from '@/generated/prisma/client';
|
|
|
|
export const PixelContext = createContext<Pixel>(null);
|
|
|
|
export function PixelProvider({ pixelId, children }: { pixelId?: string; children: ReactNode }) {
|
|
const { data: pixel, isLoading, isFetching } = usePixelQuery(pixelId);
|
|
|
|
if (isFetching && isLoading) {
|
|
return <Loading placement="absolute" />;
|
|
}
|
|
|
|
if (!pixel) {
|
|
return null;
|
|
}
|
|
|
|
return <PixelContext.Provider value={pixel}>{children}</PixelContext.Provider>;
|
|
}
|