Skip to content

Commit 49cbac8

Browse files
Merge branch 'staging' into starredPapers
2 parents 7fe47cf + e070766 commit 49cbac8

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

public/papers_logo.png

82.7 KB
Loading

src/components/screens/Info.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import man from "@/assets/man.svg" assert { type: "image/svg" };
1111
import man1 from "@/assets/man1.svg" assert { type: "image/svg" };
1212
import Link from "next/link";
1313
import { Button } from "@/components/ui/button";
14+
import PWAInstallButton from "../ui/PWAInstallButton";
15+
1416

1517
function Info() {
1618
return (
@@ -74,6 +76,27 @@ function Info() {
7476
/>
7577
</div>
7678
</section>
79+
</section>
80+
81+
{/* Create Request Section */}
82+
<section className="flex flex-col items-center justify-center gap-4 px-6 py-12 text-center">
83+
<h2 className="font-vipnabd text-2xl font-semibold text-black dark:text-white md:text-3xl">
84+
Can’t Find a Specific Paper?
85+
</h2>
86+
<Link href="/request">
87+
<Button
88+
variant="outline"
89+
className="group border-[1.5px] border-[#4A55FF] bg-transparent px-6 py-3 text-sm font-medium text-[#4A55FF] transition-all duration-200 hover:bg-[#4A55FF] hover:text-white dark:border-[#9EA8FF] dark:text-[#9EA8FF] dark:hover:bg-[#9EA8FF] dark:hover:text-black"
90+
>
91+
Create Request
92+
<ArrowUpRight className="ml-2 h-4 w-4 transition-transform group-hover:translate-x-0.5 group-hover:-translate-y-0.5" />
93+
</Button>
94+
</Link>
95+
</section>
96+
<div className="flex justify-center py-4 z-50">
97+
<PWAInstallButton />
98+
</div>
99+
</>
77100
);
78101
}
79102

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
"use client";
3+
4+
import { useEffect, useState } from "react";
5+
import Image from "next/image";
6+
import { Download } from "lucide-react";
7+
8+
9+
interface BeforeInstallPromptEvent extends Event {
10+
prompt: () => Promise<void>;
11+
userChoice: Promise<{
12+
outcome: "accepted" | "dismissed";
13+
platform: string;
14+
}>;
15+
}
16+
17+
const PWAInstallButton = () => {
18+
const [deferredPrompt, setDeferredPrompt] = useState<BeforeInstallPromptEvent | null>(null);
19+
const [showInstall, setShowInstall] = useState(false);
20+
21+
useEffect(() => {
22+
const handler = (e: Event) => {
23+
e.preventDefault();
24+
setDeferredPrompt(e as BeforeInstallPromptEvent);
25+
setShowInstall(true);
26+
};
27+
28+
window.addEventListener("beforeinstallprompt", handler);
29+
return () => window.removeEventListener("beforeinstallprompt", handler);
30+
}, []);
31+
32+
const handleInstall = async () => {
33+
if (!deferredPrompt) return;
34+
35+
deferredPrompt.prompt();
36+
const { outcome } = await deferredPrompt.userChoice;
37+
if (outcome === "accepted") {
38+
setShowInstall(false);
39+
setDeferredPrompt(null);
40+
}
41+
};
42+
43+
if (!showInstall) return null;
44+
45+
return (
46+
<div className="md:hidden flex items-center justify-between rounded-full bg-[#2b2343] px-4 py-2 shadow-md text-white w-fit">
47+
<div className="flex items-center gap-3">
48+
<Image src="/papers_logo.png" alt="Papers App" width={32} height={32} />
49+
<span className="font-semibold text-lg">Papers App</span>
50+
</div>
51+
<button
52+
onClick={handleInstall}
53+
className="ml-6 flex items-center gap-2 rounded-full border border-gray-500 bg-[#1e1e24] px-4 py-1 text-sm font-semibold transition hover:bg-[#2b2b30]"
54+
>
55+
<Download className="h-4 w-4" />
56+
Install
57+
</button>
58+
</div>
59+
);
60+
};
61+
62+
export default PWAInstallButton;

0 commit comments

Comments
 (0)