diff --git a/src/components/layout/footer.js b/src/components/layout/footer.js index 9041d3e..ee500e2 100644 --- a/src/components/layout/footer.js +++ b/src/components/layout/footer.js @@ -1,16 +1,27 @@ -import React, { useEffect, useRef } from 'react'; -import { Space, Button, Layout } from 'antd'; +import React, { useEffect, useState } from 'react'; +import { Space, Button, Layout, Tooltip } from 'antd'; import { HeartFilled, CoffeeOutlined, BugOutlined, CloudDownloadOutlined } from '@ant-design/icons'; export function Footer() { const { Footer } = Layout; - let install = useRef(null); + const [supportsPWA, setSupportsPWA] = useState(false); + const [promptInstall, setPromptInstall] = useState(null); + + const install = evt => { + evt.preventDefault(); + if(promptInstall) promptInstall.prompt(); + promptInstall.userChoice.then((choiceResult) => { + if (choiceResult.outcome === 'accepted') setSupportsPWA(false); + }); + }; useEffect(() => { - window.addEventListener('beforeinstallprompt', (e) => { + const handler = e => { e.preventDefault(); - install.current = e; - }) + setSupportsPWA(true); + setPromptInstall(e); + }; + window.addEventListener("beforeinstallprompt", handler); }, []); return ( @@ -20,8 +31,13 @@ export function Footer() {
This page is not affiliated or endorsed by Korg