import React, { createContext, useContext } from 'react'; import { OutCommandHandler } from '@/hooks/Mapper/types/mapHandlers.ts'; import { MapUnionTypes, SystemSignature } from '@/hooks/Mapper/types'; import { ContextStoreDataUpdate, useContextStore } from '@/hooks/Mapper/utils'; export type MapData = MapUnionTypes & { isConnecting: boolean; hoverNodeId: string | null; visibleNodes: Set; showKSpaceBG: boolean; isThickConnections: boolean; linkedSigEveId: string; localShowShipName: boolean; }; interface MapProviderProps { children: React.ReactNode; onCommand: OutCommandHandler; } const INITIAL_DATA: MapData = { wormholesData: {}, wormholes: [], effects: {}, characters: [], userCharacters: [], presentCharacters: [], systems: [], hubs: [], kills: {}, isConnecting: false, connections: [], hoverNodeId: null, linkedSigEveId: '', visibleNodes: new Set(), showKSpaceBG: false, isThickConnections: false, userPermissions: {}, systemSignatures: {} as Record, options: {} as Record, isSubscriptionActive: false, mainCharacterEveId: null, followingCharacterEveId: null, userHubs: [], pings: [], localShowShipName: false, }; export interface MapContextProps { update: ContextStoreDataUpdate; data: MapData; outCommand: OutCommandHandler; } const MapContext = createContext({ update: () => {}, data: { ...INITIAL_DATA }, // @ts-ignore outCommand: async () => void 0, }); export const MapProvider = ({ children, onCommand }: MapProviderProps) => { const { update, ref } = useContextStore({ ...INITIAL_DATA }); return ( {children} ); }; export const useMapState = () => { const context = useContext(MapContext); return context; };