|
1 | | -/* eslint-disable */ |
2 | | -import { useState, useEffect } from 'react'; |
3 | 1 | import { useSelector } from 'react-redux'; |
4 | 2 | import { useHistory } from 'react-router-dom'; |
5 | | -import { MapContainer, TileLayer } from 'react-leaflet'; |
6 | | -import MarkerClusterGroup from '@changey/react-leaflet-markercluster'; |
7 | | -import axios from 'axios'; |
8 | | -import { ENDPOINTS } from '../../../utils/URL'; |
9 | | -import { |
10 | | - MapThemeUpdater, |
11 | | - ProjectMarkers, |
12 | | - MapUtils, |
13 | | - MapLegend, |
14 | | - ProjectCounter, |
15 | | -} from './MapSharedComponents'; |
| 3 | +import { useProjectsData } from '../../../hooks/useProjectsData'; |
| 4 | +import BaseInteractiveMap from './BaseInteractiveMap'; |
16 | 5 |
|
17 | 6 | function EmbedInteractiveMap() { |
18 | 7 | const darkMode = useSelector(state => state.theme.darkMode); |
19 | 8 | const history = useHistory(); |
20 | | - const [orgs, setOrgs] = useState([]); |
21 | | - const [loading, setLoading] = useState(true); |
22 | | - |
23 | | - const fetchOrgs = async () => { |
24 | | - try { |
25 | | - let response; |
26 | | - try { |
27 | | - response = await axios.get(ENDPOINTS.BM_PROJECTS_WITH_LOCATION); |
28 | | - } catch (projectError) { |
29 | | - console.log('Projects with location endpoint not available, using organization data'); |
30 | | - response = await axios.get(ENDPOINTS.BM_ORGS_WITH_LOCATION); |
31 | | - } |
32 | | - |
33 | | - const data = response.data.data || []; |
34 | | - |
35 | | - if (data.length === 0) { |
36 | | - console.log('No data from backend, using pseudo data'); |
37 | | - const pseudoData = MapUtils.getPseudoOrgs(); |
38 | | - setOrgs(pseudoData); |
39 | | - } else { |
40 | | - setOrgs(data); |
41 | | - } |
42 | | - return data; |
43 | | - } catch (error) { |
44 | | - console.error('Error fetching project/org data:', error); |
45 | | - const pseudoData = MapUtils.getPseudoOrgs(); |
46 | | - setOrgs(pseudoData); |
47 | | - return []; |
48 | | - } finally { |
49 | | - setLoading(false); |
50 | | - } |
51 | | - }; |
| 9 | + const { orgs, loading } = useProjectsData(); |
52 | 10 |
|
53 | 11 | const handleProjectClick = org => { |
54 | 12 | history.push(`/bmdashboard/projects/${org.orgId}`); |
55 | 13 | }; |
56 | 14 |
|
57 | | - useEffect(() => { |
58 | | - fetchOrgs(); |
59 | | - }, []); |
60 | | - |
61 | 15 | return ( |
62 | | - <div |
63 | | - style={{ |
64 | | - width: '100%', |
65 | | - height: '100%', |
66 | | - position: 'relative', |
67 | | - overflow: 'hidden', |
68 | | - background: darkMode ? '#0d1b2a' : 'white', |
69 | | - }} |
70 | | - > |
71 | | - <ProjectCounter |
72 | | - count={orgs.length} |
73 | | - darkMode={darkMode} |
74 | | - position="bottomleft" |
75 | | - isEmbed={true} |
76 | | - /> |
77 | | - <MapLegend position="bottomleft" darkMode={darkMode} isEmbed={true} /> |
78 | | - |
79 | | - <MapContainer |
80 | | - center={[20, 0]} |
81 | | - maxBounds={[ |
82 | | - [-90, -180], |
83 | | - [90, 180], |
84 | | - ]} |
85 | | - maxBoundsViscosity={1.0} |
86 | | - zoom={1} |
87 | | - minZoom={1} |
88 | | - scrollWheelZoom |
89 | | - style={{ |
90 | | - width: '100%', |
91 | | - height: '100%', |
92 | | - borderRadius: '8px', |
93 | | - }} |
94 | | - worldCopyJump |
95 | | - > |
96 | | - <MapThemeUpdater darkMode={darkMode} /> |
97 | | - <TileLayer |
98 | | - noWrap={false} |
99 | | - attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' |
100 | | - url={ |
101 | | - darkMode |
102 | | - ? 'https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png' |
103 | | - : 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png' |
104 | | - } |
105 | | - minZoom={1} |
106 | | - maxZoom={15} |
107 | | - /> |
108 | | - <MarkerClusterGroup |
109 | | - disableClusteringAtZoom={13} |
110 | | - spiderfyOnMaxZoom={true} |
111 | | - chunkedLoading={true} |
112 | | - maxClusterRadius={80} |
113 | | - > |
114 | | - <ProjectMarkers |
115 | | - orgs={orgs} |
116 | | - darkMode={darkMode} |
117 | | - onProjectClick={handleProjectClick} |
118 | | - markerRadius={6} |
119 | | - /> |
120 | | - </MarkerClusterGroup> |
121 | | - </MapContainer> |
122 | | - </div> |
| 16 | + <BaseInteractiveMap |
| 17 | + orgs={orgs} |
| 18 | + loading={loading} |
| 19 | + darkMode={darkMode} |
| 20 | + onProjectClick={handleProjectClick} |
| 21 | + isEmbed={true} |
| 22 | + center={[20, 0]} |
| 23 | + zoom={1} |
| 24 | + minZoom={1} |
| 25 | + maxClusterRadius={80} |
| 26 | + markerRadius={6} |
| 27 | + position="bottomleft" |
| 28 | + /> |
123 | 29 | ); |
124 | 30 | } |
125 | 31 |
|
|
0 commit comments