ADD fallback thumbnail

This commit is contained in:
2025-07-09 23:12:12 +02:00
parent c001a2a1a6
commit 16781aec04
3 changed files with 23 additions and 10 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@@ -1,36 +1,49 @@
import clsx from "clsx"; import clsx from "clsx";
import { formatTime } from "../../utils/utils.ts"; import { formatTime } from "../../utils/utils.ts";
import {Link} from "react-router-dom"; import { Link } from "react-router-dom";
import { useState } from "react";
type VideoCardProps = { type VideoCardProps = {
title: string, title: string,
duration: number, duration: number,
thumbnailPath: string, thumbnailPath: string | null,
videoPath: string, videoPath: string,
className?: string className?: string
} }
const fallbackThumbnail = "../../../public/default_thumbnail.png";
const VideoCard = ({ const VideoCard = ({
title, title,
duration, duration,
thumbnailPath, thumbnailPath,
videoPath, videoPath,
className}: VideoCardProps) => { className
}: VideoCardProps) => {
const initialSrc = thumbnailPath && thumbnailPath.trim() !== "" ? thumbnailPath : fallbackThumbnail;
const [imgSrc, setImgSrc] = useState(initialSrc);
return ( return (
<Link <Link to={videoPath}>
to={videoPath}
>
<div className={clsx("flex flex-col", className)}> <div className={clsx("flex flex-col", className)}>
<img src={thumbnailPath} alt="Video Thumbnail" /> <img
src={imgSrc}
alt="Video Thumbnail"
onError={() => {
if (imgSrc !== fallbackThumbnail) {
setImgSrc(fallbackThumbnail);
}
}}
/>
<div className={"flex flex-row justify-between items-center p-2"}> <div className={"flex flex-row justify-between items-center p-2"}>
<p>{title}</p> <p>{title}</p>
<p>{formatTime(duration)}</p> <p>{formatTime(duration)}</p>
</div> </div>
</div> </div>
</Link> </Link>
); );
} }
export default VideoCard; export default VideoCard;

View File

@@ -20,7 +20,7 @@ const MyClips = () => {
duration={clip.duration} duration={clip.duration}
thumbnailPath={clip.thumbnailPath} thumbnailPath={clip.thumbnailPath}
videoPath={clip.videoPath} videoPath={clip.videoPath}
className={"w-30 p-5"} className={"w-40 p-5"}
/> />
))} ))}