// redux/slices/urlParameterSlice.js
import { createSlice } from "@reduxjs/toolkit";

const initialState = {
  mapId: null,
  userId: null,
};

const urlParameterSlice = createSlice({
  name: "urlParameter",
  initialState,
  reducers: {
    setMapId: (state, action) => {
      state.mapId = action.payload;
    },
    setUserId: (state, action) => {
      state.userId = action.payload;
    },
    setFromURL: (state, action) => {
      const { m, u } = action.payload;
      if (m) state.mapId = m;
      if (u) state.userId = u;
    },
  },
});

export const { setMapId, setUserId, setFromURL } = urlParameterSlice.actions;
export default urlParameterSlice.reducer;
