11import { Check , Copy , Link2 } from "lucide-react" ;
2- import { QRCodeSVG } from "qrcode.react" ;
2+ import { QRCodeCanvas } from "qrcode.react" ;
33import * as React from "react" ;
44import { toast } from "sonner" ;
55
66import { mintInvite } from "@/shared/api/invites" ;
7+ import { invokeTauri } from "@/shared/api/tauri" ;
78import { Button } from "@/shared/ui/button" ;
89import {
910 DropdownMenu ,
@@ -15,6 +16,11 @@ import {
1516 DropdownMenuTrigger ,
1617} from "@/shared/ui/dropdown-menu" ;
1718import { writeTextToClipboard } from "@/shared/lib/clipboard" ;
19+ import {
20+ MediaContextMenu ,
21+ type MediaContextMenuPosition ,
22+ useDismissMediaContextMenu ,
23+ } from "@/shared/ui/markdown/MediaContextMenu" ;
1824
1925const TTL_OPTIONS : { label : string ; value : number } [ ] = [
2026 { label : "1 day" , value : 24 * 60 * 60 } ,
@@ -48,6 +54,12 @@ export function InviteLinkSection() {
4854 expiresAt : number ;
4955 } | null > ( null ) ;
5056 const [ copied , setCopied ] = React . useState ( false ) ;
57+ const [ qrMenu , setQrMenu ] = React . useState < MediaContextMenuPosition | null > (
58+ null ,
59+ ) ;
60+ const qrRef = React . useRef < HTMLCanvasElement | null > ( null ) ;
61+ const closeQrMenu = React . useCallback ( ( ) => setQrMenu ( null ) , [ ] ) ;
62+ useDismissMediaContextMenu ( Boolean ( qrMenu ) , closeQrMenu ) ;
5163
5264 const ttlLabel =
5365 TTL_OPTIONS . find ( ( option ) => option . value === ttlSecs ) ?. label ?? "3 days" ;
@@ -82,6 +94,20 @@ export function InviteLinkSection() {
8294 }
8395 }
8496
97+ async function handleDownloadQr ( ) {
98+ closeQrMenu ( ) ;
99+ const dataUrl = qrRef . current ?. toDataURL ( "image/png" ) ;
100+ if ( ! dataUrl ) return ;
101+ try {
102+ await invokeTauri ( "save_png_data_url" , {
103+ dataUrl,
104+ filename : "buzz-community-invite.png" ,
105+ } ) ;
106+ } catch ( error ) {
107+ toast . error ( error instanceof Error ? error . message : "Download failed" ) ;
108+ }
109+ }
110+
85111 return (
86112 < div className = "space-y-1.5" >
87113 < span className = "text-sm font-medium" > Invite link</ span >
@@ -160,10 +186,17 @@ export function InviteLinkSection() {
160186 { invite ? (
161187 < div className = "flex flex-col gap-3 rounded-md border border-border/70 bg-background/70 p-3 sm:flex-row sm:items-center" >
162188 < div className = "shrink-0 self-center rounded-md bg-white p-2 text-black" >
163- < QRCodeSVG
189+ < QRCodeCanvas
190+ ref = { qrRef }
164191 aria-label = "Invite QR code"
165192 data-testid = "invite-link-qr-code"
166193 level = "M"
194+ onContextMenuCapture = { ( event ) => {
195+ event . preventDefault ( ) ;
196+ event . stopPropagation ( ) ;
197+ event . nativeEvent . stopImmediatePropagation ( ) ;
198+ setQrMenu ( { x : event . clientX , y : event . clientY } ) ;
199+ } }
167200 size = { 128 }
168201 value = { invite . url }
169202 />
@@ -185,6 +218,18 @@ export function InviteLinkSection() {
185218 until it expires.
186219 </ p >
187220 ) }
221+ { qrMenu ? (
222+ < MediaContextMenu
223+ dataAttributes = { [ "data-invite-qr-context-menu" ] }
224+ items = { [
225+ {
226+ label : "Download image" ,
227+ onSelect : ( ) => void handleDownloadQr ( ) ,
228+ } ,
229+ ] }
230+ position = { qrMenu }
231+ />
232+ ) : null }
188233 </ div >
189234 ) ;
190235}
0 commit comments