fix: Replace broken media thumbnails with MediaThumbnail component

Old Cloudinary URLs no longer load (account full). The new MediaThumbnail
component handles broken URLs gracefully with a fallback icon, and uses
<video preload="metadata"> for local video files to show the first frame.

- New component: client/src/components/media-thumbnail.tsx
- Updated: new-reel.tsx, new-post.tsx, media-upload.tsx,
           edit-scheduled-post-dialog.tsx

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
MichaelandClaude Sonnet 4.6 committed 2026-03-25 08:05:04 +01:00
1 parent 7733acbc22
commit 2744b538e3
5 files changed
+83 -66

No files matched your search

+57
View File
@@ -0,0 +1,57 @@
import { useState } from 'react';
import { ImageIcon, VideoIcon } from 'lucide-react';
interface MediaThumbnailProps {
src: string;
alt: string;
type?: 'image' | 'video';
className?: string;
}
function isVideoUrl(url: string): boolean {
return /\.(mp4|mov|avi|webm|mkv|m4v)(\?.*)?$/i.test(url);
}
/**
* Renders a media thumbnail that handles:
* - Local video files: uses <video preload="metadata"> to show first frame
* - Images: standard <img> with lazy loading
* - Broken/unavailable URLs: shows a placeholder icon
*/
export function MediaThumbnail({ src, alt, type, className = "w-full h-full object-cover" }: MediaThumbnailProps) {
const [error, setError] = useState(false);
const isVideo = type === 'video' || isVideoUrl(src);
if (error || !src) {
return (
<div className={`flex items-center justify-center bg-muted ${className.replace('object-cover', '')}`}>
{isVideo
? <VideoIcon className="w-8 h-8 text-muted-foreground" />
: <ImageIcon className="w-8 h-8 text-muted-foreground" />
}
</div>
);
}
if (isVideo) {
return (
<video
src={src}
className={className}
preload="metadata"
muted
onError={() => setError(true)}
/>
);
}
return (
<img
src={src}
alt={alt}
className={className}
loading="lazy"
onError={() => setError(true)}
/>
);
}