refactor: POI-Typen in MapComponent von Hook auf Redux umgestellt (v1.1.103)
This commit is contained in:
@@ -1,54 +0,0 @@
|
||||
// hooks/usePoiTypData.js
|
||||
import { useState, useEffect, useRef } from "react";
|
||||
import { toast } from "react-toastify"; // Toast für Warnungen importieren
|
||||
|
||||
const usePoiTypData = (url) => {
|
||||
const [poiTypData, setPoiTypData] = useState([]);
|
||||
const [isPoiTypLoaded, setIsPoiTypLoaded] = useState(false);
|
||||
const retryCountRef = useRef(0);
|
||||
const maxRetries = 2;
|
||||
|
||||
useEffect(() => {
|
||||
const fetchPoiTypData = async () => {
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
const data = await response.json();
|
||||
|
||||
if (!Array.isArray(data)) {
|
||||
console.warn(`Unerwartetes Format: ${JSON.stringify(data)}`);
|
||||
|
||||
if (data.warning) {
|
||||
toast.warn(data.warning, { position: "top-center", autoClose: 5000 });
|
||||
setPoiTypData([]); // Leeres Array setzen
|
||||
setIsPoiTypLoaded(true);
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Error("Daten sind kein Array");
|
||||
}
|
||||
|
||||
// Erfolgreich geladen, also Reset des Retry-Zählers
|
||||
setPoiTypData(data);
|
||||
setIsPoiTypLoaded(true);
|
||||
retryCountRef.current = 0;
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Abrufen der poiTyp-Daten in usePoiTypData.js :", error);
|
||||
|
||||
if (retryCountRef.current < maxRetries) {
|
||||
retryCountRef.current++;
|
||||
console.log(`Neuer Versuch (${retryCountRef.current}/${maxRetries}) in 5 Sekunden...`);
|
||||
setTimeout(fetchPoiTypData, 5000);
|
||||
} else {
|
||||
console.error("Maximale Anzahl an Fehlversuchen erreicht. Stoppe weitere Abrufe.");
|
||||
setIsPoiTypLoaded(true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
fetchPoiTypData();
|
||||
}, [url]);
|
||||
|
||||
return { poiTypData, isPoiTypLoaded };
|
||||
};
|
||||
|
||||
export default usePoiTypData;
|
||||
Reference in New Issue
Block a user