refactor: fetchLocationDevices.js entfernt – Nutzung über Thunk + Service strukturiert neu aufgesetzt

This commit is contained in:
ISA
2025-05-21 11:02:40 +02:00
parent 0b7704935f
commit 71a6aeef1c
8 changed files with 33 additions and 80 deletions

View File

@@ -1,10 +1,5 @@
// /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();
});
import { createSlice } from "@reduxjs/toolkit";
import { fetchLocationDevicesThunk } from "../../thunks/database/fetchLocationDevicesThunk";
const locationDevicesFromDBSlice = createSlice({
name: "locationDevicesFromDB",
@@ -16,14 +11,14 @@ const locationDevicesFromDBSlice = createSlice({
reducers: {},
extraReducers: (builder) => {
builder
.addCase(fetchLocationDevicesFromDB.pending, (state) => {
.addCase(fetchLocationDevicesThunk.pending, (state) => {
state.status = "loading";
})
.addCase(fetchLocationDevicesFromDB.fulfilled, (state, action) => {
.addCase(fetchLocationDevicesThunk.fulfilled, (state, action) => {
state.status = "succeeded";
state.devices = action.payload; // <-- Hier landen die Daten
state.devices = action.payload;
})
.addCase(fetchLocationDevicesFromDB.rejected, (state, action) => {
.addCase(fetchLocationDevicesThunk.rejected, (state, action) => {
state.status = "failed";
state.error = action.error.message;
});
@@ -31,3 +26,4 @@ const locationDevicesFromDBSlice = createSlice({
});
export default locationDevicesFromDBSlice.reducer;
export const selectLocationDevices = (state) => state.locationDevicesFromDB.devices;