cleanup: alte GIS-Fetch-Dateien und unnötige Service-Imports entfernt – vollständige Umstellung auf zentrale Thunks abgeschlossen
This commit is contained in:
33
redux/slices/database/locationDevicesFromDBSlice.js
Normal file
33
redux/slices/database/locationDevicesFromDBSlice.js
Normal 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;
|
||||
31
redux/slices/database/locationDevicesSlice.js
Normal file
31
redux/slices/database/locationDevicesSlice.js
Normal 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;
|
||||
39
redux/slices/database/poiTypesSlice.js
Normal file
39
redux/slices/database/poiTypesSlice.js
Normal 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;
|
||||
Reference in New Issue
Block a user