From ebfb7c1c8bc0a9ec50bde72eb9a0859c6e5dcee5 Mon Sep 17 00:00:00 2001 From: Ariel Costas Guerrero Date: Wed, 6 Aug 2025 21:52:21 +0200 Subject: Fix this fucking pile of steaming garbage --- src/frontend/app/routes/settings.tsx | 114 ++++++++++++++++++++++++++++++++++- 1 file changed, 113 insertions(+), 1 deletion(-) (limited to 'src/frontend/app/routes/settings.tsx') diff --git a/src/frontend/app/routes/settings.tsx b/src/frontend/app/routes/settings.tsx index c08b2c9..b75434d 100644 --- a/src/frontend/app/routes/settings.tsx +++ b/src/frontend/app/routes/settings.tsx @@ -1,6 +1,9 @@ import { useApp } from "../AppContext"; import "./settings.css"; import { useTranslation } from "react-i18next"; +import { useState } from "react"; +import { swManager } from "../utils/serviceWorkerManager"; +import { RotateCcw, Download } from "lucide-react"; export default function Settings() { const { t, i18n } = useTranslation(); @@ -13,6 +16,66 @@ export default function Settings() { setMapPositionMode, } = useApp(); + const [isCheckingUpdates, setIsCheckingUpdates] = useState(false); + const [updateMessage, setUpdateMessage] = useState(null); + + const handleCheckForUpdates = async () => { + setIsCheckingUpdates(true); + setUpdateMessage(null); + + try { + // Check if service worker is supported + if (!("serviceWorker" in navigator)) { + setUpdateMessage(t("about.sw_not_supported", "Service Workers no son compatibles en este navegador")); + return; + } + + // Force check for updates + await swManager.checkForUpdates(); + + // Wait a moment for the update check to complete + setTimeout(() => { + if (swManager.isUpdateAvailable()) { + setUpdateMessage(t("about.update_available", "¡Nueva versión disponible! Aparecerá una notificación para actualizar.")); + } else { + setUpdateMessage(t("about.up_to_date", "Ya tienes la versión más reciente.")); + } + }, 2000); + + } catch (error) { + console.error("Error checking for updates:", error); + setUpdateMessage(t("about.update_error", "Error al comprobar actualizaciones. Intenta recargar la página.")); + } finally { + setIsCheckingUpdates(false); + } + }; + + const handleClearCache = async () => { + if (confirm(t("about.clear_cache_confirm", "¿Estás seguro de que quieres limpiar la caché? Esto eliminará todos los datos guardados localmente."))) { + try { + await swManager.clearCache(); + setUpdateMessage(t("about.cache_cleared", "Caché limpiada. La página se recargará para aplicar los cambios.")); + setTimeout(() => { + window.location.reload(); + }, 2000); + } catch (error) { + console.error("Error clearing cache:", error); + setUpdateMessage(t("about.cache_error", "Error al limpiar la caché.")); + } + } + }; + + const handleResetPWA = async () => { + if (confirm(t("about.reset_pwa_confirm", "¿Estás seguro? Esto eliminará TODOS los datos de la aplicación y la reiniciará completamente. Úsalo solo si hay problemas graves de caché."))) { + try { + await swManager.resetPWA(); + } catch (error) { + console.error("Error resetting PWA:", error); + setUpdateMessage(t("about.reset_pwa_error", "Error al reiniciar la PWA.")); + } + } + }; + return (

{t("about.title")}

@@ -67,7 +130,7 @@ export default function Settings() {