generated from sanity-io/template-nextjs-personal-website
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor text content in GlobeView component and add PwaInstall compo…
…nent
- Loading branch information
1 parent
17ecec0
commit 3f02a55
Showing
4 changed files
with
99 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// @ts-nocheck | ||
"use client"; | ||
import { useEffect, useState } from "react"; | ||
|
||
import { Button } from "@/components/ui/button"; | ||
const PwaInstall = () => { | ||
const [deferredPrompt, setDeferredPrompt] = useState(null); | ||
|
||
useEffect(() => { | ||
const handleBeforeInstallPrompt = (event) => { | ||
// Prevent the default installation prompt | ||
event.preventDefault(); | ||
// Store the event for later use | ||
setDeferredPrompt(event); | ||
}; | ||
|
||
// Listen for the beforeinstallprompt event | ||
window.addEventListener("beforeinstallprompt", handleBeforeInstallPrompt); | ||
// warn the user if the app is already installed | ||
|
||
// Cleanup: remove the event listener when the component is unmounted | ||
return () => { | ||
window.removeEventListener( | ||
"beforeinstallprompt", | ||
handleBeforeInstallPrompt, | ||
); | ||
}; | ||
}, []); | ||
const handleEmailOpen = (event) => { | ||
event.preventDefault(); | ||
window.location.href = "mailto:[email protected]"; | ||
|
||
}; | ||
const handleInstallClick = (event) => { | ||
event.preventDefault(); | ||
|
||
// Display confirmation alert to install from the user | ||
// if ( | ||
// window.confirm( | ||
// "The app is still in development stage. Some devices might face flickering issues. Please use the website for better experience. Click OK to continue." | ||
// ) | ||
// ) { | ||
if (deferredPrompt) { | ||
// Show the installation prompt | ||
deferredPrompt.prompt(); | ||
|
||
// Wait for the user to respond to the prompt | ||
deferredPrompt.userChoice.then((choiceResult) => { | ||
if (choiceResult.outcome === "accepted") { | ||
console.log("User accepted the installation"); | ||
} else { | ||
console.log("User dismissed the installation"); | ||
} | ||
|
||
// Reset the deferredPrompt variable | ||
setDeferredPrompt(null); | ||
}); | ||
} | ||
// } | ||
}; | ||
|
||
return ( | ||
<div> | ||
<Button | ||
onClick={handleInstallClick} | ||
variant={'default'} | ||
size={'lg'} | ||
style={{ display: deferredPrompt ? 'block' : 'none' }} | ||
className=" md:px-4 md:py-2 px-2 py-1 md:mt-24 mt-8 z-30 w-fit mx-auto " | ||
> | ||
Get Our App | ||
</Button> | ||
<Button | ||
onClick={handleEmailOpen} | ||
variant={'default'} | ||
size={'lg'} | ||
style={{ display: deferredPrompt ? 'none' : 'block' }} | ||
className=" md:px-4 md:py-2 px-2 py-1 md:mt-24 mt-8 z-30 w-fit mx-auto " | ||
> | ||
Contact Us | ||
</Button> | ||
</div> | ||
) | ||
}; | ||
|
||
export default PwaInstall; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters