refactoring
This commit is contained in:
33
redux/slices/database/pois/poiIconsDataSlice.js
Normal file
33
redux/slices/database/pois/poiIconsDataSlice.js
Normal 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;
|
||||
33
redux/slices/database/pois/poiTypSlice.js
Normal file
33
redux/slices/database/pois/poiTypSlice.js
Normal 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;
|
||||
39
redux/slices/database/pois/poiTypesSlice.js
Normal file
39
redux/slices/database/pois/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