134 lines
4.1 KiB
JavaScript
134 lines
4.1 KiB
JavaScript
import React, { useEffect, useState } from "react";
|
|
import { useRecoilValue } from "recoil";
|
|
import { gisStationsStaticDistrictState } from "../features/gisStationState";
|
|
import { gisSystemStaticState } from "../features/gisSystemState";
|
|
function DataSheet() {
|
|
// useState für uniqueAreas und stationListing
|
|
const [uniqueAreas, setUniqueAreas] = useState([]);
|
|
const [uniqueSystems, setUniqueSystems] = useState([]);
|
|
const [stationListing, setStationListing] = useState([]);
|
|
const [systemListing, setSystemListing] = useState([]);
|
|
const GisStationsStaticDistrict = useRecoilValue(
|
|
gisStationsStaticDistrictState
|
|
);
|
|
const GisSystemStatic = useRecoilValue(gisSystemStaticState);
|
|
|
|
useEffect(() => {
|
|
console.log(
|
|
"GisStationsStaticDistrict in DataSheet:",
|
|
GisStationsStaticDistrict
|
|
);
|
|
console.log("GisSystemStatic in DataSheet:", GisSystemStatic);
|
|
|
|
// Filtern der eindeutigen Gebiete (Areas) und alphabetisches Sortieren
|
|
const seenNames = new Set();
|
|
const filteredAreas = GisStationsStaticDistrict.filter((item) => {
|
|
const isUnique = !seenNames.has(item.Area_Name);
|
|
if (isUnique) {
|
|
seenNames.add(item.Area_Name);
|
|
}
|
|
return isUnique;
|
|
});
|
|
|
|
setUniqueAreas(filteredAreas);
|
|
|
|
const seenSystemNames = new Set();
|
|
const filteredSystems = GisSystemStatic.filter((item) => {
|
|
const isUnique = !seenSystemNames.has(item.Name);
|
|
if (isUnique) {
|
|
seenSystemNames.add(item.Name);
|
|
}
|
|
return isUnique;
|
|
});
|
|
|
|
setUniqueSystems(filteredSystems);
|
|
|
|
// Erzeugen von stationListing aus uniqueAreas und alphabetisches Sortieren
|
|
const newStationListing = filteredAreas
|
|
.map((area, index) => ({
|
|
id: index + 1, // Zuweisung einer eindeutigen ID
|
|
name: area.Area_Name,
|
|
}))
|
|
.sort((a, b) => a.name.localeCompare(b.name)); // Alphabetisches Sortieren der Namen
|
|
|
|
setStationListing(newStationListing);
|
|
|
|
//----------
|
|
const newSystemListing = filteredSystems.map((area, index) => ({
|
|
id: index + 1, // Zuweisung einer eindeutigen ID
|
|
name: area.Name,
|
|
}));
|
|
setSystemListing(newSystemListing);
|
|
console.log("System Listing:", systemListing);
|
|
}, [GisStationsStaticDistrict]);
|
|
|
|
const [checkedStations, setCheckedStations] = useState({});
|
|
|
|
const handleCheckboxChange = (id) => {
|
|
setCheckedStations((prev) => ({
|
|
...prev,
|
|
[id]: !prev[id],
|
|
}));
|
|
};
|
|
|
|
const handleStationChange = (event) => {
|
|
console.log("Station selected:", event.target.value);
|
|
};
|
|
|
|
const resetView = () => {
|
|
console.log("View has been reset");
|
|
};
|
|
|
|
return (
|
|
<div
|
|
id="mainDataSheet"
|
|
className="absolute top-3 right-3 w-1/6 min-w-[300px] z-10 bg-white p-2 rounded-lg shadow-lg"
|
|
>
|
|
<div className="flex flex-col gap-4 p-4">
|
|
<div className="flex items-center justify-between">
|
|
{/* Dropdown */}
|
|
<select
|
|
onChange={handleStationChange}
|
|
id="stationListing"
|
|
className="border-solid-1 p-2 rounded ml-1"
|
|
>
|
|
<option>Station wählen</option>
|
|
{stationListing.map((station) => (
|
|
<option key={station.id} value={station.id}>
|
|
{station.name}
|
|
</option>
|
|
))}
|
|
</select>
|
|
{/* Icon */}
|
|
<img
|
|
src="/img/expand-icon.svg"
|
|
alt="Expand"
|
|
className="h-6 w-6 ml-2"
|
|
/>
|
|
</div>
|
|
|
|
{/* Liste der Stationen mit Checkboxen */}
|
|
{systemListing.map((station) => (
|
|
<div key={station.id} className="flex items-center">
|
|
<input
|
|
type="checkbox"
|
|
id={`box-${station.id}`}
|
|
className="accent-blue-500 checked:bg-blue-500"
|
|
checked={checkedStations[station.id] || false}
|
|
onChange={() => handleCheckboxChange(station.id)}
|
|
/>
|
|
<label
|
|
htmlFor={`box-${station.id}`}
|
|
className="text-sm font-bold ml-2"
|
|
>
|
|
{station.name}
|
|
</label>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default DataSheet;
|