currentPoiSlice als Redux Slice implementiert statt Recoil atom

This commit is contained in:
ISA
2024-12-18 21:44:41 +01:00
parent 2934565501
commit b5571989ba
7 changed files with 52 additions and 36 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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,
});

View File

@@ -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),
});