Skip to content

Commit f6736f0

Browse files
committed
feat: add download links for mobile view
1 parent c09ddb9 commit f6736f0

File tree

2 files changed

+79
-27
lines changed

2 files changed

+79
-27
lines changed

src/components/Template/template.jsx

Lines changed: 74 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useState } from "react";
22
import Image from "next/image";
3-
import { BlobProvider } from "@react-pdf/renderer";
3+
import { PDFDownloadLink, PDFViewer } from "@react-pdf/renderer";
44

55
import ProposalPDF from "../proposalPDF";
66

@@ -14,35 +14,45 @@ export default function Template({ isSubmitted, ...props }) {
1414
</div>
1515
);
1616
}
17-
console.log({ styles });
17+
1818
return (
1919
<div className="w-full h-full p-4 flex flex-col gap-5 xl:flex-row bg-teal-950 rounded-lg shadow-sm">
20-
<BlobProvider
21-
document={<ProposalPDF template={styles} {...props} />}
20+
<PDFViewer
21+
className="w-full h-full border-0 hidden md:block"
22+
height={"100%"}
2223
>
23-
{({ url, loading, error }) => {
24-
if (loading) return <p>Loading PDF...</p>;
25-
if (error) return <p>Error generating preview</p>;
26-
return (
27-
<iframe
28-
src={url}
29-
className="w-full h-full border-0 hidden md:block"
30-
title="PDF Preview"
31-
/>
32-
);
33-
}}
34-
</BlobProvider>
24+
<ProposalPDF template={styles} {...props} />
25+
</PDFViewer>
3526
<div className="xl:hidden text-center">Choose Templates</div>
36-
<div className="flex flex-row justify-between xl:gap-5 xl:ml-4 xl:flex-col">
27+
<div className="flex flex-col justify-between xl:gap-5 xl:ml-4 xl:flex-col">
3728
<button
3829
onClick={() => {
3930
setStyles("elegant");
4031
}}
4132
className="cursor-pointer"
4233
>
43-
<div className="input border-teal-600 bg-teal-600 hover:bg-teal-700 text-white disabled:bg-teal-600 disabled:text-white xl:hidden">
44-
Elegant
45-
</div>
34+
<PDFDownloadLink
35+
document={<ProposalPDF template={styles} {...props} />}
36+
>
37+
<div className="input flex gap-2 justify-center items-center border-teal-600 bg-teal-600 hover:bg-teal-700 text-white disabled:bg-teal-600 disabled:text-white xl:hidden">
38+
<div>Elegant</div>
39+
<svg
40+
xmlns="http://www.w3.org/2000/svg"
41+
fill="none"
42+
viewBox="0 0 24 24"
43+
strokeWidth={1.5}
44+
stroke="currentColor"
45+
className="size-4"
46+
>
47+
<path
48+
strokeLinecap="round"
49+
strokeLinejoin="round"
50+
d="M3 16.5v2.25A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75V16.5M16.5 12 12 16.5m0 0L7.5 12m4.5 4.5V3"
51+
/>
52+
</svg>
53+
</div>
54+
</PDFDownloadLink>
55+
4656
<Image
4757
src={"/elegant.png"}
4858
alt="elegant"
@@ -57,9 +67,28 @@ export default function Template({ isSubmitted, ...props }) {
5767
}}
5868
className="cursor-pointer"
5969
>
60-
<div className="input border-teal-600 bg-teal-600 hover:bg-teal-700 text-white disabled:bg-teal-600 disabled:text-white xl:hidden">
61-
Modern
62-
</div>
70+
<PDFDownloadLink
71+
document={<ProposalPDF template={styles} {...props} />}
72+
>
73+
<div className="input flex gap-2 justify-center items-center border-teal-600 bg-teal-600 hover:bg-teal-700 text-white disabled:bg-teal-600 disabled:text-white xl:hidden">
74+
<div>Modern</div>
75+
<svg
76+
xmlns="http://www.w3.org/2000/svg"
77+
fill="none"
78+
viewBox="0 0 24 24"
79+
strokeWidth={1.5}
80+
stroke="currentColor"
81+
className="size-4"
82+
>
83+
<path
84+
strokeLinecap="round"
85+
strokeLinejoin="round"
86+
d="M3 16.5v2.25A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75V16.5M16.5 12 12 16.5m0 0L7.5 12m4.5 4.5V3"
87+
/>
88+
</svg>
89+
</div>
90+
</PDFDownloadLink>
91+
6392
<Image
6493
src={"/modern.png"}
6594
alt="modern"
@@ -74,9 +103,28 @@ export default function Template({ isSubmitted, ...props }) {
74103
}}
75104
className="cursor-pointer"
76105
>
77-
<div className="input border-teal-600 bg-teal-600 hover:bg-teal-700 text-white disabled:bg-teal-600 disabled:text-white xl:hidden">
78-
Abstract
79-
</div>
106+
<PDFDownloadLink
107+
document={<ProposalPDF template={styles} {...props} />}
108+
>
109+
<div className="input flex gap-2 justify-center items-center border-teal-600 bg-teal-600 hover:bg-teal-700 text-white disabled:bg-teal-600 disabled:text-white xl:hidden">
110+
<div>Abstract</div>
111+
<svg
112+
xmlns="http://www.w3.org/2000/svg"
113+
fill="none"
114+
viewBox="0 0 24 24"
115+
strokeWidth={1.5}
116+
stroke="currentColor"
117+
className="size-4"
118+
>
119+
<path
120+
strokeLinecap="round"
121+
strokeLinejoin="round"
122+
d="M3 16.5v2.25A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75V16.5M16.5 12 12 16.5m0 0L7.5 12m4.5 4.5V3"
123+
/>
124+
</svg>
125+
</div>
126+
</PDFDownloadLink>
127+
80128
<Image
81129
src={"/abstract.png"}
82130
alt="abstract"

src/components/proposalPDF.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ const ProposalPDF = ({ template, ...props }) => {
5656
const styles = templateMap[template];
5757

5858
return (
59-
<Document pageMode="fullScreen" title={projectTitle ?? "Proposal"}>
59+
<Document
60+
pageMode="fullScreen"
61+
title={`${projectTitle}_${template}` ?? "Proposal"}
62+
subject={projectTitle}
63+
>
6064
<Page wrap size="A4" style={styles.page}>
6165
{/* Header */}
6266
<View style={styles.headerSection}>

0 commit comments

Comments
 (0)