feat: add PWA support with service worker, offline sync, and connectivity banners

- Added PWA icons for 192x192 and 512x512 resolutions.
- Implemented service worker (sw.js) for caching static assets and handling fetch requests.
- Created ConnectivityBanner component to notify users of online/offline status.
- Developed OfflineSyncPanel component to manage and display offline sync status.
- Introduced PwaInstallPrompt component to prompt users for PWA installation.
- Added PwaRegistration component to handle service worker registration and online event handling.
- Created AdminAiAuditPage for AI audit logs with filtering and review functionality.
- Developed AdminDataEthicsPage to display AI data ethics summary and recent events.
This commit is contained in:
2026-04-24 09:59:57 -04:00
parent 4148de5d66
commit e72f479639
32 changed files with 2332 additions and 74 deletions
@@ -0,0 +1,25 @@
{
"name": "OpenCCB Experience",
"short_name": "OpenCCB",
"description": "Aprendizaje en linea con soporte offline basico.",
"start_url": "/",
"scope": "/",
"display": "standalone",
"background_color": "#0b1220",
"theme_color": "#2563eb",
"orientation": "portrait-primary",
"icons": [
{
"src": "/pwa-icon-192.svg",
"sizes": "192x192",
"type": "image/svg+xml",
"purpose": "any"
},
{
"src": "/pwa-icon-512.svg",
"sizes": "512x512",
"type": "image/svg+xml",
"purpose": "any"
}
]
}
+46
View File
@@ -0,0 +1,46 @@
<!doctype html>
<html lang="es">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Sin conexion | OpenCCB</title>
<style>
body {
margin: 0;
min-height: 100vh;
display: grid;
place-items: center;
font-family: Arial, sans-serif;
background: radial-gradient(circle at 20% 20%, #1e40af, #0b1220 70%);
color: #f8fafc;
}
.card {
width: min(560px, 92vw);
padding: 2rem;
border-radius: 16px;
background: rgba(15, 23, 42, 0.82);
border: 1px solid rgba(148, 163, 184, 0.3);
}
h1 { margin: 0 0 0.75rem; font-size: 1.6rem; }
p { margin: 0.5rem 0; line-height: 1.5; color: #cbd5e1; }
button {
margin-top: 1rem;
border: 0;
border-radius: 10px;
padding: 0.75rem 1rem;
background: #2563eb;
color: #fff;
font-weight: 700;
cursor: pointer;
}
</style>
</head>
<body>
<main class="card">
<h1>No hay conexion a internet</h1>
<p>Puedes seguir usando partes ya cargadas de la plataforma mientras vuelve la conexion.</p>
<p>Cuando tengas internet, intenta recargar para sincronizar el contenido nuevo.</p>
<button onclick="location.reload()">Reintentar</button>
</main>
</body>
</html>
+4
View File
@@ -0,0 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" width="192" height="192" viewBox="0 0 192 192" role="img" aria-label="OpenCCB">
<rect width="192" height="192" rx="32" fill="#2563eb" />
<path d="M56 96c0-22.091 17.909-40 40-40h40v24H96c-8.837 0-16 7.163-16 16s7.163 16 16 16h40v24H96c-22.091 0-40-17.909-40-40z" fill="#ffffff"/>
</svg>

After

Width:  |  Height:  |  Size: 330 B

+4
View File
@@ -0,0 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 512 512" role="img" aria-label="OpenCCB">
<rect width="512" height="512" rx="84" fill="#2563eb" />
<path d="M149.333 256c0-58.909 47.758-106.667 106.667-106.667h106.667v64H256c-23.564 0-42.667 19.102-42.667 42.667 0 23.564 19.103 42.667 42.667 42.667h106.667v64H256c-58.909 0-106.667-47.758-106.667-106.667z" fill="#ffffff"/>
</svg>

After

Width:  |  Height:  |  Size: 414 B

+120
View File
@@ -0,0 +1,120 @@
const SW_VERSION = "openccb-experience-v1";
const STATIC_CACHE = `${SW_VERSION}-static`;
const PAGE_CACHE = `${SW_VERSION}-pages`;
const API_CACHE = `${SW_VERSION}-api`;
const STATIC_ASSETS = [
"/offline.html",
"/manifest.webmanifest",
"/pwa-icon-192.svg",
"/pwa-icon-512.svg",
"/next.svg",
"/window.svg",
"/globe.svg",
"/grid.svg",
"/file.svg"
];
self.addEventListener("install", (event) => {
event.waitUntil(
caches.open(STATIC_CACHE).then((cache) => cache.addAll(STATIC_ASSETS)).then(() => self.skipWaiting())
);
});
self.addEventListener("activate", (event) => {
event.waitUntil(
caches
.keys()
.then((keys) =>
Promise.all(
keys
.filter((key) => !key.startsWith(SW_VERSION))
.map((key) => caches.delete(key))
)
)
.then(async () => {
if (self.registration.navigationPreload) {
await self.registration.navigationPreload.enable();
}
await self.clients.claim();
})
);
});
self.addEventListener("message", (event) => {
if (event.data && event.data.type === "SKIP_WAITING") {
self.skipWaiting();
}
});
const isApiRequest = (url) => url.pathname.startsWith("/lms-api") || url.pathname.startsWith("/cms-api");
const isStaticRequest = (request) => ["style", "script", "image", "font"].includes(request.destination);
self.addEventListener("fetch", (event) => {
const { request } = event;
if (request.method !== "GET") return;
const url = new URL(request.url);
if (url.origin !== self.location.origin) return;
if (request.mode === "navigate") {
event.respondWith(
(async () => {
const preloadResponse = await event.preloadResponse;
if (preloadResponse) {
const preloadClone = preloadResponse.clone();
caches.open(PAGE_CACHE).then((cache) => cache.put(request, preloadClone));
return preloadResponse;
}
return fetch(request)
.then((response) => {
const clone = response.clone();
caches.open(PAGE_CACHE).then((cache) => cache.put(request, clone));
return response;
})
.catch(async () => {
const cached = await caches.match(request);
return cached || caches.match("/offline.html");
});
})()
);
return;
}
if (isApiRequest(url)) {
event.respondWith(
fetch(request)
.then((response) => {
if (response.ok) {
const clone = response.clone();
caches.open(API_CACHE).then((cache) => cache.put(request, clone));
}
return response;
})
.catch(async () => {
const cached = await caches.match(request);
if (cached) return cached;
return new Response(JSON.stringify({ message: "Offline" }), {
status: 503,
headers: { "Content-Type": "application/json" }
});
})
);
return;
}
if (isStaticRequest(request)) {
event.respondWith(
caches.match(request).then((cached) => {
if (cached) return cached;
return fetch(request).then((response) => {
if (!response || !response.ok) return response;
const clone = response.clone();
caches.open(STATIC_CACHE).then((cache) => cache.put(request, clone));
return response;
});
})
);
}
});