You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
draw-a-ui/app/components/LinkComponent.tsx

49 lines
1.1 KiB
TypeScript

'use client'
import { useEffect } from 'react'
export function LinkComponent({
linkId,
isPreview,
html,
}: {
linkId: string
isPreview: boolean
html: string
}) {
useEffect(() => {
//listen for screenshot messages
if (typeof window !== 'undefined') {
const windowListener = (event: MessageEvent) => {
if (event.data.action === 'take-screenshot') {
const iframe2 = document.getElementById(`iframe-2-shape:${linkId}`) as HTMLIFrameElement
iframe2.contentWindow.postMessage(
{ action: 'take-screenshot', shapeid: `shape:${linkId}` },
'*'
)
}
}
window.addEventListener('message', windowListener)
return () => {
window.removeEventListener('message', windowListener)
}
}
}, [linkId])
return (
<iframe
id={`iframe-2-shape:${linkId}`}
srcDoc={html}
draggable={false}
allow="geolocation;midi;usb;magnetometer;fullscreen;animations;picture-in-picture;accelerometer;vr;camera;microphone"
style={{
position: 'fixed',
inset: 0,
width: '100%',
height: '100%',
border: 'none',
}}
/>
)
}