-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathApp.tsx
More file actions
78 lines (70 loc) · 2.55 KB
/
App.tsx
File metadata and controls
78 lines (70 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { useEffect, useState } from 'react';
import { Header } from '@/components/Layout/Header';
import { MapContainer } from '@/components/Map/MapContainer';
import { LayerControls } from '@/components/Map/LayerControls';
import { ProjectDetailView } from '@/components/Project/ProjectDetailView';
import '@/styles/globals.css';
import '@/styles/map.css';
import { FixtureReader } from './data/fixture-reader';
import { getProjectData } from './types/project';
import type { LayerVisibilityMap } from './types/map';
import type { FeatureCollection } from './types/geometry';
import type { ProjectData } from './types/project';
/**
* Main application component that composes the entire UI
* Manages the map state, layer visibility, and project detail view
* @component
* @returns {JSX.Element} The complete application layout
*/
function App() {
const [layers, setLayers] = useState<FeatureCollection[]>([])
const [layerVisibility, setLayerVisibility] = useState<LayerVisibilityMap>({})
const [selectedProject, setSelectedProject] = useState<ProjectData | null>(null)
useEffect(() => {
FixtureReader.collections()
.then(collections => {
setLayers([...collections])
// Take the name property of each collection and set it's initial visibility to true
const layerNames = collections.map((fc) => fc.name )
const visibilityMap = layerNames.reduce((map, name) => { map[name] = true; return map }, {} as LayerVisibilityMap)
setLayerVisibility({...visibilityMap})
},)
}, [])
const layersToRender = layers.filter((fc) => layerVisibility[fc.name])
/**
* Handle map marker/feature click — opens the project detail view
*/
const handleFeatureClick = (featureName: string) => {
const projectData = getProjectData(featureName);
setSelectedProject(projectData);
};
/**
* Close the project detail view and restore full map
*/
const handleCloseDetail = () => {
setSelectedProject(null);
};
return (
<div className="app-container">
<Header />
<main className={`main-content ${selectedProject ? 'main-content--detail-open' : ''}`}>
<MapContainer
layers={layersToRender}
onFeatureClick={handleFeatureClick}
/>
{/*<MapLegend />*/}
<LayerControls
visibilityMap={layerVisibility}
onLayerChange={setLayerVisibility}
/>
</main>
{selectedProject && (
<ProjectDetailView
project={selectedProject}
onClose={handleCloseDetail}
/>
)}
</div>
);
}
export default App;