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:
20
CHANGELOG.md
20
CHANGELOG.md
@@ -4,6 +4,26 @@ Alle bedeutenden Änderungen an diesem Projekt werden in dieser Datei dokumentie
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## [1.1.147] - 2025-05-22
|
||||||
|
|
||||||
|
### Hinzugefügt
|
||||||
|
|
||||||
|
- Redux-Slice `gisUserRightsFromWebservice` eingeführt zur Ablösung von `useLoadUserRights.js`
|
||||||
|
- Zustand `userRights` jetzt vollständig über Redux gesteuert
|
||||||
|
|
||||||
|
### Geändert
|
||||||
|
|
||||||
|
- `MapComponent.js` angepasst: `useLoadUserRights.js` entfernt, stattdessen Thunk + Selector verwendet
|
||||||
|
- `fetchUserRightsThunk` direkt in `MapComponent.js` integriert
|
||||||
|
|
||||||
|
### Architektur
|
||||||
|
|
||||||
|
- Redux-Toolkit wird jetzt systematisch für Webservice-Daten verwendet
|
||||||
|
- Bessere Trennung zwischen Service, Thunk und Slice
|
||||||
|
- Lesbarkeit und Wartbarkeit deutlich verbessert
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## [1.1.144] – 2025-05-22
|
## [1.1.144] – 2025-05-22
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ import { enablePolylineEvents, disablePolylineEvents } from "../../utils/polylin
|
|||||||
import { updateCountdown, closePolylineContextMenu } from "../../redux/slices/polylineContextMenuSlice";
|
import { updateCountdown, closePolylineContextMenu } from "../../redux/slices/polylineContextMenuSlice";
|
||||||
//-------------------MapComponent.js hooks--------------------
|
//-------------------MapComponent.js hooks--------------------
|
||||||
import useInitializeMap from "./hooks/useInitializeMap";
|
import useInitializeMap from "./hooks/useInitializeMap";
|
||||||
import useLoadUserRights from "./hooks/useLoadUserRights";
|
|
||||||
import useFetchPoiData from "./hooks/useFetchPoiData.js";
|
import useFetchPoiData from "./hooks/useFetchPoiData.js";
|
||||||
import useRestoreMapSettings from "./hooks/useRestoreMapSettings";
|
import useRestoreMapSettings from "./hooks/useRestoreMapSettings";
|
||||||
import { setSelectedPoi } from "../../redux/slices/selectedPoiSlice";
|
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 { selectGisLines } from "../../redux/slices/database/gisLinesSlice";
|
||||||
import { selectGisLinesStatus } from "../../redux/slices/webservice/gisLinesStatusSlice";
|
import { selectGisLinesStatus } from "../../redux/slices/webservice/gisLinesStatusSlice";
|
||||||
import { selectGisLinesStatusFromWebservice } from "../../redux/slices/webservice/gisLinesStatusSlice";
|
import { selectGisLinesStatusFromWebservice } from "../../redux/slices/webservice/gisLinesStatusSlice";
|
||||||
|
import { selectGisUserRightsFromWebservice } from "../../redux/slices/webservice/userRightsSlice";
|
||||||
|
|
||||||
const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
||||||
//-------------------------------
|
//-------------------------------
|
||||||
@@ -106,10 +107,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
|||||||
const [isPopupOpen, setIsPopupOpen] = useState(false);
|
const [isPopupOpen, setIsPopupOpen] = useState(false);
|
||||||
const closePopup = () => setIsPopupOpen(false);
|
const closePopup = () => setIsPopupOpen(false);
|
||||||
const [currentCoordinates, setCurrentCoordinates] = useState("");
|
const [currentCoordinates, setCurrentCoordinates] = useState("");
|
||||||
const [isRightsLoaded, setIsRightsLoaded] = useState(false);
|
|
||||||
const [hasRights, setHasRights] = useState(false);
|
|
||||||
const [AddPoiModalWindowState, setAddPoiModalWindowState] = useState(false);
|
const [AddPoiModalWindowState, setAddPoiModalWindowState] = useState(false);
|
||||||
const [userRights, setUserRights] = useState(null);
|
|
||||||
const [showPoiUpdateModal, setShowPoiUpdateModal] = useState(false);
|
const [showPoiUpdateModal, setShowPoiUpdateModal] = useState(false);
|
||||||
const [currentPoiData, setCurrentPoiData] = useState(null);
|
const [currentPoiData, setCurrentPoiData] = useState(null);
|
||||||
const [showVersionInfoModal, setShowVersionInfoModal] = useState(false);
|
const [showVersionInfoModal, setShowVersionInfoModal] = useState(false);
|
||||||
@@ -120,7 +118,11 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
|||||||
const [map, setMap] = useState(null); // Zustand der Karteninstanz
|
const [map, setMap] = useState(null); // Zustand der Karteninstanz
|
||||||
const [oms, setOms] = useState(null); // State für OMS-Instanz
|
const [oms, setOms] = useState(null); // State für OMS-Instanz
|
||||||
const [GisStationsMeasurements, setGisStationsMeasurements] = useState([]); // Zustand für Messdaten
|
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 openPopupWithCoordinates = (e) => {
|
||||||
const coordinates = `${e.latlng.lat.toFixed(5)}, ${e.latlng.lng.toFixed(5)}`;
|
const coordinates = `${e.latlng.lat.toFixed(5)}, ${e.latlng.lng.toFixed(5)}`;
|
||||||
setCurrentCoordinates(coordinates);
|
setCurrentCoordinates(coordinates);
|
||||||
@@ -555,7 +557,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
|||||||
|
|
||||||
//---------------------------------
|
//---------------------------------
|
||||||
//--------------hokks-------------------------------------------
|
//--------------hokks-------------------------------------------
|
||||||
useLoadUserRights(setUserRights, setIsRightsLoaded, setHasRights);
|
|
||||||
useGmaMarkersLayer(
|
useGmaMarkersLayer(
|
||||||
map,
|
map,
|
||||||
gmaMarkers,
|
gmaMarkers,
|
||||||
@@ -768,6 +770,10 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}, [map, menuItemAdded]);
|
}, [map, menuItemAdded]);
|
||||||
|
//--------------------------------------------
|
||||||
|
useEffect(() => {
|
||||||
|
dispatch(fetchUserRightsThunk());
|
||||||
|
}, [dispatch]);
|
||||||
|
|
||||||
//--------------------------------------------
|
//--------------------------------------------
|
||||||
// Beim ersten Client-Render den Wert aus localStorage laden
|
// 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;
|
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
// /config/appVersion
|
// /config/appVersion
|
||||||
export const APP_VERSION = "1.1.147";
|
export const APP_VERSION = "1.1.148";
|
||||||
|
|||||||
Reference in New Issue
Block a user