29 lines
906 B
TypeScript
29 lines
906 B
TypeScript
import { createContext, useContext } from "react";
|
|
import type { SightingType } from "../types/types";
|
|
|
|
type SightingFeedContextType = {
|
|
sightings: (SightingType | null | undefined)[];
|
|
selectedRef: number | null;
|
|
setSelectedRef: (ref: number | null) => void;
|
|
// effectiveSelected: SightingType | null;
|
|
mostRecent: SightingType | null;
|
|
side: string;
|
|
selectedSighting: SightingType | null;
|
|
setSelectedSighting: (sighting: SightingType | SightingType | null) => void;
|
|
setSightingModalOpen: (isSightingModalOpen: boolean) => void;
|
|
isSightingModalOpen: boolean;
|
|
};
|
|
|
|
export const SightingFeedContext = createContext<
|
|
SightingFeedContextType | undefined
|
|
>(undefined);
|
|
|
|
export const useSightingFeedContext = () => {
|
|
const ctx = useContext(SightingFeedContext);
|
|
if (!ctx)
|
|
throw new Error(
|
|
"useSightingFeedContext must be used within SightingFeedProvider"
|
|
);
|
|
return ctx;
|
|
};
|