Added website and team providers.

This commit is contained in:
Mike Cao 2024-02-04 19:53:06 -08:00
parent dbb3801e66
commit cc273092d5
25 changed files with 123 additions and 98 deletions

View file

@ -1,6 +0,0 @@
'use client';
import { createContext } from 'react';
export const WebsiteContext = createContext(null);
export default WebsiteContext;

View 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;