fix: rendering video with src

This commit is contained in:
DIYgod
2023-05-12 17:55:52 +01:00
parent 251ea885a9
commit 0c1be7a2cb
+20 -21
View File
@@ -4,32 +4,31 @@ import { ReactElement } from "rehype-react/lib"
import { toGateway } from "~/lib/ipfs-parser"
const DPlayer: FC<{
children: ReactElement[]
}> = memo(function DPlayer({ children }) {
const sources = children.filter(
const DPlayer: FC<
{
src?: string
children?: ReactElement[]
} & DPlayerProps
> = memo(function DPlayer({ src, children, ...props }) {
const sources = children?.filter(
(child) =>
child && typeof child.type === "string" && child.type === "source",
)
if (!src) {
src = (sources?.[0]?.props as DPlayerProps)?.src as string
}
if (!src) {
return null
}
src = toGateway(src)
return (
<>
{sources.map((source, idx) => {
const { src: _src, ...props } = source.props as DPlayerProps
if (!_src) {
return <div key={idx} />
}
const src = toGateway(_src)
return (
<div className="my-8" key={idx}>
<RcDPlayer src={src} {...props} />
</div>
)
})}
</>
<div className="my-8">
<RcDPlayer src={src} {...props} />
</div>
)
})