refactor: POI-Daten vollständig in Redux integriert
- useFetchPoiData.js entfernt - Neue Redux-Slices für POI-Typen und POI-Icons erstellt - Neue Services und Thunks hinzugefügt - fetch-Aufrufe durch zentralisierte Redux-Logik ersetzt - store.js aktualisiert und neue States registriert
This commit is contained in:
33
redux/slices/database/poiIconsDataSlice.js
Normal file
33
redux/slices/database/poiIconsDataSlice.js
Normal file
@@ -0,0 +1,33 @@
|
||||
// /redux/slices/database/poiIconsDataSlice.js
|
||||
import { createSlice } from "@reduxjs/toolkit";
|
||||
import { fetchPoiIconsDataThunk } from "../../thunks/database/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/poiTypSlice.js
Normal file
33
redux/slices/database/poiTypSlice.js
Normal file
@@ -0,0 +1,33 @@
|
||||
// /redux/slices/database/poiTypSlice.js
|
||||
import { createSlice } from "@reduxjs/toolkit";
|
||||
import { fetchPoiTypThunk } from "../../thunks/database/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;
|
||||
@@ -20,6 +20,8 @@ import priorityConfigReducer from "./slices/database/priorityConfigSlice";
|
||||
import poiTypesReducer from "./slices/database/poiTypesSlice";
|
||||
import locationDevicesFromDBReducer from "./slices/database/locationDevicesFromDBSlice";
|
||||
import gisLinesFromDatabaseReducer from "./slices/database/gisLinesSlice";
|
||||
import poiTypReducer from "./slices/database/poiTypSlice";
|
||||
import poiIconsDataReducer from "./slices/database/poiIconsDataSlice";
|
||||
//----webservice------------
|
||||
import gisStationsStaticDistrictReducer from "./slices/webservice/gisStationsStaticDistrictSlice";
|
||||
import gisStationsStatusDistrictReducer from "./slices/webservice/gisStationsStatusDistrictSlice";
|
||||
@@ -57,5 +59,7 @@ export const store = configureStore({
|
||||
urlParameter: urlParameterReducer,
|
||||
priorityConfig: priorityConfigReducer,
|
||||
addPoi: addPoiReducer,
|
||||
poiTyp: poiTypReducer,
|
||||
poiIconsData: poiIconsDataReducer,
|
||||
},
|
||||
});
|
||||
|
||||
11
redux/thunks/database/fetchPoiIconsDataThunk.js
Normal file
11
redux/thunks/database/fetchPoiIconsDataThunk.js
Normal file
@@ -0,0 +1,11 @@
|
||||
// /redux/thunks/database/fetchPoiIconsDataThunk.js
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { fetchPoiIconsDataService } from "../../../services/database/fetchPoiIconsDataService";
|
||||
|
||||
export const fetchPoiIconsDataThunk = createAsyncThunk("poiIconsData/fetch", async (_, thunkAPI) => {
|
||||
try {
|
||||
return await fetchPoiIconsDataService();
|
||||
} catch (err) {
|
||||
return thunkAPI.rejectWithValue(err.message);
|
||||
}
|
||||
});
|
||||
11
redux/thunks/database/fetchPoiTypThunk.js
Normal file
11
redux/thunks/database/fetchPoiTypThunk.js
Normal file
@@ -0,0 +1,11 @@
|
||||
// /redux/thunks/database/fetchPoiTypThunk.js
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { fetchPoiTypService } from "../../../services/database/fetchPoiTypService";
|
||||
|
||||
export const fetchPoiTypThunk = createAsyncThunk("poiTyp/fetch", async (_, thunkAPI) => {
|
||||
try {
|
||||
return await fetchPoiTypService();
|
||||
} catch (err) {
|
||||
return thunkAPI.rejectWithValue(err.message);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user