import type { PreloadValue } from '@app/shared/sandbox-listener'; import type { SourceId } from '@app/shared/sources'; import type { Preset, Skin, Styling } from '@app/types'; import { forwardRef, useState } from 'react'; type PreviewProps = { pagePath: string; preset: Preset; skin: Skin; styling: Styling; source: SourceId; autoplay: boolean; muted: boolean; loop: boolean; preload: PreloadValue; }; export const Preview = forwardRef(function Preview( { pagePath, preset, skin, styling, source, autoplay, muted, loop, preload }, ref ) { const buildUrl = (base: string) => { const params = new URLSearchParams({ preset, skin, styling, source, autoplay: autoplay ? '1' : '0', muted: muted ? '1' : '0', loop: loop ? '1' : '0', preload, }); return `${base}?${params}`; }; // Capture the initial query so the iframe doesn't reload when autoplay/muted // toggle — those changes are streamed in via postMessage. const [iframeUrl] = useState(() => buildUrl(pagePath)); const openUrl = buildUrl(pagePath); return (
Open