Skip to content

Commit

Permalink
fix: <Media/> show fallback
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Aug 12, 2024
1 parent 4f429a9 commit ca0fd18
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/renderer/src/components/ui/media.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const failedList = new Set<string | undefined>()

type BaseProps = {
mediaContainerClassName?: string
showFallback?: boolean
}
export type MediaProps = BaseProps &
(
Expand Down Expand Up @@ -47,7 +48,7 @@ const MediaImpl: FC<MediaProps> = ({
mediaContainerClassName,
...props
}) => {
const { src, style, type, previewImageUrl, ...rest } = props
const { src, style, type, previewImageUrl, showFallback, ...rest } = props
const [hidden, setHidden] = useState(!src)
const [imgSrc, setImgSrc] = useState(() =>
proxy && src && !failedList.has(src) ?
Expand Down Expand Up @@ -198,7 +199,9 @@ const MediaImpl: FC<MediaProps> = ({
type,
])

if (hidden) return <FallbackMedia {...props} />
if (hidden) {
if (showFallback) { return <FallbackMedia {...props} /> } else { return null }
}
return (
<div className={cn("overflow-hidden rounded", className)} style={style}>
{InnerContent}
Expand Down Expand Up @@ -232,9 +235,13 @@ const FallbackMedia: FC<MediaProps> = ({
<p className="flex items-center gap-1">
Go to
{" "}
<a href={props.src} target="_blank" rel="noreferrer" className="follow-link--underline">
<a
href={props.src}
target="_blank"
rel="noreferrer"
className="follow-link--underline"
>
{props.src}

</a>
<i className="i-mgc-external-link-cute-re" />
</p>
Expand Down
1 change: 1 addition & 0 deletions src/renderer/src/lib/parse-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ const Img: Components["img"] = ({ node, ...props }) => {
mediaContainerClassName: tw`max-w-full inline size-auto`,
popper: true,
className: tw`inline`,
showFallback: true,
})
}

Expand Down

0 comments on commit ca0fd18

Please sign in to comment.