refactor: Komponenten-Hooks strukturiert und in passende UI-Unterverzeichnisse verschoben
- useLineData.js → components/gisPolylines/tooltip/ - useLayerVisibility.js → components/mapLayersControlPanel/hooks/ - useAreaMarkersLayer.js → components/area/hooks/ - useDynamicDeviceLayers.js → components/devices/hooks/ - useDataUpdater.js & useMapComponentState.js → components/hooks/ 💡 Ziel: Alle UI-bezogenen Hooks an logische Stellen verschoben, um Wartbarkeit zu verbessern. 🔍 Vorteil: Schnellere Navigation bei UI-Fehlern oder Layout-Anpassungen.
This commit is contained in:
40
components/hooks/useDataUpdater.js
Normal file
40
components/hooks/useDataUpdater.js
Normal file
@@ -0,0 +1,40 @@
|
||||
// hooks/useDataUpdater.js
|
||||
import { useEffect } from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
// import type { AppDispatch } from "../redux/store";
|
||||
|
||||
// ✅ Thunks aus korrektem Pfad importieren
|
||||
import { fetchGisLinesStatusThunk } from "@/redux/thunks/webservice/fetchGisLinesStatusThunk";
|
||||
import { fetchGisStationsMeasurementsThunk } from "@/redux/thunks/webservice/fetchGisStationsMeasurementsThunk";
|
||||
import { fetchGisStationsStaticDistrictThunk } from "@/redux/thunks/webservice/fetchGisStationsStaticDistrictThunk";
|
||||
import { fetchGisStationsStatusDistrictThunk } from "@/redux/thunks/webservice/fetchGisStationsStatusDistrictThunk";
|
||||
import { fetchGisSystemStaticThunk } from "@/redux/thunks/webservice/fetchGisSystemStaticThunk";
|
||||
|
||||
const REFRESH_INTERVAL = parseInt(process.env.NEXT_PUBLIC_REFRESH_INTERVAL || "10000");
|
||||
|
||||
export const useDataUpdater = () => {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
useEffect(() => {
|
||||
const updateAll = () => {
|
||||
dispatch(fetchGisLinesStatusThunk());
|
||||
dispatch(fetchGisStationsMeasurementsThunk());
|
||||
dispatch(fetchGisStationsStaticDistrictThunk());
|
||||
dispatch(fetchGisStationsStatusDistrictThunk());
|
||||
dispatch(fetchGisSystemStaticThunk());
|
||||
};
|
||||
|
||||
updateAll();
|
||||
const interval = setInterval(updateAll, 10000);
|
||||
return () => clearInterval(interval);
|
||||
}, [dispatch]);
|
||||
};
|
||||
|
||||
// Das ist eine normale Funktion
|
||||
export const triggerDataUpdate = dispatch => {
|
||||
dispatch(fetchGisLinesStatusThunk());
|
||||
dispatch(fetchGisStationsMeasurementsThunk());
|
||||
dispatch(fetchGisStationsStaticDistrictThunk());
|
||||
dispatch(fetchGisStationsStatusDistrictThunk());
|
||||
dispatch(fetchGisSystemStaticThunk());
|
||||
};
|
||||
65
components/hooks/useMapComponentState.js
Normal file
65
components/hooks/useMapComponentState.js
Normal file
@@ -0,0 +1,65 @@
|
||||
// /hooks/useMapComponentState.js
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
|
||||
// Redux: POI-Typen
|
||||
import { fetchPoiTypThunk } from "@/redux/thunks/database/pois/fetchPoiTypThunk";
|
||||
import { selectPoiTypData, selectPoiTypStatus } from "@/redux/slices/database/pois/poiTypSlice";
|
||||
|
||||
// Redux: GIS Geräte
|
||||
import { fetchGisStationsStaticDistrictThunk } from "@/redux/thunks/webservice/fetchGisStationsStaticDistrictThunk";
|
||||
import { selectGisStationsStaticDistrict } from "@/redux/slices/webservice/gisStationsStaticDistrictSlice";
|
||||
|
||||
// Redux: priorityConfig
|
||||
import { fetchPriorityConfigThunk } from "@/redux/thunks/database/fetchPriorityConfigThunk";
|
||||
import { selectPriorityConfig } from "@/redux/slices/database/priorityConfigSlice";
|
||||
|
||||
export const useMapComponentState = () => {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
// Redux: Sichtbarkeit des POI-Layers
|
||||
const poiLayerVisible = useSelector(state => state.poiLayerVisible.visible);
|
||||
|
||||
// Redux: POI-Typen
|
||||
const poiTypData = useSelector(selectPoiTypData);
|
||||
const poiTypStatus = useSelector(selectPoiTypStatus);
|
||||
|
||||
// Redux: Geräte
|
||||
const locationDeviceData = useSelector(selectGisStationsStaticDistrict);
|
||||
const deviceName = locationDeviceData?.Points?.[0]?.LD_Name || "";
|
||||
|
||||
// Redux: Prioritätskonfiguration
|
||||
const priorityConfig = useSelector(selectPriorityConfig);
|
||||
|
||||
// UI-interner Zustand
|
||||
const [menuItemAdded, setMenuItemAdded] = useState(false);
|
||||
|
||||
// POI-Typen laden
|
||||
useEffect(() => {
|
||||
if (poiTypStatus === "idle") {
|
||||
dispatch(fetchPoiTypThunk());
|
||||
}
|
||||
}, [dispatch, poiTypStatus]);
|
||||
|
||||
// GIS Geräte laden
|
||||
useEffect(() => {
|
||||
dispatch(fetchGisStationsStaticDistrictThunk());
|
||||
}, [dispatch]);
|
||||
|
||||
// PriorityConfig laden
|
||||
useEffect(() => {
|
||||
dispatch(fetchPriorityConfigThunk());
|
||||
}, [dispatch]);
|
||||
|
||||
return {
|
||||
poiTypData,
|
||||
isPoiTypLoaded: poiTypStatus === "succeeded",
|
||||
deviceName,
|
||||
locationDeviceData,
|
||||
priorityConfig,
|
||||
menuItemAdded,
|
||||
setMenuItemAdded,
|
||||
poiLayerVisible,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user