mirror of
https://github.com/umami-software/umami.git
synced 2025-12-06 01:18:00 +01:00
21 lines
648 B
TypeScript
21 lines
648 B
TypeScript
'use client';
|
|
import { createContext, ReactNode } from 'react';
|
|
import { Loading } from '@umami/react-zen';
|
|
import { Link } from '@/generated/prisma/client';
|
|
import { useLinkQuery } from '@/components/hooks/queries/useLinkQuery';
|
|
|
|
export const LinkContext = createContext<Link>(null);
|
|
|
|
export function LinkProvider({ linkId, children }: { linkId?: string; children: ReactNode }) {
|
|
const { data: link, isLoading, isFetching } = useLinkQuery(linkId);
|
|
|
|
if (isFetching && isLoading) {
|
|
return <Loading position="page" />;
|
|
}
|
|
|
|
if (!link) {
|
|
return null;
|
|
}
|
|
|
|
return <LinkContext.Provider value={link}>{children}</LinkContext.Provider>;
|
|
}
|