update frontend

This commit is contained in:
Your Name 2025-12-21 19:32:19 -05:00
parent eb018a0bee
commit 8508f0f98f
2 changed files with 18 additions and 24 deletions

View File

@ -18,7 +18,7 @@ import "./styles/maps.css"; // ✅ pour la barre de recherche (taille + couleurs
import { AuthProvider } from "./auth/AuthContext.jsx";
// Import pour PWA install prompt (si tu as créé pwaInstall.js)
// Import pour PWA install prompt
import { promptInstall } from './pwaInstall';
ReactDOM.createRoot(document.getElementById("root")).render(
@ -42,7 +42,7 @@ if ('serviceWorker' in navigator) {
});
}
// Force le prompt dinstallation après 5 secondes (optionnel)
// Force le prompt dinstallation après 5 secondes (une seule fois)
setTimeout(() => {
promptInstall();
}, 5000);

View File

@ -1,40 +1,34 @@
// src/pwaInstall.js
let deferredPrompt = null;
let promptShown = false; // Flag pour n'afficher qu'une fois
window.addEventListener('beforeinstallprompt', (e) => {
e.preventDefault();
deferredPrompt = e;
console.log('PWA install prompt ready');
// Affiche le prompt automatiquement après 5 secondes (une seule fois)
setTimeout(() => {
if (!promptShown && deferredPrompt) {
deferredPrompt.prompt();
promptShown = true;
deferredPrompt.userChoice.then((choice) => {
console.log('Install outcome:', choice.outcome);
deferredPrompt = null;
});
}
}, 5000); // 5000 ms = 5 secondes
});
export function promptInstall() {
if (deferredPrompt) {
if (deferredPrompt && !promptShown) {
deferredPrompt.prompt();
promptShown = true;
deferredPrompt.userChoice.then((choice) => {
console.log('Install outcome:', choice.outcome);
deferredPrompt = null;
});
} else {
console.log('No install prompt available');
console.log('No install prompt available or already shown');
}
}
// Exporte la fonction pour ajouter le bouton dans TopBar
export function addPwaInstallButton(container) {
const btn = document.createElement('button');
btn.innerHTML = '<i class="fa-solid fa-download"></i> Installer';
btn.style.marginLeft = '8px';
btn.style.padding = '5px 10px';
btn.style.fontSize = '12px';
btn.style.background = '#0ea5e9';
btn.style.color = 'white';
btn.style.border = 'none';
btn.style.borderRadius = '999px';
btn.style.cursor = 'pointer';
btn.style.display = 'flex';
btn.style.alignItems = 'center';
btn.style.gap = '6px';
btn.style.boxShadow = '0 2px 8px rgba(0,0,0,0.3)';
btn.onclick = promptInstall;
container.appendChild(btn);
}