refactor: mainComponent/hooks/webServices/
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
// components/mainComponent/hooks/useAutoRefreshLocationDevices.js
|
||||
/*
|
||||
Das ist erstmal nur so da, falls es gebraucht wird
|
||||
Diese datei ist zum automatischen aktualisieren der LocationDevices gedacht
|
||||
jeder 20 Sekunden wird die Funktion fetchLocationDevicesFromDB() aufgerufen
|
||||
Daten werden dann in der Redux State gespeichert
|
||||
*/
|
||||
|
||||
import { useEffect } from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { fetchLocationDevicesFromDB } from "../../../../redux/slices/db/locationDevicesFromDBSlice";
|
||||
|
||||
export const useAutoRefreshLocationDevices = (interval = 20000) => {
|
||||
// alle 20 Sekunden
|
||||
const dispatch = useDispatch();
|
||||
|
||||
useEffect(() => {
|
||||
const fetchData = () => {
|
||||
dispatch(fetchLocationDevicesFromDB());
|
||||
};
|
||||
|
||||
fetchData(); // Sofort beim Start holen
|
||||
|
||||
const intervalId = setInterval(fetchData, interval);
|
||||
|
||||
return () => clearInterval(intervalId); // Cleanup beim Unmount
|
||||
}, [dispatch, interval]);
|
||||
};
|
||||
|
||||
/*
|
||||
In MapComponent.js einbinden
|
||||
import { useAutoRefreshLocationDevices } from "./hooks/useAutoRefreshLocationDevices";
|
||||
|
||||
const MapComponent = () => {
|
||||
useAutoRefreshLocationDevices();
|
||||
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,12 @@
|
||||
// /components/mainComponent/hooks/useInitGisStationsMeasurements.js
|
||||
import { useEffect } from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { fetchGisStationsMeasurementsFromWebService } from "../../../../redux/slices/webService/gisStationsMeasurementsSlice";
|
||||
|
||||
export const useInitGisStationsMeasurements = () => {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(fetchGisStationsMeasurementsFromWebService());
|
||||
}, [dispatch]);
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
// /components/mainComponent/hooks/useInitGisStationsStatic.js
|
||||
//Bereiche/Area-Name Dropdownmenu für Datasheet wird hier initialisiert und in der Komponente verwendet
|
||||
import { useEffect } from "react";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { fetchGisStationsStatic, selectGisStationsStatic } from "../../../../redux/slices/webService/gisStationsStaticSlice";
|
||||
|
||||
export const useInitGisStationsStatic = () => {
|
||||
const dispatch = useDispatch();
|
||||
const gisStationsStatic = useSelector(selectGisStationsStatic);
|
||||
|
||||
useEffect(() => {
|
||||
// console.log("🔍 useInitGisStationsStatic - Aktueller Wert:", gisStationsStatic);
|
||||
|
||||
if (!gisStationsStatic || gisStationsStatic === null) {
|
||||
//console.log("🚀 Starte fetchGisStationsStatic...");
|
||||
dispatch(fetchGisStationsStatic());
|
||||
}
|
||||
}, [gisStationsStatic, dispatch]);
|
||||
|
||||
return gisStationsStatic;
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
// /components/mainComponent/hooks/useInitGisStationsStaticDistrict.js
|
||||
import { useEffect } from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { fetchGisStationsStaticDistrictFromWebService } from "../../../../redux/slices/webService/gisStationsStaticDistrictSlice";
|
||||
|
||||
export const useInitGisStationsStaticDistrict = () => {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(fetchGisStationsStaticDistrictFromWebService());
|
||||
}, [dispatch]);
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
// /componets/mainComponent/hooks/useInitGisStationsStatusDistrict.js
|
||||
import { useEffect } from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { fetchGisStationsStatusDistrictFromWebService } from "../../../../redux/slices/webService/gisStationsStatusDistrictSlice";
|
||||
|
||||
export const useInitGisStationsStatusDistrict = () => {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(fetchGisStationsStatusDistrictFromWebService());
|
||||
}, [dispatch]);
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
// /components/mainComponent/hooks/useInitGisStationsMeasurements.js
|
||||
import { useEffect } from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { fetchGisSystemStaticFromWebService } from "../../../../redux/slices/webService/gisSystemStaticSlice";
|
||||
|
||||
export const useInitGisSystemStatic = () => {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(fetchGisSystemStaticFromWebService());
|
||||
}, [dispatch]);
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
// /components/mainComponent/hooks/useInitLocationDevices.js
|
||||
import { useEffect } from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { fetchLocationDevicesFromDB } from "../../../../redux/slices/db/locationDevicesFromDBSlice";
|
||||
|
||||
export const useInitLocationDevices = () => {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(fetchLocationDevicesFromDB());
|
||||
}, [dispatch]);
|
||||
};
|
||||
Reference in New Issue
Block a user