fix(pwa): optimize responsive mobile UI, safe area insets, navigation bar and stable SW v7

This commit is contained in:
unknown
2026-10-04 20:18:06 -06:00
parent cfa8efbc0a
commit e6ea875411
5 changed files with 525 additions and 91 deletions
+321 -18
View File
@@ -3,6 +3,10 @@
========================================================================== */ ========================================================================== */
:root { :root {
--safe-top: env(safe-area-inset-top, 0px);
--safe-bottom: env(safe-area-inset-bottom, 0px);
--safe-left: env(safe-area-inset-left, 0px);
--safe-right: env(safe-area-inset-right, 0px);
--primary: #0284c7; --primary: #0284c7;
--primary-hover: #0369a1; --primary-hover: #0369a1;
--secondary: #10b981; --secondary: #10b981;
@@ -33,7 +37,7 @@ body.dark-mode {
--shadow: 0 10px 20px -3px rgba(0, 0, 0, 0.5); --shadow: 0 10px 20px -3px rgba(0, 0, 0, 0.5);
} }
* { *, *::before, *::after {
box-sizing: border-box; box-sizing: border-box;
margin: 0; margin: 0;
padding: 0; padding: 0;
@@ -41,10 +45,23 @@ body.dark-mode {
-webkit-tap-highlight-color: transparent; -webkit-tap-highlight-color: transparent;
} }
html {
width: 100%;
max-width: 100vw;
overflow-x: hidden;
position: relative;
-webkit-text-size-adjust: 100%;
}
body { body {
background-color: var(--bg-main); background-color: var(--bg-main);
color: var(--text-main); color: var(--text-main);
min-height: 100vh; min-height: 100vh;
min-height: -webkit-fill-available;
width: 100%;
max-width: 100vw;
overflow-x: hidden;
position: relative;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
transition: background-color 0.3s ease, color 0.3s ease; transition: background-color 0.3s ease, color 0.3s ease;
@@ -55,13 +72,14 @@ body {
max-width: 480px; max-width: 480px;
margin: 0 auto; margin: 0 auto;
width: 100%; width: 100%;
padding-bottom: 90px; padding-bottom: calc(90px + var(--safe-bottom));
box-sizing: border-box;
} }
/* Top App Bar */ /* Top App Bar */
.top-bar { .top-bar {
background: var(--card-bg); background: var(--card-bg);
padding: 14px 18px; padding: calc(12px + var(--safe-top)) 16px 12px 16px;
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
@@ -70,6 +88,35 @@ body {
top: 0; top: 0;
z-index: 40; z-index: 40;
box-shadow: var(--shadow); box-shadow: var(--shadow);
width: 100%;
box-sizing: border-box;
}
@media (max-width: 480px) {
.top-bar {
padding: calc(10px + var(--safe-top)) 12px 10px 12px;
}
.brand-badge {
font-size: 1.05rem;
gap: 6px;
}
.brand-badge .logo-icon {
width: 32px;
height: 32px;
font-size: 1.05rem;
}
.top-actions {
gap: 5px;
}
.theme-toggle-btn {
width: 34px;
height: 34px;
font-size: 1.05rem;
}
.logout-btn {
padding: 6px 10px;
font-size: 0.75rem;
}
} }
.brand-badge { .brand-badge {
@@ -161,6 +208,13 @@ body.dark-mode .logout-btn {
border: 1px solid rgba(255, 255, 255, 0.2); border: 1px solid rgba(255, 255, 255, 0.2);
} }
@media (max-width: 480px) {
.wallet-card {
margin: 12px 10px;
padding: 16px 14px;
}
}
body.dark-mode .wallet-card { body.dark-mode .wallet-card {
background: linear-gradient(135deg, #1e293b, #0f172a); background: linear-gradient(135deg, #1e293b, #0f172a);
border: 1px solid #334155; border: 1px solid #334155;
@@ -208,10 +262,39 @@ body.dark-mode .wallet-card {
margin-top: 2px; margin-top: 2px;
} }
.wallet-logout-pill {
background: rgba(255, 255, 255, 0.2);
border: 1px solid rgba(255, 255, 255, 0.4);
color: #ffffff;
font-size: 0.74rem;
font-weight: 800;
padding: 5px 11px;
border-radius: 9999px;
cursor: pointer;
display: inline-flex;
align-items: center;
gap: 4px;
white-space: nowrap;
transition: all 0.15s ease;
backdrop-filter: blur(4px);
-webkit-backdrop-filter: blur(4px);
flex-shrink: 0;
}
.wallet-logout-pill:hover,
.wallet-logout-pill:active {
background: #ef4444;
border-color: #ef4444;
color: #ffffff;
transform: scale(0.96);
}
.balance-row { .balance-row {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: flex-end; align-items: flex-end;
flex-wrap: wrap;
gap: 10px;
border-top: 1px solid rgba(255, 255, 255, 0.2); border-top: 1px solid rgba(255, 255, 255, 0.2);
padding-top: 14px; padding-top: 14px;
} }
@@ -267,25 +350,39 @@ body.dark-mode .wallet-card {
.modal-qr-backdrop { .modal-qr-backdrop {
position: fixed; position: fixed;
inset: 0; inset: 0;
background: rgba(15, 23, 42, 0.8); background: rgba(15, 23, 42, 0.82);
backdrop-filter: blur(6px); backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
z-index: 100; z-index: 200;
padding: 20px; padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom)) 16px;
overflow-y: auto;
box-sizing: border-box;
} }
.modal-qr-card { .modal-qr-card {
background: white; background: var(--card-bg, #ffffff);
color: var(--text-main, #0f172a);
border-radius: 24px; border-radius: 24px;
padding: 26px 20px; padding: 24px 18px;
max-width: 340px; max-width: 360px;
width: 100%; width: 100%;
text-align: center; text-align: center;
box-shadow: 0 20px 40px rgba(0,0,0,0.3); box-shadow: 0 20px 40px rgba(0,0,0,0.3);
position: relative; position: relative;
animation: zoomIn 0.25s cubic-bezier(0.16, 1, 0.3, 1); animation: zoomIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
box-sizing: border-box;
max-height: calc(100vh - 36px - var(--safe-top) - var(--safe-bottom));
overflow-y: auto;
}
@media (max-width: 480px) {
.modal-qr-card {
padding: 18px 14px;
border-radius: 20px;
}
} }
@keyframes zoomIn { @keyframes zoomIn {
@@ -480,6 +577,15 @@ body.dark-mode .wallet-card {
cursor: pointer; cursor: pointer;
} }
@media (max-width: 640px) {
.floating-cart-bar {
bottom: calc(72px + var(--safe-bottom));
left: 12px;
right: 12px;
padding: 10px 14px;
}
}
body.dark-mode .floating-cart-bar { body.dark-mode .floating-cart-bar {
background: #0284c7; background: #0284c7;
border: 1px solid rgba(255, 255, 255, 0.2); border: 1px solid rgba(255, 255, 255, 0.2);
@@ -1105,8 +1211,11 @@ body.dark-mode .floating-cart-bar {
margin: 0 auto; margin: 0 auto;
min-height: 100vh; min-height: 100vh;
background: var(--bg-main, #f8fafc); background: var(--bg-main, #f8fafc);
padding: 16px 16px 60px 16px; padding: calc(16px + var(--safe-top)) 16px calc(60px + var(--safe-bottom)) 16px;
box-sizing: border-box; box-sizing: border-box;
width: 100%;
max-width: 100vw;
overflow-x: hidden;
} }
.admin-header { .admin-header {
@@ -1119,6 +1228,34 @@ body.dark-mode .floating-cart-bar {
padding: 14px 18px; padding: 14px 18px;
margin-bottom: 16px; margin-bottom: 16px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
flex-wrap: wrap;
gap: 12px;
}
.admin-header-actions {
display: flex;
gap: 8px;
align-items: center;
flex-wrap: wrap;
}
.admin-action-btn-caja {
padding: 7px 12px;
background: #0284c7;
color: #ffffff;
border-radius: 10px;
font-size: 0.78rem;
font-weight: 800;
text-decoration: none;
display: inline-flex;
align-items: center;
gap: 4px;
white-space: nowrap;
transition: background 0.15s ease;
}
.admin-action-btn-caja:hover {
background: #0369a1;
} }
.admin-badge { .admin-badge {
@@ -1169,6 +1306,11 @@ body.dark-mode .floating-cart-bar {
margin-bottom: 16px; margin-bottom: 16px;
overflow-x: auto; overflow-x: auto;
padding-bottom: 4px; padding-bottom: 4px;
scrollbar-width: none;
}
.admin-tabs::-webkit-scrollbar {
display: none;
} }
.admin-tab-btn { .admin-tab-btn {
@@ -1185,6 +1327,7 @@ body.dark-mode .floating-cart-bar {
gap: 6px; gap: 6px;
white-space: nowrap; white-space: nowrap;
transition: all 0.15s; transition: all 0.15s;
flex-shrink: 0;
} }
.admin-tab-btn.active { .admin-tab-btn.active {
@@ -1203,21 +1346,55 @@ body.dark-mode .floating-cart-bar {
margin-bottom: 16px; margin-bottom: 16px;
} }
/* Tabla / Lista de Inventario Admin */ /* Tabla / Lista de Inventario Admin Responsive */
.inventory-item-row { .inventory-item-row {
display: grid; display: flex;
grid-template-columns: 44px 1fr auto auto; flex-direction: column;
align-items: center; gap: 10px;
gap: 12px;
padding: 12px; padding: 12px;
border-bottom: 1px solid var(--border, #f1f5f9); border-bottom: 1px solid var(--border, #f1f5f9);
transition: background 0.15s; transition: background 0.15s;
width: 100%;
box-sizing: border-box;
}
@media (min-width: 640px) {
.inventory-item-row {
flex-direction: row;
align-items: center;
justify-content: space-between;
}
} }
.inventory-item-row:last-child { .inventory-item-row:last-child {
border-bottom: none; border-bottom: none;
} }
.inventory-item-top {
display: flex;
align-items: center;
gap: 12px;
flex: 1;
min-width: 0;
}
.inventory-item-bottom {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
flex-shrink: 0;
width: 100%;
}
@media (min-width: 640px) {
.inventory-item-bottom {
width: auto;
justify-content: flex-end;
gap: 12px;
}
}
.inventory-stock-controls { .inventory-stock-controls {
display: flex; display: flex;
align-items: center; align-items: center;
@@ -1225,11 +1402,11 @@ body.dark-mode .floating-cart-bar {
} }
.stock-btn-quick { .stock-btn-quick {
padding: 5px 9px; padding: 6px 10px;
background: #f1f5f9; background: #f1f5f9;
border: 1px solid #cbd5e1; border: 1px solid #cbd5e1;
border-radius: 8px; border-radius: 8px;
font-size: 0.78rem; font-size: 0.8rem;
font-weight: 800; font-weight: 800;
cursor: pointer; cursor: pointer;
color: #1e293b; color: #1e293b;
@@ -1239,6 +1416,44 @@ body.dark-mode .floating-cart-bar {
background: #e2e8f0; background: #e2e8f0;
} }
.admin-student-card {
transition: transform 0.15s ease, box-shadow 0.15s ease;
}
@media (max-width: 600px) {
.admin-container {
padding: calc(12px + var(--safe-top)) 10px calc(80px + var(--safe-bottom)) 10px;
}
.admin-header {
flex-direction: column;
align-items: flex-start;
gap: 10px;
padding: 12px;
}
.admin-header-actions {
width: 100%;
justify-content: space-between;
}
.admin-stats-grid {
grid-template-columns: repeat(2, 1fr);
gap: 8px;
}
.admin-stat-card {
padding: 10px 8px;
}
.admin-stat-card .val {
font-size: 1.25rem;
}
.admin-tab-btn {
padding: 8px 12px;
font-size: 0.8rem;
}
.admin-card {
padding: 14px 12px;
border-radius: 14px;
}
}
/* ========================================================================== /* ==========================================================================
PRODUCTO AGOTADO (GREYED OUT) Y TARJETA BLOQUEADA PRODUCTO AGOTADO (GREYED OUT) Y TARJETA BLOQUEADA
========================================================================== */ ========================================================================== */
@@ -1290,3 +1505,91 @@ body.dark-mode .banner-card-blocked {
border-color: #ef4444; border-color: #ef4444;
} }
/* ==========================================================================
BARRA DE NAVEGACIÓN INFERIOR PWA (MÓVILES)
========================================================================== */
.pwa-bottom-nav {
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: calc(62px + var(--safe-bottom));
padding-bottom: var(--safe-bottom);
background: var(--card-bg, #ffffff);
border-top: 1px solid var(--border, #e2e8f0);
box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
display: flex;
justify-content: space-around;
align-items: center;
z-index: 100;
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
@media (min-width: 641px) {
.pwa-bottom-nav {
display: none !important;
}
}
body.dark-mode .pwa-bottom-nav {
background: rgba(30, 41, 59, 0.95);
border-color: #334155;
box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.4);
}
.pwa-nav-item {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background: transparent;
border: none;
outline: none;
cursor: pointer;
padding: 6px 0;
color: var(--text-muted, #64748b);
transition: all 0.15s ease;
min-width: 0;
user-select: none;
-webkit-tap-highlight-color: transparent;
}
.pwa-nav-item:active {
transform: scale(0.92);
}
.pwa-nav-icon {
font-size: 1.35rem;
line-height: 1;
display: block;
}
.pwa-nav-label {
font-size: 0.68rem;
font-weight: 700;
margin-top: 3px;
line-height: 1;
display: block;
white-space: nowrap;
}
.pwa-nav-item.active {
color: var(--primary, #0284c7);
}
.pwa-nav-item.active .pwa-nav-icon {
transform: scale(1.1);
transition: transform 0.15s ease;
}
.pwa-nav-logout {
color: #ef4444 !important;
}
.pwa-nav-logout:active {
background: rgba(239, 68, 68, 0.1);
border-radius: 8px;
}
+46 -24
View File
@@ -2,24 +2,15 @@
<html lang="es"> <html lang="es">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
<title>RecreoPay - Tu Soda Escolar Digital</title> <title>RecreoPay - Tu Soda Escolar Digital</title>
<link rel="manifest" href="/manifest.json"> <link rel="manifest" href="/manifest.json">
<meta name="theme-color" content="#0284c7"> <meta name="theme-color" content="#0284c7">
<link rel="stylesheet" href="/css/styles.css?v=6.0"> <meta name="apple-mobile-web-app-capable" content="yes">
<script> <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
// Purgar y desactivar service workers y cachés obsoletas en móviles <meta name="apple-mobile-web-app-title" content="RecreoPay">
if ('serviceWorker' in navigator) { <meta name="mobile-web-app-capable" content="yes">
navigator.serviceWorker.getRegistrations().then(function(regs) { <link rel="stylesheet" href="/css/styles.css?v=7.0">
for (var r of regs) { r.unregister(); }
});
}
if ('caches' in window) {
caches.keys().then(function(names) {
for (var n of names) { caches.delete(n); }
});
}
</script>
<style> <style>
/* Transiciones suaves */ /* Transiciones suaves */
.fade-enter { animation: fadeIn 0.2s ease-in-out; } .fade-enter { animation: fadeIn 0.2s ease-in-out; }
@@ -88,14 +79,14 @@
</div> </div>
</div> </div>
<div style="display: flex; gap: 8px; align-items: center;"> <div class="admin-header-actions">
<button onclick="toggleTheme()" class="theme-toggle-btn" title="Alternar Modo Oscuro / Modo Claro"> <button onclick="toggleTheme()" class="theme-toggle-btn" title="Alternar Modo Oscuro / Modo Claro">
🌙 🌙
</button> </button>
<a href="/pos.html" target="_blank" style="padding: 7px 12px; background: #0284c7; color: white; border-radius: 10px; font-size: 0.78rem; font-weight: 800; text-decoration: none;" title="Abrir Caja / Terminal POS"> <a href="/pos.html" target="_blank" class="admin-action-btn-caja" title="Abrir Caja / Terminal POS">
📟 Ir a Caja 📟 Ir a Caja
</a> </a>
<button onclick="logout()" class="logout-btn" title="Cerrar sesión"> <button onclick="logout(true)" class="logout-btn" title="Cerrar sesión y cambiar de cuenta">
<span>🚪</span> <span>🚪</span>
<span class="logout-text">Salir</span> <span class="logout-text">Salir</span>
</button> </button>
@@ -259,7 +250,7 @@
<button id="btnModePadres" onclick="toggleParentPanel(true)" class="mode-btn" style="background: var(--bg-main); border: 1.5px solid var(--border); font-size: 0.8rem; font-weight: 800; border-radius: 10px; padding: 7px 11px; cursor: pointer; color: var(--text-main);" title="Acceso al Portal de Padres"> <button id="btnModePadres" onclick="toggleParentPanel(true)" class="mode-btn" style="background: var(--bg-main); border: 1.5px solid var(--border); font-size: 0.8rem; font-weight: 800; border-radius: 10px; padding: 7px 11px; cursor: pointer; color: var(--text-main);" title="Acceso al Portal de Padres">
👨‍👩‍👦 Padres 👨‍👩‍👦 Padres
</button> </button>
<button id="btnLogout" onclick="logout()" class="logout-btn" title="Cerrar sesión"> <button id="btnLogout" onclick="logout(true)" class="logout-btn" title="Cerrar sesión y cambiar de cuenta">
<span>🚪</span> <span>🚪</span>
<span class="logout-text">Salir</span> <span class="logout-text">Salir</span>
</button> </button>
@@ -273,9 +264,16 @@
<section class="wallet-card"> <section class="wallet-card">
<div class="student-info"> <div class="student-info">
<img id="walletAvatar" class="student-avatar" src="" alt="Avatar"> <img id="walletAvatar" class="student-avatar" src="" alt="Avatar">
<div class="student-meta"> <div class="student-meta" style="flex: 1; min-width: 0;">
<h2 id="walletName">Cargando...</h2> <div style="display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;">
<span id="walletGrade" class="student-grade">Grado y Sección</span> <div style="min-width: 0;">
<h2 id="walletName" style="word-break: break-word; margin: 0; font-size: 1.15rem; font-weight: 800;">Cargando...</h2>
<span id="walletGrade" class="student-grade">Grado y Sección</span>
</div>
<button type="button" onclick="logout(true)" class="wallet-logout-pill" title="Cerrar sesión o cambiar de estudiante">
<span>🚪 Salir</span>
</button>
</div>
</div> </div>
</div> </div>
@@ -734,8 +732,32 @@
</div> </div>
</div> </div>
<script src="/js/sounds.js?v=6.0"></script> <!-- BARRA DE NAVEGACIÓN INFERIOR PWA (MÓVILES) -->
<nav class="pwa-bottom-nav" id="pwaBottomNav" style="display: none;">
<button class="pwa-nav-item active" id="pwaNavMenu" onclick="pwaNavigateTo('menu')">
<span class="pwa-nav-icon">🥪</span>
<span class="pwa-nav-label">Menú</span>
</button>
<button class="pwa-nav-item" id="pwaNavQr" onclick="pwaNavigateTo('qr')">
<span class="pwa-nav-icon">📱</span>
<span class="pwa-nav-label">Mi QR</span>
</button>
<button class="pwa-nav-item" id="pwaNavTransfer" onclick="pwaNavigateTo('transfer')">
<span class="pwa-nav-icon">⚡</span>
<span class="pwa-nav-label">Transferir</span>
</button>
<button class="pwa-nav-item" id="pwaNavPadres" onclick="pwaNavigateTo('padres')">
<span class="pwa-nav-icon">👨‍👩‍👦</span>
<span class="pwa-nav-label">Padres</span>
</button>
<button class="pwa-nav-item pwa-nav-logout" onclick="logout(true)" title="Cerrar sesión y cambiar de cuenta">
<span class="pwa-nav-icon">🚪</span>
<span class="pwa-nav-label">Salir</span>
</button>
</nav>
<script src="/js/sounds.js?v=7.0"></script>
<script src="/js/jsQR.js"></script> <script src="/js/jsQR.js"></script>
<script src="/js/app.js?v=6.0"></script> <script src="/js/app.js?v=7.0"></script>
</body> </body>
</html> </html>
+94 -34
View File
@@ -51,8 +51,8 @@ document.addEventListener('DOMContentLoaded', async () => {
// Registrar Service Worker para PWA // Registrar Service Worker para PWA
if ('serviceWorker' in navigator) { if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js?v=6.0').then(reg => { navigator.serviceWorker.register('/sw.js?v=7.0').then(reg => {
reg.update(); // Registro limpio sin recargas forzadas
}).catch(err => console.log('SW error:', err)); }).catch(err => console.log('SW error:', err));
} }
@@ -84,10 +84,12 @@ function showLoginView() {
const viewLogin = document.getElementById('viewLogin'); const viewLogin = document.getElementById('viewLogin');
const viewAdmin = document.getElementById('viewAdmin'); const viewAdmin = document.getElementById('viewAdmin');
const appContainer = document.getElementById('appContainer'); const appContainer = document.getElementById('appContainer');
const bottomNav = document.getElementById('pwaBottomNav');
if (viewLogin) viewLogin.style.display = 'flex'; if (viewLogin) viewLogin.style.display = 'flex';
if (viewAdmin) viewAdmin.style.display = 'none'; if (viewAdmin) viewAdmin.style.display = 'none';
if (appContainer) appContainer.style.display = 'none'; if (appContainer) appContainer.style.display = 'none';
if (bottomNav) bottomNav.style.display = 'none';
// Cerrar cualquier modal que pudiera estar abierto // Cerrar cualquier modal que pudiera estar abierto
toggleParentPanel(false); toggleParentPanel(false);
@@ -160,18 +162,23 @@ async function applyUserRoleSession() {
const viewLogin = document.getElementById('viewLogin'); const viewLogin = document.getElementById('viewLogin');
const viewAdmin = document.getElementById('viewAdmin'); const viewAdmin = document.getElementById('viewAdmin');
const appContainer = document.getElementById('appContainer'); const appContainer = document.getElementById('appContainer');
const bottomNav = document.getElementById('pwaBottomNav');
const navPadres = document.getElementById('pwaNavPadres');
if (viewLogin) viewLogin.style.display = 'none'; if (viewLogin) viewLogin.style.display = 'none';
if (currentUser.rol === 'admin') { if (currentUser.rol === 'admin') {
if (viewAdmin) viewAdmin.style.display = 'block'; if (viewAdmin) viewAdmin.style.display = 'block';
if (appContainer) appContainer.style.display = 'none'; if (appContainer) appContainer.style.display = 'none';
if (bottomNav) bottomNav.style.display = 'none';
const adminNameEl = document.getElementById('adminLoggedName'); const adminNameEl = document.getElementById('adminLoggedName');
if (adminNameEl) adminNameEl.textContent = `${currentUser.nombre} (Administrador)`; if (adminNameEl) adminNameEl.textContent = `${currentUser.nombre} (Administrador)`;
await loadAdminData(); await loadAdminData();
} else if (currentUser.rol === 'padre') { } else if (currentUser.rol === 'padre') {
if (viewAdmin) viewAdmin.style.display = 'none'; if (viewAdmin) viewAdmin.style.display = 'none';
if (appContainer) appContainer.style.display = 'block'; if (appContainer) appContainer.style.display = 'block';
if (bottomNav) bottomNav.style.display = 'flex';
if (navPadres) navPadres.style.display = 'flex';
// Mostrar botón de acceso al portal de padres // Mostrar botón de acceso al portal de padres
const btnPadres = document.getElementById('btnModePadres'); const btnPadres = document.getElementById('btnModePadres');
@@ -184,6 +191,8 @@ async function applyUserRoleSession() {
// Estudiante: SEGURIDAD ESTRICTA - Ocultar botón de padres // Estudiante: SEGURIDAD ESTRICTA - Ocultar botón de padres
if (viewAdmin) viewAdmin.style.display = 'none'; if (viewAdmin) viewAdmin.style.display = 'none';
if (appContainer) appContainer.style.display = 'block'; if (appContainer) appContainer.style.display = 'block';
if (bottomNav) bottomNav.style.display = 'flex';
if (navPadres) navPadres.style.display = 'none'; // Estudiantes no ven pestaña padres
const btnPadres = document.getElementById('btnModePadres'); const btnPadres = document.getElementById('btnModePadres');
if (btnPadres) btnPadres.style.display = 'none'; if (btnPadres) btnPadres.style.display = 'none';
@@ -197,8 +206,8 @@ async function applyUserRoleSession() {
} }
} }
function logout() { function logout(skipConfirm = false) {
if (confirm('¿Deseas cerrar la sesión en RecreoPay?')) { if (skipConfirm || confirm('¿Deseas cerrar sesión para seleccionar otra cuenta?')) {
localStorage.removeItem('recreopay_user'); localStorage.removeItem('recreopay_user');
currentUser = null; currentUser = null;
currentStudent = null; currentStudent = null;
@@ -207,6 +216,39 @@ function logout() {
} }
} }
// Navegación PWA móvil con barra inferior
function pwaNavigateTo(target) {
document.querySelectorAll('.pwa-nav-item').forEach(b => b.classList.remove('active'));
if (target === 'menu') {
const btn = document.getElementById('pwaNavMenu');
if (btn) btn.classList.add('active');
closeQrModal();
closeTransferModal();
toggleParentPanel(false);
closeCartModal();
window.scrollTo({ top: 0, behavior: 'smooth' });
} else if (target === 'qr') {
const btn = document.getElementById('pwaNavQr');
if (btn) btn.classList.add('active');
closeTransferModal();
toggleParentPanel(false);
openQrModal();
} else if (target === 'transfer') {
const btn = document.getElementById('pwaNavTransfer');
if (btn) btn.classList.add('active');
closeQrModal();
toggleParentPanel(false);
openTransferModal();
} else if (target === 'padres') {
const btn = document.getElementById('pwaNavPadres');
if (btn) btn.classList.add('active');
closeQrModal();
closeTransferModal();
toggleParentPanel(true);
}
}
async function loadInitialData() { async function loadInitialData() {
try { try {
// 1. Cargar estudiantes // 1. Cargar estudiantes
@@ -597,9 +639,19 @@ function openQrModal() {
document.getElementById('modalQr').style.display = 'flex'; document.getElementById('modalQr').style.display = 'flex';
} }
function resetPwaNavActive() {
const menuBtn = document.getElementById('pwaNavMenu');
if (menuBtn) {
document.querySelectorAll('.pwa-nav-item').forEach(b => b.classList.remove('active'));
menuBtn.classList.add('active');
}
}
function closeQrModal(e) { function closeQrModal(e) {
if (e && e.target !== e.currentTarget) return; if (e && e.target !== e.currentTarget) return;
document.getElementById('modalQr').style.display = 'none'; const modal = document.getElementById('modalQr');
if (modal) modal.style.display = 'none';
resetPwaNavActive();
} }
// ========================================== // ==========================================
@@ -611,11 +663,13 @@ function toggleParentPanel(show, e) {
if (currentUser && currentUser.rol === 'estudiante') { if (currentUser && currentUser.rol === 'estudiante') {
const modalPadres = document.getElementById('modalPadres'); const modalPadres = document.getElementById('modalPadres');
if (modalPadres) modalPadres.style.display = 'none'; if (modalPadres) modalPadres.style.display = 'none';
resetPwaNavActive();
return; return;
} }
if (e && e.target !== e.currentTarget) return; if (e && e.target !== e.currentTarget) return;
const modalPadres = document.getElementById('modalPadres'); const modalPadres = document.getElementById('modalPadres');
if (modalPadres) modalPadres.style.display = show ? 'flex' : 'none'; if (modalPadres) modalPadres.style.display = show ? 'flex' : 'none';
if (!show) resetPwaNavActive();
} }
function openDailyLimitEditor() { function openDailyLimitEditor() {
@@ -825,7 +879,9 @@ function openTransferModal() {
function closeTransferModal(e) { function closeTransferModal(e) {
if (e && e.target !== e.currentTarget) return; if (e && e.target !== e.currentTarget) return;
stopTransferCamera(); stopTransferCamera();
document.getElementById('modalTransfer').style.display = 'none'; const modal = document.getElementById('modalTransfer');
if (modal) modal.style.display = 'none';
resetPwaNavActive();
} }
function renderQuickTransferFriends() { function renderQuickTransferFriends() {
@@ -1462,29 +1518,33 @@ function renderAdminInventory(list) {
return ` return `
<div class="inventory-item-row" style="${isOutOfStock ? 'background: #fff1f2;' : ''}"> <div class="inventory-item-row" style="${isOutOfStock ? 'background: #fff1f2;' : ''}">
<div style="font-size: 1.8rem; text-align: center;">${p.icono || '🥪'}</div> <div class="inventory-item-top">
<div> <div style="font-size: 1.8rem; text-align: center; flex-shrink: 0; min-width: 40px;">${p.icono || '🥪'}</div>
<div style="display: flex; align-items: center; gap: 6px; flex-wrap: wrap;"> <div style="flex: 1; min-width: 0;">
<strong style="font-size: 0.92rem; color: var(--text-main);">${p.nombre}</strong> <div style="display: flex; align-items: center; gap: 6px; flex-wrap: wrap;">
${statusPill} <strong style="font-size: 0.92rem; color: var(--text-main); word-break: break-word;">${p.nombre}</strong>
</div> ${statusPill}
<div style="font-size: 0.74rem; color: var(--text-muted); margin-top: 2px;"> </div>
${p.categoria_nombre || 'General'} • ₡${p.precio_colones.toLocaleString('es-CR')} <div style="font-size: 0.74rem; color: var(--text-muted); margin-top: 2px;">
${p.categoria_nombre || 'General'} • ₡${p.precio_colones.toLocaleString('es-CR')}
</div>
</div> </div>
</div> </div>
<!-- Controles rápidos de stock --> <!-- Controles rápidos de stock -->
<div class="inventory-stock-controls"> <div class="inventory-item-bottom">
<button type="button" class="stock-btn-quick" onclick="quickAdjustStock(${p.id}, -1)" title="Restar 1">-1</button> <div class="inventory-stock-controls">
<input type="number" id="inputStock_${p.id}" value="${p.stock || 0}" min="0" style="width: 54px; text-align: center; padding: 5px; border-radius: 8px; border: 1.5px solid var(--border); font-weight: 900; font-size: 0.95rem; background: var(--card-bg); color: var(--text-main);"> <button type="button" class="stock-btn-quick" onclick="quickAdjustStock(${p.id}, -1)" title="Restar 1">-1</button>
<button type="button" class="stock-btn-quick" onclick="quickAdjustStock(${p.id}, 5)" title="Sumar 5">+5</button> <input type="number" id="inputStock_${p.id}" value="${p.stock || 0}" min="0" style="width: 50px; text-align: center; padding: 5px; border-radius: 8px; border: 1.5px solid var(--border); font-weight: 900; font-size: 0.95rem; background: var(--card-bg); color: var(--text-main);">
<button type="button" class="stock-btn-quick" onclick="quickAdjustStock(${p.id}, 10)" title="Sumar 10">+10</button> <button type="button" class="stock-btn-quick" onclick="quickAdjustStock(${p.id}, 5)" title="Sumar 5">+5</button>
</div> <button type="button" class="stock-btn-quick" onclick="quickAdjustStock(${p.id}, 10)" title="Sumar 10">+10</button>
</div>
<div> <div>
<button type="button" onclick="saveProductStock(${p.id})" style="padding: 7px 12px; background: #0284c7; color: white; border: none; border-radius: 8px; font-size: 0.78rem; font-weight: 800; cursor: pointer;"> <button type="button" onclick="saveProductStock(${p.id})" style="padding: 7px 14px; background: #0284c7; color: white; border: none; border-radius: 8px; font-size: 0.8rem; font-weight: 800; cursor: pointer; white-space: nowrap;">
💾 Guardar 💾 Guardar
</button> </button>
</div>
</div> </div>
</div> </div>
`; `;
@@ -1543,28 +1603,28 @@ function renderAdminStudents(list) {
${list.map(s => { ${list.map(s => {
const isBlocked = s.tarjeta_bloqueada === 1; const isBlocked = s.tarjeta_bloqueada === 1;
return ` return `
<div style="display: flex; align-items: center; justify-content: space-between; padding: 12px; border-radius: 12px; border: 1.5px solid ${isBlocked ? '#fca5a5' : 'var(--border)'}; background: ${isBlocked ? '#fff5f5' : 'var(--card-bg)'}; flex-wrap: wrap; gap: 10px;"> <div class="admin-student-card" style="display: flex; flex-direction: column; gap: 10px; padding: 12px; border-radius: 12px; border: 1.5px solid ${isBlocked ? '#fca5a5' : 'var(--border)'}; background: ${isBlocked ? '#fff5f5' : 'var(--card-bg)'}; width: 100%; box-sizing: border-box;">
<div style="display: flex; align-items: center; gap: 12px;"> <div style="display: flex; align-items: center; gap: 10px; width: 100%;">
<img src="${s.foto_url || 'https://api.dicebear.com/7.x/bottts/svg?seed=est'}" style="width: 44px; height: 44px; border-radius: 50%; border: 2px solid ${isBlocked ? '#ef4444' : '#0284c7'}; background: white;"> <img src="${s.foto_url || 'https://api.dicebear.com/7.x/bottts/svg?seed=est'}" style="width: 44px; height: 44px; border-radius: 50%; border: 2px solid ${isBlocked ? '#ef4444' : '#0284c7'}; background: white; flex-shrink: 0;">
<div> <div style="flex: 1; min-width: 0; word-break: break-word;">
<div style="display: flex; align-items: center; gap: 8px;"> <div style="display: flex; align-items: center; gap: 6px; flex-wrap: wrap;">
<strong style="font-size: 0.95rem; color: var(--text-main);">${s.nombre_completo}</strong> <strong style="font-size: 0.95rem; color: var(--text-main);">${s.nombre_completo}</strong>
${isBlocked ? '<span style="font-size: 0.68rem; font-weight: 900; background: #ef4444; color: white; padding: 2px 7px; border-radius: 5px;">⛔ SUSPENDIDA</span>' : '<span style="font-size: 0.68rem; font-weight: 800; background: #dcfce7; color: #166534; padding: 2px 7px; border-radius: 5px;">ACTIVA</span>'} ${isBlocked ? '<span style="font-size: 0.68rem; font-weight: 900; background: #ef4444; color: white; padding: 2px 7px; border-radius: 5px;">⛔ SUSPENDIDA</span>' : '<span style="font-size: 0.68rem; font-weight: 800; background: #dcfce7; color: #166534; padding: 2px 7px; border-radius: 5px;">ACTIVA</span>'}
</div> </div>
<div style="font-size: 0.75rem; color: var(--text-muted); margin-top: 2px;"> <div style="font-size: 0.74rem; color: var(--text-muted); margin-top: 2px;">
${s.grado} • Sección ${s.seccion} • Cód: <strong>${s.codigo_estudiante}</strong> • PIN: <strong>${s.pin_seguridad || '1234'}</strong> ${s.grado} • Sección ${s.seccion} • Cód: <strong>${s.codigo_estudiante}</strong> • PIN: <strong>${s.pin_seguridad || '1234'}</strong>
</div> </div>
<div style="font-size: 0.78rem; font-weight: 800; color: #0284c7; margin-top: 3px;"> <div style="font-size: 0.76rem; font-weight: 800; color: #0284c7; margin-top: 3px;">
Saldo: ₡${s.saldo_colones.toLocaleString('es-CR')} | Límite: ₡${s.limite_diario_colones.toLocaleString('es-CR')}/día Saldo: ₡${s.saldo_colones.toLocaleString('es-CR')} | Límite: ₡${s.limite_diario_colones.toLocaleString('es-CR')}/día
</div> </div>
</div> </div>
</div> </div>
<div style="display: flex; gap: 8px; align-items: center;"> <div style="display: flex; gap: 8px; align-items: center; justify-content: flex-end; border-top: 1px dashed var(--border); padding-top: 8px; width: 100%;">
<a href="/carnet.html" target="_blank" style="padding: 7px 10px; background: #e0f2fe; color: #0369a1; border-radius: 8px; font-size: 0.76rem; font-weight: 800; text-decoration: none;" title="Ver e Imprimir Carné Físico"> <a href="/carnet.html?id=${s.id}" target="_blank" style="padding: 7px 12px; background: #e0f2fe; color: #0369a1; border-radius: 8px; font-size: 0.76rem; font-weight: 800; text-decoration: none;" title="Ver e Imprimir Carné Físico">
🖨️ Carné 🖨️ Carné
</a> </a>
<button type="button" onclick="toggleBlockCard(${s.id}, ${isBlocked ? 0 : 1})" style="padding: 7px 12px; background: ${isBlocked ? '#10b981' : '#ef4444'}; color: white; border: none; border-radius: 8px; font-size: 0.78rem; font-weight: 900; cursor: pointer;"> <button type="button" onclick="toggleBlockCard(${s.id}, ${isBlocked ? 0 : 1})" style="padding: 7px 14px; background: ${isBlocked ? '#10b981' : '#ef4444'}; color: white; border: none; border-radius: 8px; font-size: 0.78rem; font-weight: 900; cursor: pointer;">
${isBlocked ? '✅ Desbloquear' : '⛔ Bloquear Tarjeta'} ${isBlocked ? '✅ Desbloquear' : '⛔ Bloquear Tarjeta'}
</button> </button>
</div> </div>
+3
View File
@@ -2,7 +2,10 @@
"name": "RecreoPay - Soda Escolar Costa Rica", "name": "RecreoPay - Soda Escolar Costa Rica",
"short_name": "RecreoPay", "short_name": "RecreoPay",
"start_url": "/index.html", "start_url": "/index.html",
"scope": "/",
"id": "recreopay-pwa",
"display": "standalone", "display": "standalone",
"orientation": "portrait",
"background_color": "#0f172a", "background_color": "#0f172a",
"theme_color": "#0284c7", "theme_color": "#0284c7",
"description": "Monedero Digital y Pre-órdenes para Sodas Escolares en Costa Rica", "description": "Monedero Digital y Pre-órdenes para Sodas Escolares en Costa Rica",
+61 -15
View File
@@ -1,6 +1,28 @@
// RecreoPay PWA Service Worker (Auto-purge & Unregister para evitar caché vieja en móviles) // RecreoPay PWA Service Worker v7.0 - Alta Estabilidad
const CACHE_NAME = 'recreopay-v7.0';
const STATIC_ASSETS = [
'/',
'/index.html',
'/pos.html',
'/carnet.html',
'/manifest.json',
'/css/styles.css',
'/js/app.js',
'/js/pos.js',
'/js/sounds.js',
'/icons/icon-192.png',
'/icons/icon-512.png'
];
self.addEventListener('install', (event) => { self.addEventListener('install', (event) => {
self.skipWaiting(); self.skipWaiting();
event.waitUntil(
caches.open(CACHE_NAME).then((cache) => {
return cache.addAll(STATIC_ASSETS).catch((err) => {
console.warn('[SW] Cache prefetch warn:', err);
});
})
);
}); });
self.addEventListener('activate', (event) => { self.addEventListener('activate', (event) => {
@@ -8,24 +30,48 @@ self.addEventListener('activate', (event) => {
caches.keys().then((keys) => { caches.keys().then((keys) => {
return Promise.all( return Promise.all(
keys.map((key) => { keys.map((key) => {
console.log('[SW] Purgando caché obsoleta:', key); if (key !== CACHE_NAME) {
return caches.delete(key); console.log('[SW] Purgando versión anterior:', key);
return caches.delete(key);
}
}) })
); );
}).then(() => self.registration.unregister()) }).then(() => self.clients.claim())
.then(() => self.clients.claim()) );
.then(() => self.clients.matchAll()) });
.then((clients) => {
clients.forEach((client) => { // Network-First con fallback a caché para navegación y recursos estáticos
if (client.url && 'navigate' in client) { self.addEventListener('fetch', (event) => {
client.navigate(client.url); const url = new URL(event.request.url);
// APIs y Server-Sent Events (SSE): Directo a red sin caché
if (url.pathname.startsWith('/api/') || url.pathname.startsWith('/events')) {
return;
}
// Peticiones no-GET: directo a red
if (event.request.method !== 'GET') {
return;
}
event.respondWith(
fetch(event.request)
.then((networkResponse) => {
if (networkResponse && networkResponse.status === 200) {
const responseClone = networkResponse.clone();
caches.open(CACHE_NAME).then((cache) => {
cache.put(event.request, responseClone);
});
}
return networkResponse;
})
.catch(() => {
return caches.match(event.request).then((cachedResponse) => {
if (cachedResponse) return cachedResponse;
if (event.request.mode === 'navigate') {
return caches.match('/index.html');
} }
}); });
}) })
); );
}); });
// Pass-through directo a la red (sin caché en desarrollo y pruebas)
self.addEventListener('fetch', (event) => {
// Sin intercepción: el navegador siempre pide al servidor
});