feat: Geräte-Daten aus Redux-Store in POI-Bearbeiten-Modal integriert
- Geräte-Liste wird jetzt direkt aus dem Redux-Store (locationDevicesFromDB) verwendet. - Dropdown-Menü zeigt alle verfügbaren Geräte aus der Datenbank. - Beim Öffnen des Modals wird der vorher zugewiesene Gerätname automatisch ausgewählt (Pre-Selection). - Cleanup und Optimierung: Keine separaten API-Calls mehr im Modal. - Struktur verbessert durch Auslagerung der Lade-Logik in useInitLocationDevices Hook.
This commit is contained in:
8
redux/api/fromDB/locationDevicesLoader.js
Normal file
8
redux/api/fromDB/locationDevicesLoader.js
Normal file
@@ -0,0 +1,8 @@
|
||||
// /redux/api/fromDB/locationDevicesLoader.js
|
||||
export const fetchLocationDevices = async () => {
|
||||
const response = await fetch("/api/talas_v5_DB/locationDevice/locationDevices");
|
||||
if (!response.ok) {
|
||||
throw new Error("Geräteliste konnte nicht geladen werden");
|
||||
}
|
||||
return await response.json();
|
||||
};
|
||||
0
redux/api/fromDB/poiTypLoader.js
Normal file
0
redux/api/fromDB/poiTypLoader.js
Normal file
0
redux/api/fromWebService/userSessionLoader.js
Normal file
0
redux/api/fromWebService/userSessionLoader.js
Normal file
33
redux/slices/db/locationDevicesFromDBSlice.js
Normal file
33
redux/slices/db/locationDevicesFromDBSlice.js
Normal file
@@ -0,0 +1,33 @@
|
||||
// /redux/slices/db/locationDevicesFromDBSlice.js
|
||||
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { fetchLocationDevices } from "../../api/fromDB/locationDevicesLoader";
|
||||
|
||||
export const fetchLocationDevicesFromDB = createAsyncThunk("locationDevicesFromDB/fetchLocationDevicesFromDB", async () => {
|
||||
return fetchLocationDevices();
|
||||
});
|
||||
|
||||
const locationDevicesFromDBSlice = createSlice({
|
||||
name: "locationDevicesFromDB",
|
||||
initialState: {
|
||||
devices: [],
|
||||
status: "idle",
|
||||
error: null,
|
||||
},
|
||||
reducers: {},
|
||||
extraReducers: (builder) => {
|
||||
builder
|
||||
.addCase(fetchLocationDevicesFromDB.pending, (state) => {
|
||||
state.status = "loading";
|
||||
})
|
||||
.addCase(fetchLocationDevicesFromDB.fulfilled, (state, action) => {
|
||||
state.status = "succeeded";
|
||||
state.devices = action.payload; // <-- Hier landen die Daten
|
||||
})
|
||||
.addCase(fetchLocationDevicesFromDB.rejected, (state, action) => {
|
||||
state.status = "failed";
|
||||
state.error = action.error.message;
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export default locationDevicesFromDBSlice.reducer;
|
||||
@@ -3,6 +3,7 @@ import lineVisibilityReducer from "./slices/lineVisibilitySlice";
|
||||
import currentPoiReducer from "./slices/currentPoiSlice";
|
||||
import gisStationsStaticDistrictReducer from "./slices/webService/gisStationsStaticDistrictSlice";
|
||||
import polylineLayerVisibleReducer from "./slices/polylineLayerVisibleSlice";
|
||||
import locationDevicesFromDBReducer from "./slices/db/locationDevicesFromDBSlice";
|
||||
|
||||
export const store = configureStore({
|
||||
reducer: {
|
||||
@@ -10,5 +11,6 @@ export const store = configureStore({
|
||||
currentPoi: currentPoiReducer,
|
||||
gisStationsStaticDistrict: gisStationsStaticDistrictReducer,
|
||||
polylineLayerVisible: polylineLayerVisibleReducer,
|
||||
locationDevicesFromDB: locationDevicesFromDBReducer,
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user