refactor: userRights mit Redux umgesetzt, useLoadUserRights entfernt
- Thunk fetchUserRightsThunk in MapComponent verwendet - Redux-Slice gisUserRightsFromWebservice selektiert - useLoadUserRights Hook entfernt - Zustand isRightsLoaded und hasRights in Redux integriert - MapComponent vollständig auf Redux umgestellt
This commit is contained in:
@@ -46,7 +46,7 @@ import { enablePolylineEvents, disablePolylineEvents } from "../../utils/polylin
|
||||
import { updateCountdown, closePolylineContextMenu } from "../../redux/slices/polylineContextMenuSlice";
|
||||
//-------------------MapComponent.js hooks--------------------
|
||||
import useInitializeMap from "./hooks/useInitializeMap";
|
||||
import useLoadUserRights from "./hooks/useLoadUserRights";
|
||||
|
||||
import useFetchPoiData from "./hooks/useFetchPoiData.js";
|
||||
import useRestoreMapSettings from "./hooks/useRestoreMapSettings";
|
||||
import { setSelectedPoi } from "../../redux/slices/selectedPoiSlice";
|
||||
@@ -67,6 +67,7 @@ import { fetchUserRightsThunk } from "../../redux/thunks/webservice/fetchUserRig
|
||||
import { selectGisLines } from "../../redux/slices/database/gisLinesSlice";
|
||||
import { selectGisLinesStatus } from "../../redux/slices/webservice/gisLinesStatusSlice";
|
||||
import { selectGisLinesStatusFromWebservice } from "../../redux/slices/webservice/gisLinesStatusSlice";
|
||||
import { selectGisUserRightsFromWebservice } from "../../redux/slices/webservice/userRightsSlice";
|
||||
|
||||
const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
||||
//-------------------------------
|
||||
@@ -106,10 +107,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
||||
const [isPopupOpen, setIsPopupOpen] = useState(false);
|
||||
const closePopup = () => setIsPopupOpen(false);
|
||||
const [currentCoordinates, setCurrentCoordinates] = useState("");
|
||||
const [isRightsLoaded, setIsRightsLoaded] = useState(false);
|
||||
const [hasRights, setHasRights] = useState(false);
|
||||
const [AddPoiModalWindowState, setAddPoiModalWindowState] = useState(false);
|
||||
const [userRights, setUserRights] = useState(null);
|
||||
const [showPoiUpdateModal, setShowPoiUpdateModal] = useState(false);
|
||||
const [currentPoiData, setCurrentPoiData] = useState(null);
|
||||
const [showVersionInfoModal, setShowVersionInfoModal] = useState(false);
|
||||
@@ -120,7 +118,11 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
||||
const [map, setMap] = useState(null); // Zustand der Karteninstanz
|
||||
const [oms, setOms] = useState(null); // State für OMS-Instanz
|
||||
const [GisStationsMeasurements, setGisStationsMeasurements] = useState([]); // Zustand für Messdaten
|
||||
|
||||
//-----userRights----------------
|
||||
const isRightsLoaded = useSelector((state) => state.gisUserRightsFromWebservice.status === "succeeded");
|
||||
const userRights = useSelector(selectGisUserRightsFromWebservice);
|
||||
const hasRights = userRights.includes(56);
|
||||
//-----------------------------
|
||||
const openPopupWithCoordinates = (e) => {
|
||||
const coordinates = `${e.latlng.lat.toFixed(5)}, ${e.latlng.lng.toFixed(5)}`;
|
||||
setCurrentCoordinates(coordinates);
|
||||
@@ -555,7 +557,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
||||
|
||||
//---------------------------------
|
||||
//--------------hokks-------------------------------------------
|
||||
useLoadUserRights(setUserRights, setIsRightsLoaded, setHasRights);
|
||||
|
||||
useGmaMarkersLayer(
|
||||
map,
|
||||
gmaMarkers,
|
||||
@@ -768,6 +770,10 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
||||
);
|
||||
}
|
||||
}, [map, menuItemAdded]);
|
||||
//--------------------------------------------
|
||||
useEffect(() => {
|
||||
dispatch(fetchUserRightsThunk());
|
||||
}, [dispatch]);
|
||||
|
||||
//--------------------------------------------
|
||||
// Beim ersten Client-Render den Wert aus localStorage laden
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
// /components/mainComponent/hooks/useLoadUserRights.js
|
||||
import { useEffect } from "react";
|
||||
import { fetchUserRightsService } from "../../../services/webservice/fetchUserRightsService";
|
||||
|
||||
const useLoadUserRights = (setUserRights, setIsRightsLoaded, setHasRights) => {
|
||||
useEffect(() => {
|
||||
const fetchAndSetUserRights = async () => {
|
||||
const rights = await fetchUserRightsService();
|
||||
setUserRights(rights);
|
||||
setIsRightsLoaded(true);
|
||||
|
||||
// Sicherstellen, dass `rights` ein Array ist, bevor `.includes()` aufgerufen wird
|
||||
setHasRights(localStorage.getItem("editMode") && Array.isArray(rights) && rights.includes(56));
|
||||
};
|
||||
|
||||
fetchAndSetUserRights();
|
||||
}, []);
|
||||
};
|
||||
|
||||
export default useLoadUserRights;
|
||||
Reference in New Issue
Block a user