Skip to content

Commit

Permalink
fix(VideoBlock): fix add search params to src
Browse files Browse the repository at this point in the history
  • Loading branch information
aeksandla committed Dec 3, 2024
1 parent 3cf0683 commit fc6c7ed
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/components/VideoBlock/VideoBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,27 @@ const VideoBlock = (props: VideoBlockProps) => {

const [isPlaying, setIsPlaying] = useState(!previewImg);

const iframeSrc =
src && isPlaying
? `${src}?${getPageSearchParams({
...(attributes || {}),
...(previewImg || autoplay ? AUTOPLAY_ATTRIBUTES : NO_AUTOPLAY_ATTRIBUTES),
})}`
: undefined;
const iframeSrc = useMemo(() => {
if (src && isPlaying) {
try {
const url = new URL(src);
const searchParams = getPageSearchParams({
...(attributes || {}),
...(previewImg || autoplay ? AUTOPLAY_ATTRIBUTES : NO_AUTOPLAY_ATTRIBUTES),
});

searchParams.forEach((value, key) => {
url.searchParams.set(key, value);
});

return url.href;
} catch (e) {
return src;
}
}

return undefined;
}, [attributes, autoplay, isPlaying, previewImg, src]);

const onPreviewClick = useCallback(() => {
handleAnalytics(analyticsEvents);
Expand Down

0 comments on commit fc6c7ed

Please sign in to comment.