forked from MyZubster-Ecosystem/myzubster
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapPage.js
More file actions
119 lines (107 loc) 路 3.74 KB
/
Copy pathMapPage.js
File metadata and controls
119 lines (107 loc) 路 3.74 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import React, { useState, useEffect } from 'react';
import PlantMap from '../components/Map/PlantMap';
import { getPlants } from '../api/plants';
const MapPage = () => {
const [plants, setPlants] = useState([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
const [filters, setFilters] = useState({
species: '',
size: '',
status: 'verified'
});
useEffect(() => {
fetchPlants();
}, [filters]);
const fetchPlants = async () => {
setLoading(true);
try {
const data = await getPlants(filters);
setPlants(data.plants || []);
setError(null);
} catch (err) {
setError('Failed to load plants');
console.error(err);
} finally {
setLoading(false);
}
};
const handleFilterChange = (key, value) => {
setFilters(prev => ({ ...prev, [key]: value }));
};
const handlePlantClick = (plant) => {
console.log('Selected plant:', plant);
};
if (loading) {
return (
<div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '400px' }}>
<div>Loading plants...</div>
</div>
);
}
if (error) {
return (
<div style={{ color: 'red', textAlign: 'center', padding: '20px' }}>
{error}
</div>
);
}
return (
<div style={{ padding: '20px' }}>
<h1>馃實 Global Plant Map</h1>
<p>Showing {plants.length} plants worldwide</p>
{/* Filtri */}
<div style={{ display: 'flex', gap: '10px', marginBottom: '20px', flexWrap: 'wrap' }}>
<input
type="text"
placeholder="Filter by species..."
value={filters.species}
onChange={(e) => handleFilterChange('species', e.target.value)}
style={{ padding: '8px', border: '1px solid #ccc', borderRadius: '4px' }}
/>
<select
value={filters.size}
onChange={(e) => handleFilterChange('size', e.target.value)}
style={{ padding: '8px', border: '1px solid #ccc', borderRadius: '4px' }}
>
<option value="">All Sizes</option>
<option value="seedling">Seedling</option>
<option value="small">Small</option>
<option value="medium">Medium</option>
<option value="ancient">Ancient</option>
</select>
<select
value={filters.status}
onChange={(e) => handleFilterChange('status', e.target.value)}
style={{ padding: '8px', border: '1px solid #ccc', borderRadius: '4px' }}
>
<option value="verified">Verified Only</option>
<option value="all">All</option>
<option value="pending">Pending</option>
<option value="rejected">Rejected</option>
</select>
<button
onClick={fetchPlants}
style={{ padding: '8px 16px', background: '#4CAF50', color: 'white', border: 'none', borderRadius: '4px', cursor: 'pointer' }}
>
Refresh
</button>
</div>
{/* Mappa */}
<PlantMap plants={plants} onPlantClick={handlePlantClick} />
{/* Statistiche */}
<div style={{ marginTop: '20px', display: 'flex', gap: '20px', flexWrap: 'wrap' }}>
<div style={{ padding: '10px', background: '#f0f0f0', borderRadius: '4px' }}>
<strong>Total:</strong> {plants.length}
</div>
<div style={{ padding: '10px', background: '#e8f5e9', borderRadius: '4px' }}>
<strong>Verified:</strong> {plants.filter(p => p.status === 'verified').length}
</div>
<div style={{ padding: '10px', background: '#fff3e0', borderRadius: '4px' }}>
<strong>Pending:</strong> {plants.filter(p => p.status === 'pending').length}
</div>
</div>
</div>
);
};
export default MapPage;