@@ -6,14 +6,16 @@ import { ICON_NAME } from "@p4b/ui/components/Icon";
66import { useTranslation } from "@/i18n/client" ;
77
88import { MAPBOX_TOKEN } from "@/lib/constants" ;
9- import { setActiveBasemap , setActiveLeftPanel , setActiveRightPanel } from "@/lib/store/map/slice" ;
9+ import { setActiveLeftPanel , setActiveRightPanel } from "@/lib/store/map/slice" ;
1010import { layerType } from "@/lib/validations/common" ;
1111import { FeatureName } from "@/lib/validations/organization" ;
12+ import type { Project } from "@/lib/validations/project" ;
1213
1314import { MapSidebarItemID } from "@/types/map/common" ;
1415
1516import { useAuthZ } from "@/hooks/auth/AuthZ" ;
1617import { useActiveLayer , useFilteredProjectLayers , useLayerActions } from "@/hooks/map/LayerPanelHooks" ;
18+ import { useBasemap } from "@/hooks/map/MapHooks" ;
1719import { useAppDispatch , useAppSelector } from "@/hooks/store/ContextHooks" ;
1820
1921import MapSidebar from "@/components/map/Sidebar" ;
@@ -35,20 +37,21 @@ const sidebarWidth = 52;
3537const toolbarHeight = 52 ;
3638
3739interface ProjectNavigationProps {
38- projectId : string ;
40+ project : Project ;
3941 isPublic ?: boolean ;
42+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
43+ onProjectUpdate ?: ( key : string , value : any , refresh ?: boolean ) => void ;
4044}
4145
42- const ProjectNavigation = ( { projectId } : ProjectNavigationProps ) => {
46+ const ProjectNavigation = ( { project , onProjectUpdate } : ProjectNavigationProps ) => {
4347 const theme = useTheme ( ) ;
44- const { t, i18n } = useTranslation ( "common" ) ;
48+ const { t } = useTranslation ( "common" ) ;
4549 const dispatch = useAppDispatch ( ) ;
46- const basemaps = useAppSelector ( ( state ) => state . map . basemaps ) ;
47- const activeBasemap = useAppSelector ( ( state ) => state . map . activeBasemap ) ;
50+ const projectId = project . id ;
51+ const { translatedBaseMaps , activeBasemap } = useBasemap ( project ) ;
4852 const activeLeft = useAppSelector ( ( state ) => state . map . activeLeftPanel ) ;
4953 const activeRight = useAppSelector ( ( state ) => state . map . activeRightPanel ) ;
5054 const { activeLayer } = useActiveLayer ( projectId ) ;
51-
5255 const prevActiveLeftRef = useRef < MapSidebarItemID | undefined > ( undefined ) ;
5356 const prevActiveRightRef = useRef < MapSidebarItemID | undefined > ( undefined ) ;
5457 const { isProjectEditor, isAppFeatureEnabled } = useAuthZ ( ) ;
@@ -75,17 +78,6 @@ const ProjectNavigation = ({ projectId }: ProjectNavigationProps) => {
7578 position : "left" ,
7679 } ;
7780
78- const translatedBaseMaps = useMemo ( ( ) => {
79- return basemaps . map ( ( basemap ) => ( {
80- ...basemap ,
81- title : i18n . exists ( `common:basemap_types.${ basemap . value } .title` )
82- ? t ( `basemap_types.${ basemap . value } .title` )
83- : t ( basemap . title ) ,
84- subtitle : i18n . exists ( `common:basemap_types.${ basemap . value } .subtitle` )
85- ? t ( `basemap_types.${ basemap . value } .subtitle` )
86- : t ( basemap . subtitle ) ,
87- } ) ) ;
88- } , [ basemaps , i18n , t ] ) ;
8981 const rightSidebar : MapSidebarProps = {
9082 topItems : [
9183 {
@@ -266,9 +258,9 @@ const ProjectNavigation = ({ projectId }: ProjectNavigationProps) => {
266258 < Stack direction = "column" sx = { { pointerEvents : "all" } } >
267259 < BasemapSelector
268260 styles = { translatedBaseMaps }
269- active = { activeBasemap }
270- basemapChange = { ( basemap ) => {
271- dispatch ( setActiveBasemap ( basemap ) ) ;
261+ active = { activeBasemap . value }
262+ basemapChange = { async ( basemap ) => {
263+ await onProjectUpdate ?. ( " basemap" , basemap ) ;
272264 } }
273265 />
274266 </ Stack >
0 commit comments