Kontextmenü Item "POI Bearbeiten", "POI hinzufügen" und "Stützpunkt hinzufügen" ausblenden wenn localStorage Variable "editMode" false ist

This commit is contained in:
ISA
2024-09-09 11:48:43 +02:00
parent 04e50c30f8
commit e1b51f6802
8 changed files with 886 additions and 103 deletions

View File

@@ -2,31 +2,55 @@
import * as config from "../config/config";
import * as urls from "../config/urls";
export const fetchGisStatusStations = async (idMap, idUser) => {
const SERVER_URL = process.env.NEXT_PUBLIC_SERVER_URL;
let timeoutId;
// Zähler für API-Aufrufe in localStorage speichern
let requestCount = localStorage.getItem("gisStatusStationsCount") || 0;
requestCount++;
localStorage.setItem("gisStatusStationsCount", requestCount);
console.log(`fetchGisStatusStations wurde ${requestCount} Mal aufgerufen.`);
const fetchWithTimeout = async (url, options, timeout = 5000) => {
const controller = new AbortController();
const id = setTimeout(() => controller.abort(), timeout);
try {
const response = await fetch(`${SERVER_URL}/talas5/ClientData/WebServiceMap.asmx/GisStationsStatusDistrict?idMap=${idMap}&idUser=${idUser}`);
if (!response.ok) {
throw new Error(`Error: ${response.statusText}
MySQL Datenbankverbindung fehlgeschlagen!
MySQL-Mode: SET GLOBAL sql_mode = 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
prüfen oder nodeMap Dienst neu starten`);
}
const data = await response.json();
return data;
const response = await fetch(url, {
...options,
signal: controller.signal,
});
clearTimeout(id);
return response;
} catch (error) {
console.error("Fehler beim Abrufen der Daten:", error);
throw error; // Fehler weiter werfen, um ihn in der Komponente behandeln zu können
clearTimeout(id); // Im Falle eines Fehlers den Timeout abbrechen
throw error;
}
};
export const fetchGisStatusStations = async (idMap, idUser) => {
// Verhindere wiederholte schnelle API-Aufrufe durch Debouncing
if (timeoutId) {
clearTimeout(timeoutId);
}
timeoutId = setTimeout(async () => {
const SERVER_URL = process.env.NEXT_PUBLIC_SERVER_URL;
try {
// Verwende das Timeout für die API-Anfrage
const response = await fetchWithTimeout(
`${SERVER_URL}/talas5/ClientData/WebServiceMap.asmx/GisStationsStatusDistrict?idMap=${idMap}&idUser=${idUser}`,
null,
5000 // Timeout auf 5 Sekunden gesetzt
);
if (!response.ok) {
throw new Error(`Error: ${response.statusText}`);
}
const data = await response.json();
return data;
} catch (error) {
console.error("Fehler beim Abrufen der Daten:", error);
throw error;
}
}, 500); // Debounce-Zeit auf 500ms gesetzt
};
// ----------------------------------------------
/* export const fetchPriorityConfig = async () => {
try {
@@ -113,7 +137,13 @@ export const fetchUserRights = async () => {
console.log(`fetchUserRights wurde ${userRightsRequestCount} Mal aufgerufen.`);
try {
const response = await fetch(`${process.env.NEXT_PUBLIC_SERVER_URL}/talas5/ClientData/WebserviceMap.asmx/GisSystemStatic?idMap=${config.idMap}&idUser=${config.idUser}`);
const response = await fetch(`${process.env.NEXT_PUBLIC_SERVER_URL}/talas5/ClientData/WebserviceMap.asmx/GisSystemStatic?idMap=${config.idMap}&idUser=${config.idUser}`, {
method: "GET",
headers: {
Connection: "keep-alive", // Keep-Alive Header hinzufügen
},
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}