2026-08-05 13:13:48 -05:00
|
|
|
import { Box } from "@radix-ui/themes";
|
|
|
|
|
import { useEffect, useRef } from "react";
|
|
|
|
|
import { embedPreviews } from "../../constants/embeds";
|
|
|
|
|
import { useEmbedStateCurry } from "../../stores/embedState/utilities";
|
2024-10-26 14:33:04 -05:00
|
|
|
|
|
|
|
|
interface PreviewWrapperProps {
|
2024-10-26 19:46:35 -05:00
|
|
|
name: keyof typeof embedPreviews;
|
2024-10-28 10:57:42 -05:00
|
|
|
naked?: boolean;
|
2024-10-26 14:33:04 -05:00
|
|
|
}
|
|
|
|
|
|
2024-10-28 10:57:42 -05:00
|
|
|
export function PreviewWrapper({ name, naked }: PreviewWrapperProps) {
|
2024-10-28 10:30:53 -05:00
|
|
|
const { useEmbedState } = useEmbedStateCurry();
|
2026-08-05 13:13:48 -05:00
|
|
|
|
|
|
|
|
const width = useEmbedState("width");
|
|
|
|
|
const height = useEmbedState("height");
|
|
|
|
|
|
2024-10-26 19:46:35 -05:00
|
|
|
const Preview = embedPreviews[name];
|
2026-08-05 13:13:48 -05:00
|
|
|
|
2024-10-26 14:33:04 -05:00
|
|
|
const wrapper = useRef<HTMLDivElement>(null);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (!wrapper.current) return;
|
|
|
|
|
|
2026-08-05 13:13:48 -05:00
|
|
|
wrapper.current.classList.remove("preview-container-animated");
|
2024-10-26 14:33:04 -05:00
|
|
|
void wrapper.current.offsetWidth;
|
2026-08-05 13:13:48 -05:00
|
|
|
wrapper.current.classList.add("preview-container-animated");
|
2024-10-26 14:33:04 -05:00
|
|
|
}, [width, height]);
|
|
|
|
|
|
2024-10-28 10:57:42 -05:00
|
|
|
if (naked) {
|
|
|
|
|
return (
|
|
|
|
|
<Box
|
|
|
|
|
position="absolute"
|
|
|
|
|
top="0"
|
|
|
|
|
left="50%"
|
2026-08-05 13:13:48 -05:00
|
|
|
style={{ transform: "translate(-50%, 0) scale(0.75)" }}
|
2024-10-28 10:57:42 -05:00
|
|
|
width={`${width}px`}
|
|
|
|
|
height={`${height}px`}
|
|
|
|
|
>
|
|
|
|
|
<Preview />
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-26 14:33:04 -05:00
|
|
|
return (
|
|
|
|
|
<Box
|
2024-10-28 10:57:42 -05:00
|
|
|
position="absolute"
|
|
|
|
|
top="50%"
|
|
|
|
|
left="50%"
|
|
|
|
|
overflow="hidden"
|
2026-08-05 13:13:48 -05:00
|
|
|
style={{ transform: naked ? "scale(0.25)" : "translate(-50%, -50%)" }}
|
2024-10-26 14:33:04 -05:00
|
|
|
ref={wrapper}
|
2024-11-01 10:52:54 -05:00
|
|
|
className="preview-container-animated"
|
2024-10-26 14:33:04 -05:00
|
|
|
width={`${width}px`}
|
|
|
|
|
height={`${height}px`}
|
|
|
|
|
>
|
|
|
|
|
<Preview />
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
}
|