import React, { createContext, useContext, ReactNode } from 'react'; import useSpaces from '../hooks/useSpaces'; import { Space, Memo, CreateSpaceRequest, UpdateSpaceRequest } from '../services/spaceService'; // Define the context shape interface SpaceContextType { spaces: Space[]; isLoading: boolean; error: string | null; fetchSpaces: () => Promise; createSpace: (spaceData: CreateSpaceRequest) => Promise; updateSpace: (spaceId: string, spaceData: UpdateSpaceRequest) => Promise; deleteSpace: (spaceId: string) => Promise; leaveSpace: (spaceId: string) => Promise; getSpace: (spaceId: string) => Promise; getSpaceMemos: (spaceId: string) => Promise; linkMemoToSpace: (memoId: string, spaceId: string) => Promise; unlinkMemoFromSpace: (memoId: string, spaceId: string) => Promise; } // Create the context export const SpaceContext = createContext(undefined); // Create provider component export const SpaceProvider: React.FC<{ children: ReactNode }> = ({ children }) => { const spacesMethods = useSpaces(); return ( {children} ); }; // Custom hook to use the space context export const useSpaceContext = () => { const context = useContext(SpaceContext); if (context === undefined) { throw new Error('useSpaceContext must be used within a SpaceProvider'); } return context; }; export default SpaceProvider;