video-card.tsx159 lines, 5.6 KB
| 1 | "use client"; |
| 2 | |
| 3 | import { Button } from "@/components/ui/button"; |
| 4 | import { Card, CardContent } from "@/components/ui/card"; |
| 5 | import { Video } from "@/lib/api/types"; |
| 6 | import { cn } from "@/lib/utils"; |
| 7 | import { formatDistanceToNow } from "date-fns"; |
| 8 | import { |
| 9 | CheckCircle2, |
| 10 | Clock, |
| 11 | ExternalLink, |
| 12 | PlayCircle, |
| 13 | XCircle, |
| 14 | Youtube, |
| 15 | } from "lucide-react"; |
| 16 | import Image from "next/image"; |
| 17 | import Link from "next/link"; |
| 18 | |
| 19 | interface VideoCardProps { |
| 20 | video: Video & { thumbnail?: string }; |
| 21 | } |
| 22 | |
| 23 | function getStatusIndicator(status: unknown) { |
| 24 | if (!!status) { |
| 25 | return { Icon: CheckCircle2, color: "text-green-500", text: "Complete" }; |
| 26 | } |
| 27 | return { |
| 28 | Icon: XCircle, |
| 29 | color: "text-muted-foreground/70", |
| 30 | text: "Unavailable", |
| 31 | }; |
| 32 | } |
| 33 | |
| 34 | export function VideoCard({ video }: VideoCardProps) { |
| 35 | const transcriptionStatus = getStatusIndicator(video.transcription); |
| 36 | const analysisStatus = getStatusIndicator(video.analysis); |
| 37 | |
| 38 | return ( |
| 39 | <Card className="overflow-hidden transition-all hover:shadow-lg"> |
| 40 | <CardContent className="p-4 sm:p-6"> |
| 41 | <div className="flex flex-col sm:flex-row items-start gap-4"> |
| 42 | <div className="relative flex-shrink-0 w-full sm:w-40 h-24 rounded-md overflow-hidden bg-muted flex items-center justify-center group"> |
| 43 | {video.thumbnail ? ( |
| 44 | <> |
| 45 | <Image |
| 46 | src={video.thumbnail} |
| 47 | alt={video.title} |
| 48 | fill |
| 49 | className="object-cover transition-transform duration-300 group-hover:scale-105" |
| 50 | sizes="(max-width: 640px) 100vw, 160px" |
| 51 | /> |
| 52 | <div className="absolute inset-0 bg-gradient-to-t from-black/40 via-black/10 to-transparent"></div> |
| 53 | <div className="absolute inset-0 bg-black/20 opacity-0 group-hover:opacity-100 transition-opacity duration-300 flex items-center justify-center"> |
| 54 | <PlayCircle className="size-8 text-white/90 drop-shadow-lg" /> |
| 55 | </div> |
| 56 | </> |
| 57 | ) : ( |
| 58 | <Youtube className="size-8 text-muted-foreground/60" /> |
| 59 | )} |
| 60 | </div> |
| 61 | |
| 62 | <div className="flex-1 min-w-0"> |
| 63 | <h3 className="text-lg font-semibold leading-tight mb-1 truncate"> |
| 64 | {video.title || "Untitled Video"} |
| 65 | </h3> |
| 66 | |
| 67 | {video.description && ( |
| 68 | <p className="text-sm text-muted-foreground line-clamp-2 mb-3"> |
| 69 | {video.description} |
| 70 | </p> |
| 71 | )} |
| 72 | |
| 73 | <div className="flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground mb-3"> |
| 74 | {video.author && ( |
| 75 | <span className="inline-flex items-center gap-1"> |
| 76 | <Youtube className="size-3" /> {video.author} |
| 77 | </span> |
| 78 | )} |
| 79 | {video.duration > 0 && ( |
| 80 | <> |
| 81 | {video.author && <span className="opacity-50">•</span>} |
| 82 | <span className="inline-flex items-center gap-1"> |
| 83 | <Clock className="size-3" /> |
| 84 | {Math.floor(video.duration / 60)} min{" "} |
| 85 | {Math.floor(video.duration % 60)} sec |
| 86 | </span> |
| 87 | </> |
| 88 | )} |
| 89 | {video.createdAt && ( |
| 90 | <> |
| 91 | {(video.author || video.duration > 0) && ( |
| 92 | <span className="opacity-50">•</span> |
| 93 | )} |
| 94 | <span> |
| 95 | {formatDistanceToNow(new Date(video.createdAt), { |
| 96 | addSuffix: true, |
| 97 | })} |
| 98 | </span> |
| 99 | </> |
| 100 | )} |
| 101 | </div> |
| 102 | |
| 103 | <div className="flex flex-wrap items-center gap-x-4 gap-y-1 text-xs mb-4"> |
| 104 | <div |
| 105 | className={cn( |
| 106 | "inline-flex items-center gap-1.5", |
| 107 | transcriptionStatus.color |
| 108 | )} |
| 109 | > |
| 110 | <transcriptionStatus.Icon className={cn("size-3.5")} /> |
| 111 | <span className="font-medium">Transcription</span> |
| 112 | <span className="text-muted-foreground/80"> |
| 113 | ({transcriptionStatus.text}) |
| 114 | </span> |
| 115 | </div> |
| 116 | <div |
| 117 | className={cn( |
| 118 | "inline-flex items-center gap-1.5", |
| 119 | analysisStatus.color |
| 120 | )} |
| 121 | > |
| 122 | <analysisStatus.Icon className={cn("size-3.5")} /> |
| 123 | <span className="font-medium">Analysis</span> |
| 124 | <span className="text-muted-foreground/80"> |
| 125 | ({analysisStatus.text}) |
| 126 | </span> |
| 127 | </div> |
| 128 | </div> |
| 129 | |
| 130 | <div className="flex items-center justify-end gap-2"> |
| 131 | {video.url && ( |
| 132 | <Button variant="outline" size="sm" asChild> |
| 133 | <a |
| 134 | href={video.url} |
| 135 | target="_blank" |
| 136 | rel="noopener noreferrer" |
| 137 | className="inline-flex items-center gap-1.5" |
| 138 | > |
| 139 | <Youtube className="h-3.5 w-3.5" /> |
| 140 | <span>Watch</span> |
| 141 | </a> |
| 142 | </Button> |
| 143 | )} |
| 144 | <Button variant="default" size="sm" asChild> |
| 145 | <Link |
| 146 | href={`/dashboard/videos/${video.id}`} |
| 147 | className="inline-flex items-center gap-1.5" |
| 148 | > |
| 149 | <ExternalLink className="h-3.5 w-3.5" /> |
| 150 | <span>View Details</span> |
| 151 | </Link> |
| 152 | </Button> |
| 153 | </div> |
| 154 | </div> |
| 155 | </div> |
| 156 | </CardContent> |
| 157 | </Card> |
| 158 | ); |
| 159 | } |