Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ Formato basado en [Keep a Changelog](https://keepachangelog.com/es-ES/1.1.0/).
o con red lenta, arranca desde caché (#5).

### Corregido
- El banner de instalación ya no tapa el último botón en pantallas largas
(el contenido reserva su altura mientras se ve) y se puede cerrar con ✕;
el cierre se recuerda en este navegador (#34).
- Correcciones menores (#22): la ronda 3 ya no propone "La vuestra (con
todo)" cuando una receta tiene exactamente esos ingredientes; los nombres
vacíos pasan a "Jugador N" y los guardados se recortan a `maxPlayers`
Expand Down
8 changes: 6 additions & 2 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,17 @@ button { font-family: inherit; }
.error-box { color: #EE5C3F; background: #241A15; border: 1px solid rgba(225,71,43,0.4); border-radius: 12px; padding: 14px; font-size: 13px; text-align: center; }

.install-banner {
position: fixed; left: 16px; right: 16px; bottom: 16px; max-width: 380px; margin: 0 auto;
position: fixed; left: 16px; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); max-width: 380px; margin: 0 auto;
background: #241A15; border: 1px solid rgba(232,163,61,0.35); border-radius: 14px; padding: 12px 14px;
display: flex; align-items: center; justify-content: space-between; gap: 10px; z-index: 50;
box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
.install-banner span { font-size: 13px; }
.install-banner[hidden] { display: none; }
.install-banner > span { font-size: 13px; flex: 1; }
.install-banner button { background: #E8A33D; color: #1B1410; border: none; border-radius: 8px; padding: 8px 12px; font-weight: 600; font-size: 13px; cursor: pointer; white-space: nowrap; }
.install-banner .install-close { background: transparent; color: #F7EDDD; border: 1px solid rgba(247,237,221,0.25); min-width: 36px; min-height: 36px; padding: 0; }
/* Mientras el banner (fixed) está visible, reservar su altura para que no tape el final. */
body.has-install-banner { padding-bottom: calc(var(--install-banner-h, 64px) + 32px + env(safe-area-inset-bottom)); }

/* Admin-specific */
.admin-wrap { max-width: 640px; align-items: stretch; }
Expand Down
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
<body>
<main id="app"></main>
<div id="announcer" class="sr-only" aria-live="polite" aria-atomic="true"></div>
<aside id="installBanner" class="install-banner" style="display:none;" aria-label="Instalar la app">
<aside id="installBanner" class="install-banner" hidden aria-label="Instalar la app">
<span>Instala Dinner Match en tu pantalla de inicio</span>
<button id="installBtn">Instalar</button>
<button id="installClose" class="install-close" aria-label="Cerrar el aviso de instalación"><span aria-hidden="true">✕</span></button>
</aside>
<script type="module" src="./js/app.js"></script>
</body>
Expand Down
44 changes: 37 additions & 7 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,21 +536,51 @@ document.getElementById("app").addEventListener("input", (e) => {
});

// ---- PWA install ----
// El banner es position: fixed. Mientras se ve, el body reserva abajo su
// altura real (--install-banner-h, medida con ResizeObserver porque en móvil
// el texto puede ocupar dos líneas) para que no tape el último botón.
const INSTALL_DISMISSED_KEY = "dinnerMatchInstallDismissed";
const installBanner = document.getElementById("installBanner");
let deferredPrompt;
const bannerObserver = "ResizeObserver" in window
? new ResizeObserver(() => document.body.style.setProperty("--install-banner-h", `${installBanner.offsetHeight}px`))
: null;

function installDismissed() {
try { return localStorage.getItem(INSTALL_DISMISSED_KEY) === "1"; } catch { return false; }
}
function setInstallBanner(visible) {
if (!installBanner) return;
installBanner.hidden = !visible;
document.body.classList.toggle("has-install-banner", visible);
if (visible) {
document.body.style.setProperty("--install-banner-h", `${installBanner.offsetHeight}px`);
bannerObserver?.observe(installBanner);
} else {
bannerObserver?.disconnect();
}
}
// Al cerrar el banner con su botón, el foco no debe caer en <body>.
function focusAfterBanner() {
if (installBanner?.contains(document.activeElement)) document.querySelector("#app [data-autofocus]")?.focus();
}

window.addEventListener("beforeinstallprompt", (e) => {
e.preventDefault();
deferredPrompt = e;
const banner = document.getElementById("installBanner");
if (banner) banner.style.display = "flex";
if (!installDismissed()) setInstallBanner(true);
});
document.getElementById("installBtn")?.addEventListener("click", async () => {
document.getElementById("installBanner").style.display = "none";
document.getElementById("installBtn")?.addEventListener("click", () => {
focusAfterBanner();
setInstallBanner(false);
if (deferredPrompt) { deferredPrompt.prompt(); deferredPrompt = null; }
});
window.addEventListener("appinstalled", () => {
const banner = document.getElementById("installBanner");
if (banner) banner.style.display = "none";
document.getElementById("installClose")?.addEventListener("click", () => {
focusAfterBanner();
setInstallBanner(false);
try { localStorage.setItem(INSTALL_DISMISSED_KEY, "1"); } catch { /* sin almacenamiento: volverá a salir */ }
});
window.addEventListener("appinstalled", () => setInstallBanner(false));
if ("serviceWorker" in navigator && (location.protocol === "https:" || location.hostname === "localhost")) {
window.addEventListener("load", () => {
navigator.serviceWorker.register("./service-worker.js").catch(() => {});
Expand Down
Loading