refactoring

This commit is contained in:
ISA
2025-05-26 10:11:58 +02:00
parent 8034e28a45
commit 7c8a553235
8 changed files with 11 additions and 11 deletions

View File

@@ -0,0 +1,33 @@
// /redux/slices/database/poiIconsDataSlice.js
import { createSlice } from "@reduxjs/toolkit";
import { fetchPoiIconsDataThunk } from "../../../thunks/database/pois/fetchPoiIconsDataThunk";
const initialState = {
data: [],
status: "idle",
error: null,
};
const poiIconsDataSlice = createSlice({
name: "poiIconsData",
initialState,
reducers: {},
extraReducers: (builder) => {
builder
.addCase(fetchPoiIconsDataThunk.pending, (state) => {
state.status = "loading";
})
.addCase(fetchPoiIconsDataThunk.fulfilled, (state, action) => {
state.status = "succeeded";
state.data = action.payload;
})
.addCase(fetchPoiIconsDataThunk.rejected, (state, action) => {
state.status = "failed";
state.error = action.payload;
});
},
});
export default poiIconsDataSlice.reducer;
export const selectPoiIconsData = (state) => state.poiIconsData.data;
export const selectPoiIconsStatus = (state) => state.poiIconsData.status;

View File

@@ -0,0 +1,33 @@
// /redux/slices/database/poiTypSlice.js
import { createSlice } from "@reduxjs/toolkit";
import { fetchPoiTypThunk } from "../../../thunks/database/pois/fetchPoiTypThunk";
const initialState = {
data: [],
status: "idle",
error: null,
};
const poiTypSlice = createSlice({
name: "poiTyp",
initialState,
reducers: {},
extraReducers: (builder) => {
builder
.addCase(fetchPoiTypThunk.pending, (state) => {
state.status = "loading";
})
.addCase(fetchPoiTypThunk.fulfilled, (state, action) => {
state.status = "succeeded";
state.data = action.payload;
})
.addCase(fetchPoiTypThunk.rejected, (state, action) => {
state.status = "failed";
state.error = action.payload;
});
},
});
export default poiTypSlice.reducer;
export const selectPoiTypData = (state) => state.poiTyp.data;
export const selectPoiTypStatus = (state) => state.poiTyp.status;

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;