Skip to content

Commit

Permalink
add home added
Browse files Browse the repository at this point in the history
  • Loading branch information
enkhbold470 committed May 4, 2024
1 parent 816eb55 commit 8d9be33
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Contact from "@/components/Contact";
import PortfolioCart from "@/components/Projects/PortfolioCart";
import Socials from "@/components/Socials";
import DarkToggle from "@/components/DarkToggle";
import AddToHomeScreenButton from "@/components/AddHome";

let prevScrollPos: number = typeof window !== "undefined" ? window.scrollY : 0;

Expand All @@ -36,7 +37,7 @@ export default function Home() {
return (
<>
{/* <ResponsiveDebug /> */}

{/* <AddToHomeScreenButton /> */}
<Navbar />
{/* <DarkToggle /> */}
<Hero />
Expand Down
30 changes: 30 additions & 0 deletions src/components/AddHome.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use client";
import { useEffect, useState } from "react";

export default function AddToHomeScreenButton() {
const [installPrompt, setInstallPrompt] = useState<any>();

useEffect(() => {
const installHandler = (event: Event) => {
event.preventDefault();
setInstallPrompt(event);
};

window.addEventListener("beforeinstallprompt", installHandler);

return () =>
window.removeEventListener("beforeinstallprompt", installHandler);
});

const onClick = async () => {
if (!installPrompt) return;
await installPrompt.prompt();
setInstallPrompt(false);
};

return (
<button onClick={onClick} disabled={!installPrompt}>
Install this Demo!
</button>
);
}

0 comments on commit 8d9be33

Please sign in to comment.