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());
|
||||
};
|
||||
Reference in New Issue
Block a user