turash/bugulma/frontend/contexts/MapUIContext.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

69 lines
1.8 KiB
TypeScript

/**
* Map UI Context
* Manages UI state for the map view: sidebar, view modes, refs
* Separated from MapContexts.tsx for better SRP
*/
import React, { createContext, ReactNode, useCallback, useContext, useRef, useState } from 'react';
interface MapUIState {
isSidebarOpen: boolean;
mapViewMode: 'organizations' | 'historical';
addOrgButtonRef: React.RefObject<HTMLButtonElement>;
}
interface MapUIActions {
setIsSidebarOpen: (isOpen: boolean) => void;
setMapViewMode: (mode: 'organizations' | 'historical') => void;
toggleSidebar: () => void;
closeSidebar: () => void;
}
interface MapUIContextType extends MapUIState, MapUIActions {}
const MapUIContext = createContext<MapUIContextType | undefined>(undefined);
export const useMapUI = () => {
const context = useContext(MapUIContext);
if (context === undefined) {
throw new Error('useMapUI must be used within a MapUIProvider');
}
return context;
};
interface MapUIProviderProps {
children: ReactNode;
defaultViewMode?: 'organizations' | 'historical';
}
export const MapUIProvider = ({
children,
defaultViewMode = 'organizations',
}: MapUIProviderProps) => {
const [isSidebarOpen, setIsSidebarOpen] = useState(true);
const [mapViewMode, setMapViewMode] = useState<'organizations' | 'historical'>(defaultViewMode);
const addOrgButtonRef = useRef<HTMLButtonElement>(null);
const toggleSidebar = useCallback(() => {
setIsSidebarOpen((prev) => !prev);
}, []);
const closeSidebar = useCallback(() => {
setIsSidebarOpen(false);
}, []);
const value: MapUIContextType = {
// State
isSidebarOpen,
mapViewMode,
addOrgButtonRef,
// Actions
setIsSidebarOpen,
setMapViewMode,
toggleSidebar,
closeSidebar,
};
return <MapUIContext.Provider value={value}>{children}</MapUIContext.Provider>;
};