ADD fallback thumbnail
This commit is contained in:
BIN
frontend/public/default_thumbnail.png
Normal file
BIN
frontend/public/default_thumbnail.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
@@ -1,33 +1,46 @@
|
|||||||
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>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -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"}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user