Refac preemptive image fallback when url is undefined. Ticket: #911

This commit is contained in:
MerlinScheurer 2025-03-28 01:34:34 +01:00
parent 0aa5ef5b31
commit 2be190aa65
5 changed files with 35 additions and 5 deletions

View File

@ -7,9 +7,15 @@ type ChannelIconProps = {
};
const ChannelBanner = ({ channelId, channelBannerUrl }: ChannelIconProps) => {
let src = `${getApiUrl()}${channelBannerUrl}`;
if (channelBannerUrl === undefined) {
src = defaultChannelImage;
}
return (
<img
src={`${getApiUrl()}${channelBannerUrl}`}
src={src}
alt={`${channelId}-banner`}
onError={({ currentTarget }) => {
currentTarget.onerror = null; // prevents looping

View File

@ -7,9 +7,15 @@ type ChannelIconProps = {
};
const ChannelIcon = ({ channelId, channelThumbUrl }: ChannelIconProps) => {
let src = `${getApiUrl()}${channelThumbUrl}`;
if (channelThumbUrl === undefined) {
src = defaultChannelIcon;
}
return (
<img
src={`${getApiUrl()}${channelThumbUrl}`}
src={src}
alt={`${channelId}-thumb`}
onError={({ currentTarget }) => {
currentTarget.onerror = null; // prevents looping

View File

@ -22,12 +22,18 @@ const DownloadListItem = ({ download, setRefresh }: DownloadListItemProps) => {
const [hideDownload, setHideDownload] = useState(false);
let src = `${getApiUrl()}${download.vid_thumb_url}`;
if (download.vid_thumb_url === undefined) {
src = defaultVideoThumb;
}
return (
<div className={`video-item ${view}`} id={`dl-${download.youtube_id}`}>
<div className={`video-thumb-wrap ${view}`}>
<div className="video-thumb">
<img
src={`${getApiUrl()}${download.vid_thumb_url}`}
src={src}
alt="video_thumb"
onError={({ currentTarget }) => {
currentTarget.onerror = null; // prevents looping

View File

@ -7,9 +7,15 @@ type PlaylistThumbnailProps = {
};
const PlaylistThumbnail = ({ playlistId, playlistThumbnail }: PlaylistThumbnailProps) => {
let src = `${getApiUrl()}${playlistThumbnail}`;
if (playlistThumbnail === undefined) {
src = defaultPlaylistThumbnail;
}
return (
<img
src={`${getApiUrl()}${playlistThumbnail}`}
src={src}
alt={`${playlistId}-thumbnail`}
onError={({ currentTarget }) => {
currentTarget.onerror = null; // prevents looping

View File

@ -36,6 +36,12 @@ const VideoListItem = ({
return <p>No video found.</p>;
}
let videoThumbSrc = `${getApiUrl()}${video.vid_thumb_url}`;
if (video.vid_thumb_url === undefined) {
videoThumbSrc = defaultVideoThumb;
}
return (
<div className={`video-item ${viewLayout}`}>
<a
@ -46,7 +52,7 @@ const VideoListItem = ({
<div className={`video-thumb-wrap ${viewLayout}`}>
<div className="video-thumb">
<img
src={`${getApiUrl()}${video.vid_thumb_url}`}
src={videoThumbSrc}
alt="video-thumb"
onError={({ currentTarget }) => {
currentTarget.onerror = null; // prevents looping