@@ -11,7 +11,7 @@ import {
1111import { useRef , useState } from "react" ;
1212import { Button } from "@/components/ui/button" ;
1313import type { QuoteFormData } from "@/model/quote.model" ;
14- import { ArrowLeftIcon , CircleArrowDown , LoaderCircle , Save , Share } from "lucide-react" ;
14+ import { ArrowLeftIcon , CircleArrowDown , Copy , LoaderCircle , Save , Share } from "lucide-react" ;
1515import useBackground , { type Pri_set , type TextureKey } from "@/hook/use-background.hook" ;
1616import { sanitizeHTML } from "@/helper/sanitize-html" ;
1717import { cn } from "@/lib/utils" ;
@@ -29,6 +29,7 @@ export function ShareBackground(props: Props) {
2929 const { buildStyle } = useBackground ( )
3030 const noteRef = useRef < HTMLDivElement > ( null )
3131 const [ downloading , setDownloading ] = useState ( false )
32+ const [ copying , setCopying ] = useState ( false )
3233 const [ dimensions , setDimensions ] = useState ( { width : 320 , height : 240 } )
3334 const cardStyle = buildStyle ( quoteFormData . texture ! , quoteFormData . pri_set ! )
3435
@@ -180,46 +181,62 @@ export function ShareBackground(props: Props) {
180181 { /* Action */ }
181182
182183 < div className = "flex items-center gap-4 " >
183-
184184 < div className = "flex flex-col gap-4" >
185185 < Button
186186 className = ""
187187 variant = { "outline" }
188- onClick = { async ( e ) => {
189- setDownloading ( true )
188+ onClick = { async ( e ) => {
189+ setDownloading ( true )
190190 e . preventDefault ( )
191- await exportAsImage ( )
192- setTimeout ( ( ) => {
193- setDownloading ( false )
194- } , 500 ) ;
195-
191+ await exportAsImage ( )
192+ setDownloading ( false )
196193 } }
197194 aria-label = "Download quote"
198195 size = { "lg" }
199196 >
200197 { downloading ? < LoaderCircle className = "animate-spin" /> : < CircleArrowDown /> }
201198 </ Button >
202- < p className = "text-xs" >
199+ < p className = "text-xs text-center " >
203200 { downloading ? "Downloading" : "Download" }
204201 </ p >
205202 </ div >
206203
207204 < div className = "flex flex-col gap-4" >
208-
209205 < Button
210206 variant = "outline"
211207 size = "lg"
212208 onClick = { async ( e ) => {
213209 e . preventDefault ( )
210+ setCopying ( true )
211+ const dataUrl = await exportAsImage ( )
212+ if ( ! dataUrl ) return
213+ const res = await fetch ( dataUrl )
214+ const blob = await res . blob ( )
215+ await navigator . clipboard . write ( [
216+ new ClipboardItem ( { "image/png" : blob } )
217+ ] )
218+ setCopying ( false )
219+ } }
220+ >
221+ { copying ? < LoaderCircle className = "animate-spin" /> : < Copy /> }
222+ </ Button >
223+ < p className = "text-xs text-center" > { copying ? "Copying" : "Copy" } </ p >
224+ </ div >
214225
226+ < div className = "flex flex-col gap-4" >
227+ < Button
228+ variant = "outline"
229+ size = "lg"
230+ onClick = { async ( e ) => {
231+ e . preventDefault ( )
215232 const dataUrl = await exportAsImage ( )
216233 if ( ! dataUrl ) return
217234 exportAndShareWhatsApp ( dataUrl )
218235 } }
219236 >
220237 < Share />
221238 </ Button >
222- < p className = "text-xs" > WhatsApp</ p >
239+ < p className = "text-xs text-center " > WhatsApp</ p >
223240 </ div >
224241
225242 </ div >
0 commit comments