import * as S from 'components/PopupInstallPwa/styles' ; import { SetStateAction , useEffect , useState } from 'react' ; export const PopupInstallPwa = ( ) => { const [ isActive , setIsActive ] = useState ( false ) ; const [ deferredPrompt , setDeferredPrompt ] = useState < SetStateAction < any > > ( ) ; useEffect ( ( ) => { window . addEventListener ( 'beforeinstallprompt' , e => { e . preventDefault ( ) ; setDeferredPrompt ( e ) ; setIsActive ( true ) ; } ) ; } , [ ] ) ; const closePopup = ( ) => setIsActive ( false ) ; const handleInstallPwa = ( ) => { closePopup ( ) ; deferredPrompt . prompt ( ) ; deferredPrompt . userChoice . then ( ( choiceResult ) => { if ( choiceResult . outcome === 'accepted' ) { console . log ( 'Você aceitou a instalação do App' ) ; } else { console . log ( 'Infelizmente você não aceitou a instalação do App, pressione "ctrl + F5" e tente novamente' ) ; } } ) ; } ; return ( < > { isActive && ( < S . ContainerPopup > < div > < S . ContainerImg > < span onClick = { ( ) => closePopup ( ) } > < S . Close /> < /span> < img src = "/icons/icon-72x72.png" width = "50" height = "50" alt = "Pizzaria Toffanetto" / > < img src = "/img/logo-popup-pwa.png" alt = "Pizzaria Toffanetto" width = "240" height = "50" / > < /S.ContainerImg> < p > Adicione nosso App à tela inicial ! < /p> < button onClick = { ( ) => handleInstallPwa ( ) } > Adicionar Atalho < /button> < /div> < /S.ContainerPopup>)} < />); } ;