From 0c1be7a2cbafaadf2f31f7309731f8fdf9b277fa Mon Sep 17 00:00:00 2001 From: DIYgod Date: Fri, 12 May 2023 17:55:52 +0100 Subject: [PATCH] fix: rendering video with src --- src/components/ui/DPlayer.tsx | 41 +++++++++++++++++------------------ 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/components/ui/DPlayer.tsx b/src/components/ui/DPlayer.tsx index 6bbad2e7..40690d71 100644 --- a/src/components/ui/DPlayer.tsx +++ b/src/components/ui/DPlayer.tsx @@ -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
- } - - const src = toGateway(_src) - - return ( -
- -
- ) - })} - +
+ +
) })