From 96b36eb706b6d8a801bc76cc683517517bccedf3 Mon Sep 17 00:00:00 2001 From: ISA Date: Fri, 23 May 2025 14:08:37 +0200 Subject: [PATCH] refactor: PoiUpdateModal auf Redux poiTypSlice umgestellt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - fetch(...) durch fetchPoiTypThunk ersetzt - Zugriff auf POI-Typen über selectPoiTypData - Code vereinheitlicht mit AddPOIModal.js - Version erhöht auf 1.1.160 --- CHANGELOG.md | 19 ++++++++++++++++ components/pois/PoiUpdateModal.js | 37 +++++++------------------------ config/appVersion.js | 2 +- 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bc63ec6e..f3954dc90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,25 @@ Alle bedeutenden Änderungen an diesem Projekt werden in dieser Datei dokumentie --- +## [1.1.160] – 2025-05-23 + +### ♻️ Refactor + +- `PoiUpdateModal.js` umgestellt auf Redux `poiTypSlice` +- Direkter `fetch("/api/talas_v5_DB/poiTyp/readPoiTyp")` entfernt +- POI-Typen jetzt über `fetchPoiTypThunk` geladen + +### 🧠 Architektur + +- POI-Typen einheitlich über Redux-Store statt lokalem State +- `poiTypData` kommt nun aus `selectPoiTypData` (Redux) + +### 🔧 Version + +- 📦 Version erhöht auf **1.1.160** + +--- + ## [1.1.159] – 2025-05-23 ### 🐞 Fixed diff --git a/components/pois/PoiUpdateModal.js b/components/pois/PoiUpdateModal.js index 490718af2..6ad9316f1 100644 --- a/components/pois/PoiUpdateModal.js +++ b/components/pois/PoiUpdateModal.js @@ -4,18 +4,21 @@ import Select from "react-select"; // Importiere react-select import { fetchLocationDevicesThunk } from "../../redux/thunks/database/fetchLocationDevicesThunk"; import { useSelector, useDispatch } from "react-redux"; import { selectMapLayersState } from "../../redux/slices/mapLayersSlice"; +import { fetchPoiTypThunk } from "../../redux/thunks/database/fetchPoiTypThunk"; +import { selectPoiTypData, selectPoiTypStatus } from "../../redux/slices/database/poiTypSlice"; const PoiUpdateModal = ({ onClose, poiData, onSubmit }) => { const dispatch = useDispatch(); const mapLayersVisibility = useSelector(selectMapLayersState); const [poiId, setPoiId] = useState(poiData ? poiData.idPoi : ""); const [name, setName] = useState(poiData ? poiData.name : ""); - const [poiTypData, setPoiTypData] = useState([]); const [poiTypeId, setPoiTypeId] = useState(null); // Verwende null für react-select const [filteredDevices, setFilteredDevices] = useState([]); const [deviceName, setDeviceName] = useState(poiData ? poiData.deviceName : null); // Verwende null für react-select const [idLD, setIdLD] = useState(poiData ? poiData.idLD : ""); const [description, setDescription] = useState(poiData ? poiData.description : ""); + const poiTypData = useSelector(selectPoiTypData); + const poiTypStatus = useSelector(selectPoiTypStatus); // Map von Systemnamen zu IDs (wie zuvor) const systemNameToIdMap = { @@ -55,34 +58,10 @@ const PoiUpdateModal = ({ onClose, poiData, onSubmit }) => { // Fetch POI types and set the current POI type in the react-select dropdown useEffect(() => { - const fetchPoiTypData = async () => { - try { - const response = await fetch("/api/talas_v5_DB/poiTyp/readPoiTyp"); - const data = await response.json(); - setPoiTypData(data); - - // Prüfe den gespeicherten Typ im localStorage - const storedPoiType = localStorage.getItem("selectedPoiType"); - - // Finde den passenden Typ in den abgerufenen Daten und setze ihn als ausgewählt - if (storedPoiType) { - const matchingType = data.find((type) => type.name === storedPoiType); - if (matchingType) { - setPoiTypeId({ value: matchingType.idPoiTyp, label: matchingType.name }); - } - } else if (poiData && poiData.idPoiTyp) { - // Falls kein Typ im localStorage ist, setze den Typ von poiData - const matchingType = data.find((type) => type.idPoiTyp === poiData.idPoiTyp); - if (matchingType) { - setPoiTypeId({ value: matchingType.idPoiTyp, label: matchingType.name }); - } - } - } catch (error) { - console.error("Fehler beim Abrufen der poiTyp Daten:", error); - } - }; - fetchPoiTypData(); - }, [poiData]); + if (poiTypStatus === "idle") { + dispatch(fetchPoiTypThunk()); + } + }, [dispatch, poiTypStatus]); // Fetch location devices and pre-select the current device useEffect(() => { diff --git a/config/appVersion.js b/config/appVersion.js index 2cf479c8d..a1dad4d6d 100644 --- a/config/appVersion.js +++ b/config/appVersion.js @@ -1,2 +1,2 @@ // /config/appVersion -export const APP_VERSION = "1.1.160"; +export const APP_VERSION = "1.1.161";