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,33 +1,46 @@
import clsx from "clsx";
import { formatTime } from "../../utils/utils.ts";
import {Link} from "react-router-dom";
import { Link } from "react-router-dom";
import { useState } from "react";
type VideoCardProps = {
title: string,
duration: number,
thumbnailPath: string,
thumbnailPath: string | null,
videoPath: string,
className?: string
}
const fallbackThumbnail = "../../../public/default_thumbnail.png";
const VideoCard = ({
title,
duration,
thumbnailPath,
videoPath,
className}: VideoCardProps) => {
className
}: VideoCardProps) => {
const initialSrc = thumbnailPath && thumbnailPath.trim() !== "" ? thumbnailPath : fallbackThumbnail;
const [imgSrc, setImgSrc] = useState(initialSrc);
return (
<Link
to={videoPath}
>
<Link to={videoPath}>
<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"}>
<p>{title}</p>
<p>{formatTime(duration)}</p>
</div>
</div>
</Link>
);

View File

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