All files / pages/collections CollectionDetailContext.tsx

83.33% Statements 5/6
50% Branches 1/2
100% Functions 2/2
83.33% Lines 5/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47                                      2x                     32x                   50x 50x     50x    
/**
 * Outlet context for collection detail tabs (full collection + list metadata).
 */
 
import { createContext, useContext, type ReactNode } from 'react';
import type {
  Collection,
  CollectionListItem,
} from '@/services/collections.service';
 
export interface CollectionDetailContextValue {
  collection: Collection | null;
  listItem: CollectionListItem | undefined;
  collectionName: string;
  loading: boolean;
  error: string | null;
  refreshDetail: () => Promise<void>;
}
 
const CollectionDetailContext = createContext<CollectionDetailContextValue | null>(
  null,
);
 
export function CollectionDetailProvider({
  value,
  children,
}: {
  value: CollectionDetailContextValue;
  children: ReactNode;
}) {
  return (
    <CollectionDetailContext.Provider value={value}>
      {children}
    </CollectionDetailContext.Provider>
  );
}
 
// Context hooks are co-located with providers (standard React pattern).
// eslint-disable-next-line react-refresh/only-export-components
export function useCollectionDetail() {
  const ctx = useContext(CollectionDetailContext);
  Iif (!ctx) {
    throw new Error('useCollectionDetail must be used within CollectionDetailProvider');
  }
  return ctx;
}