turash/bugulma/frontend/contexts/MapInteractionContext.tsx
Damir Mukimov 6347f42e20
Consolidate repositories: Remove nested frontend .git and merge into main repository
- Remove nested git repository from bugulma/frontend/.git
- Add all frontend files to main repository tracking
- Convert from separate frontend/backend repos to unified monorepo
- Preserve all frontend code and development history as tracked files
- Eliminate nested repository complexity for simpler development workflow

This creates a proper monorepo structure with frontend and backend
coexisting in the same repository for easier development and deployment.
2025-11-25 06:02:57 +01:00

121 lines
3.9 KiB
TypeScript

/**
* Map Interaction Context
* Manages user interactions: selections, hovers, analysis results
* Separated from MapContexts.tsx for better SRP
*/
import React, { createContext, ReactNode, useCallback, useContext, useState } from 'react';
import type {
HistoricalLandmark,
Organization,
SymbiosisMatch,
WebIntelligenceResult,
} from '@/types.ts';
interface MapInteractionState {
// Organization interactions
selectedOrg: Organization | null;
hoveredOrgId: string | null;
// Landmark interactions
selectedLandmark: HistoricalLandmark | null;
hoveredLandmarkId: string | null;
// Analysis results
symbiosisResult: SymbiosisMatch[] | null;
isAnalyzing: boolean;
analysisError: string | null;
webIntelResult: WebIntelligenceResult | null;
isFetchingWebIntel: boolean;
webIntelError: string | null;
}
interface MapInteractionActions {
handleSelectOrg: (org: Organization | null) => void;
setHoveredOrgId: (id: string | null) => void;
handleSelectLandmark: (landmark: HistoricalLandmark | null) => void;
setHoveredLandmarkId: (id: string | null) => void;
setSymbiosisResult: (result: SymbiosisMatch[] | null) => void;
setIsAnalyzing: (analyzing: boolean) => void;
setAnalysisError: (error: string | null) => void;
setWebIntelResult: (result: WebIntelligenceResult | null) => void;
setIsFetchingWebIntel: (fetching: boolean) => void;
setWebIntelError: (error: string | null) => void;
clearAnalysisResults: () => void;
}
interface MapInteractionContextType extends MapInteractionState, MapInteractionActions {}
const MapInteractionContext = createContext<MapInteractionContextType | undefined>(undefined);
export const useMapInteraction = () => {
const context = useContext(MapInteractionContext);
if (context === undefined) {
throw new Error('useMapInteraction must be used within a MapInteractionProvider');
}
return context;
};
interface MapInteractionProviderProps {
children: ReactNode;
}
export const MapInteractionProvider = ({ children }: MapInteractionProviderProps) => {
// Organization interactions
const [selectedOrg, setSelectedOrg] = useState<Organization | null>(null);
const [hoveredOrgId, setHoveredOrgId] = useState<string | null>(null);
// Landmark interactions
const [selectedLandmark, setSelectedLandmark] = useState<HistoricalLandmark | null>(null);
const [hoveredLandmarkId, setHoveredLandmarkId] = useState<string | null>(null);
// Analysis state
const [symbiosisResult, setSymbiosisResult] = useState<SymbiosisMatch[] | null>(null);
const [isAnalyzing, setIsAnalyzing] = useState(false);
const [analysisError, setAnalysisError] = useState<string | null>(null);
const [webIntelResult, setWebIntelResult] = useState<WebIntelligenceResult | null>(null);
const [isFetchingWebIntel, setIsFetchingWebIntel] = useState(false);
const [webIntelError, setWebIntelError] = useState<string | null>(null);
const handleSelectOrg = useCallback((org: Organization | null) => {
setSelectedOrg(org);
}, []);
const handleSelectLandmark = useCallback((landmark: HistoricalLandmark | null) => {
setSelectedLandmark(landmark);
}, []);
const clearAnalysisResults = useCallback(() => {
setSymbiosisResult(null);
setWebIntelResult(null);
setAnalysisError(null);
setWebIntelError(null);
}, []);
const value: MapInteractionContextType = {
// State
selectedOrg,
hoveredOrgId,
selectedLandmark,
hoveredLandmarkId,
symbiosisResult,
isAnalyzing,
analysisError,
webIntelResult,
isFetchingWebIntel,
webIntelError,
// Actions
handleSelectOrg,
setHoveredOrgId,
handleSelectLandmark,
setHoveredLandmarkId,
setSymbiosisResult,
setIsAnalyzing,
setAnalysisError,
setWebIntelResult,
setIsFetchingWebIntel,
setWebIntelError,
clearAnalysisResults,
};
return <MapInteractionContext.Provider value={value}>{children}</MapInteractionContext.Provider>;
};