currentPoiSlice als Redux Slice implementiert statt Recoil atom
This commit is contained in:
@@ -1,18 +1,9 @@
|
||||
// /redux/reducer.js
|
||||
const initialState = {
|
||||
messages: [],
|
||||
};
|
||||
// redux/reducer.js
|
||||
import { combineReducers } from "redux";
|
||||
import currentPoiReducer from "./slices/currentPoiSlice";
|
||||
|
||||
const websocketReducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case "WS_MESSAGE_RECEIVED":
|
||||
return {
|
||||
...state,
|
||||
messages: [...state.messages, action.payload],
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
const rootReducer = combineReducers({
|
||||
currentPoi: currentPoiReducer,
|
||||
});
|
||||
|
||||
export default websocketReducer;
|
||||
export default rootReducer;
|
||||
|
||||
@@ -1,7 +1,28 @@
|
||||
// /redux/slices/currentPoiSlice.js
|
||||
import { atom } from 'recoil';
|
||||
import { createSlice } from "@reduxjs/toolkit";
|
||||
|
||||
export const currentPoiState = atom({
|
||||
key: 'currentPoiState', // Eindeutiger Key, der dieses Atom identifiziert
|
||||
default: null, // Standardwert ist null oder ein leeres Objekt, je nach Bedarf
|
||||
const initialState = {
|
||||
currentPoi: null, // Standardwert wie im Recoil-Atom
|
||||
};
|
||||
|
||||
const currentPoiSlice = createSlice({
|
||||
name: "currentPoi",
|
||||
initialState,
|
||||
reducers: {
|
||||
setCurrentPoi(state, action) {
|
||||
state.currentPoi = action.payload; // Zustand mit dem neuen POI aktualisieren
|
||||
},
|
||||
clearCurrentPoi(state) {
|
||||
state.currentPoi = null; // Zustand auf null zurücksetzen
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Actions exportieren
|
||||
export const { setCurrentPoi, clearCurrentPoi } = currentPoiSlice.actions;
|
||||
|
||||
// Selector exportieren (optional)
|
||||
export const selectCurrentPoi = (state) => state.currentPoi.currentPoi;
|
||||
|
||||
// Reducer exportieren
|
||||
export default currentPoiSlice.reducer;
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
// /redux/slices/poiLayerVisibleStateSlice.js
|
||||
// Recoil atom for the visibility of the POI layer
|
||||
import { atom } from "recoil";
|
||||
|
||||
export const poiLayerVisibleState = atom({
|
||||
key: "poiLayerVisibleState",
|
||||
default: true,
|
||||
});
|
||||
@@ -1,11 +1,9 @@
|
||||
// /redux/store.js
|
||||
import { configureStore } from "@reduxjs/toolkit";
|
||||
import websocketMiddleware from "./middleware/websocketMiddleware";
|
||||
import websocketReducer from "./reducer";
|
||||
import rootReducer from "./reducer";
|
||||
|
||||
// Erstelle den Store mit configureStore
|
||||
const store = configureStore({
|
||||
reducer: websocketReducer,
|
||||
reducer: rootReducer, // Kombinierter Root-Reducer
|
||||
middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(websocketMiddleware),
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user