@@ -3,6 +3,7 @@ import { FaShare } from "react-icons/fa6";
3
3
import { QRCodeCanvas } from "qrcode.react" ;
4
4
import { saveAs } from "file-saver" ;
5
5
import { useRouter } from "next/router" ;
6
+ import { toPng } from "html-to-image" ;
6
7
7
8
import FallbackImage from "@components/FallbackImage" ;
8
9
import UserSocial from "./UserSocials" ;
@@ -14,6 +15,19 @@ import Modal from "@components/Modal";
14
15
import ClipboardCopy from "@components/ClipboardCopy" ;
15
16
import { socials } from "@config/socials" ;
16
17
import Markdown from "@components/Markdown" ;
18
+ import { renderToString } from "react-dom/server" ;
19
+ import QRcodeWallpaper from "./QRcodeWallpaper" ;
20
+
21
+ const renderQRCodeWallpaperToString = ( BASE_URL , data ) => {
22
+ const qrCodeElement = React . createElement ( QRcodeWallpaper , {
23
+ BASE_URL : BASE_URL ,
24
+ data : data ,
25
+ } ) ;
26
+
27
+ const qrCodeString = renderToString ( qrCodeElement ) ;
28
+
29
+ return qrCodeString ;
30
+ } ;
17
31
18
32
function UserProfile ( { BASE_URL , data } ) {
19
33
const [ qrShow , setQrShow ] = useState ( false ) ;
@@ -30,6 +44,26 @@ function UserProfile({ BASE_URL, data }) {
30
44
saveAs ( blob , `biodrop-${ data . username } .png` ) ,
31
45
) ;
32
46
47
+ const downloadWallpaper = async ( ) => {
48
+ try {
49
+ const qrCodeString = renderQRCodeWallpaperToString ( BASE_URL , data ) ;
50
+
51
+ const container = document . createElement ( "div" ) ;
52
+ container . innerHTML = qrCodeString ;
53
+
54
+ const dataUrl = await toPng ( container , {
55
+ cacheBust : false ,
56
+ backgroundColor : "#122640" ,
57
+ width : 1080 ,
58
+ height : 1920 ,
59
+ } ) ;
60
+
61
+ saveAs ( dataUrl , `Biodrop-Wallpaper-${ data . username } .png` ) ;
62
+ } catch ( e ) {
63
+ console . error ( e ) ;
64
+ }
65
+ } ;
66
+
33
67
return (
34
68
< >
35
69
< div className = "flex justify-center items-center flex-col md:flex-row gap-x-6" >
@@ -128,6 +162,13 @@ function UserProfile({ BASE_URL, data }) {
128
162
</ Button >
129
163
) }
130
164
</ div >
165
+ < div className = "w-full px-2 mx-auto flex justify-center mb-4" >
166
+ { qrShow && (
167
+ < Button primary = { true } onClick = { downloadWallpaper } >
168
+ Export as Wallpaper
169
+ </ Button >
170
+ ) }
171
+ </ div >
131
172
</ div >
132
173
{ qrShow && (
133
174
< >
0 commit comments