mirror of
https://github.com/umami-software/umami.git
synced 2026-02-14 17:45:38 +01:00
Added website and team providers.
This commit is contained in:
parent
dbb3801e66
commit
cc273092d5
25 changed files with 123 additions and 98 deletions
|
|
@ -1,6 +0,0 @@
|
|||
'use client';
|
||||
import { createContext } from 'react';
|
||||
|
||||
export const WebsiteContext = createContext(null);
|
||||
|
||||
export default WebsiteContext;
|
||||
32
src/app/(main)/websites/[websiteId]/WebsiteProvider.tsx
Normal file
32
src/app/(main)/websites/[websiteId]/WebsiteProvider.tsx
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
'use client';
|
||||
import { createContext, ReactNode, useEffect } from 'react';
|
||||
import { useWebsite } from 'components/hooks';
|
||||
import { Loading } from 'react-basics';
|
||||
import useModified from 'store/modified';
|
||||
|
||||
export const WebsiteContext = createContext(null);
|
||||
|
||||
export function WebsiteProvider({
|
||||
websiteId,
|
||||
children,
|
||||
}: {
|
||||
websiteId: string;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
const modified = useModified(state => state?.[`website:${websiteId}`]);
|
||||
const { data: website, isFetching, isLoading, refetch } = useWebsite(websiteId);
|
||||
|
||||
useEffect(() => {
|
||||
if (modified) {
|
||||
refetch();
|
||||
}
|
||||
}, [modified]);
|
||||
|
||||
if (isFetching && isLoading) {
|
||||
return <Loading position="page" />;
|
||||
}
|
||||
|
||||
return <WebsiteContext.Provider value={website}>{children}</WebsiteContext.Provider>;
|
||||
}
|
||||
|
||||
export default WebsiteProvider;
|
||||
Loading…
Add table
Add a link
Reference in a new issue