From 1444e70d6187f6a8596e76cce9dbdedb6fe33b8d Mon Sep 17 00:00:00 2001 From: Oscar Date: Sat, 20 Feb 2021 12:58:43 +0100 Subject: [PATCH] [ADD] Install button on the footer --- src/components/layout/footer.js | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) 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

- { install.current ? : ""} - + { supportsPWA ? + + + : ""} + + +