cleanup: alte GIS-Fetch-Dateien und unnötige Service-Imports entfernt – vollständige Umstellung auf zentrale Thunks abgeschlossen

This commit is contained in:
ISA
2025-05-21 10:41:59 +02:00
parent 86f1c1feb0
commit 0b7704935f
19 changed files with 110 additions and 31 deletions

View File

@@ -0,0 +1,33 @@
// /redux/slices/database/locationDevicesFromDBSlice.js
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
import { fetchLocationDevices } from "../../api/fromDB/fetchLocationDevices";
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;

View File

@@ -0,0 +1,31 @@
// /redux/slices/database/locationDevicesSlice.js
import { createSlice } from "@reduxjs/toolkit";
import { fetchLocationDevicesThunk } from "../../../thunks/fetchLocationDevicesThunk";
const slice = createSlice({
name: "locationDevices",
initialState: {
data: [],
status: "idle",
error: null,
},
reducers: {},
extraReducers: (builder) => {
builder
.addCase(fetchLocationDevicesThunk.pending, (state) => {
state.status = "loading";
})
.addCase(fetchLocationDevicesThunk.fulfilled, (state, action) => {
state.status = "succeeded";
state.data = action.payload;
})
.addCase(fetchLocationDevicesThunk.rejected, (state, action) => {
state.status = "failed";
state.error = action.error.message;
});
},
});
export default slice.reducer;
export const selectLocationDevices = (state) => state.locationDevices.data;

View File

@@ -0,0 +1,39 @@
// /redux/slices/database/poiTypesSlice.js
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
// API-Abruf für POI-Typen
export const fetchPoiTypes = createAsyncThunk("poiTypes/fetchPoiTypes", async () => {
let API_BASE_URL = "";
if (typeof window !== "undefined") {
// Browser
API_BASE_URL = `${window.location.protocol}//${window.location.hostname}:3000`;
} else {
// Server (z.B. SSR)
API_BASE_URL = "http://localhost:3000"; // oder env-Fallback z.B. process.env.API_BASE_URL
}
const response = await fetch(`${API_BASE_URL}/api/talas_v5_DB/poiTyp/readPoiTyp`);
return await response.json();
});
const poiTypesSlice = createSlice({
name: "poiTypes",
initialState: { data: [], status: "idle" },
reducers: {},
extraReducers: (builder) => {
builder
.addCase(fetchPoiTypes.pending, (state) => {
state.status = "loading";
})
.addCase(fetchPoiTypes.fulfilled, (state, action) => {
state.data = action.payload;
state.status = "succeeded";
})
.addCase(fetchPoiTypes.rejected, (state) => {
state.status = "failed";
});
},
});
export default poiTypesSlice.reducer;