page.tsx172 lines, 6.0 KB
| 1 | "use client"; |
| 2 | |
| 3 | import { useUserVideos } from "@/lib/hooks/queries/videos"; |
| 4 | import { Button } from "@/components/ui/button"; |
| 5 | import { Skeleton } from "@/components/ui/skeleton"; |
| 6 | import Link from "next/link"; |
| 7 | import { AlertCircle, Plus, VideoIcon, FileVideo } from "lucide-react"; |
| 8 | import { |
| 9 | Select, |
| 10 | SelectContent, |
| 11 | SelectItem, |
| 12 | SelectTrigger, |
| 13 | SelectValue, |
| 14 | } from "@/components/ui/select"; |
| 15 | import { useState } from "react"; |
| 16 | import { VideoCard } from "../components/video-card"; |
| 17 | import { Card } from "@/components/ui/card"; |
| 18 | |
| 19 | function VideoCardSkeleton() { |
| 20 | return ( |
| 21 | <Card className="overflow-hidden"> |
| 22 | <div className="p-4 sm:p-6"> |
| 23 | <div className="flex flex-col sm:flex-row items-start gap-4"> |
| 24 | <Skeleton className="flex-shrink-0 w-full sm:w-40 h-24 rounded-md" /> |
| 25 | <div className="flex-1 min-w-0 space-y-2"> |
| 26 | <Skeleton className="h-5 w-3/4 mb-1" /> |
| 27 | <Skeleton className="h-4 w-full" /> |
| 28 | <Skeleton className="h-4 w-5/6" /> |
| 29 | <div className="flex gap-3 pt-1"> |
| 30 | <Skeleton className="h-3 w-20" /> |
| 31 | <Skeleton className="h-3 w-16" /> |
| 32 | <Skeleton className="h-3 w-24" /> |
| 33 | </div> |
| 34 | <div className="flex gap-4 pt-1"> |
| 35 | <Skeleton className="h-4 w-28" /> |
| 36 | <Skeleton className="h-4 w-28" /> |
| 37 | </div> |
| 38 | <div className="flex justify-end pt-2"> |
| 39 | <Skeleton className="h-8 w-20 mr-2" /> |
| 40 | <Skeleton className="h-8 w-24" /> |
| 41 | </div> |
| 42 | </div> |
| 43 | </div> |
| 44 | </div> |
| 45 | </Card> |
| 46 | ); |
| 47 | } |
| 48 | |
| 49 | export default function VideosPage() { |
| 50 | const [filter, setFilter] = useState<string>("all"); |
| 51 | const { data: videos, isLoading, error, refetch } = useUserVideos(); |
| 52 | |
| 53 | if (error) { |
| 54 | return ( |
| 55 | <div className="flex flex-col items-center justify-center min-h-[400px] text-center p-6 bg-red-50 border border-red-200 rounded-lg shadow-sm"> |
| 56 | <AlertCircle className="size-12 text-red-500 mb-4" /> |
| 57 | <h2 className="text-xl font-semibold text-red-700 mb-2"> |
| 58 | Oops! Something went wrong. |
| 59 | </h2> |
| 60 | <p className="text-red-600 mb-6 max-w-md"> |
| 61 | We couldn't load your videos at the moment. Please try again. |
| 62 | </p> |
| 63 | <Button |
| 64 | onClick={() => refetch()} |
| 65 | variant={"destructive"} |
| 66 | className="gap-2" |
| 67 | > |
| 68 | <AlertCircle className="size-4" /> |
| 69 | Try Again |
| 70 | </Button> |
| 71 | </div> |
| 72 | ); |
| 73 | } |
| 74 | |
| 75 | if (isLoading || !videos) { |
| 76 | return ( |
| 77 | <div className="space-y-6"> |
| 78 | <div className="flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4"> |
| 79 | <div className="space-y-1.5"> |
| 80 | <Skeleton className="h-7 w-40" /> |
| 81 | <Skeleton className="h-4 w-56" /> |
| 82 | </div> |
| 83 | <div className="flex items-center gap-4 w-full sm:w-auto"> |
| 84 | <Skeleton className="h-10 w-full sm:w-[180px]" /> |
| 85 | <Skeleton className="h-10 w-32 flex-shrink-0" /> |
| 86 | </div> |
| 87 | </div> |
| 88 | <div className="grid grid-cols-1 lg:grid-cols-2 gap-4"> |
| 89 | {Array.from({ length: 4 }).map((_, i) => ( |
| 90 | <VideoCardSkeleton key={i} /> |
| 91 | ))} |
| 92 | </div> |
| 93 | </div> |
| 94 | ); |
| 95 | } |
| 96 | |
| 97 | const filteredVideos = videos.filter((video) => { |
| 98 | if (filter === "all") return true; |
| 99 | if (filter === "analyzed") return !!video.analysis; |
| 100 | if (filter === "transcribed") return !!video.transcription; |
| 101 | return true; |
| 102 | }); |
| 103 | |
| 104 | const hasVideos = videos.length > 0; |
| 105 | const hasFilteredVideos = filteredVideos.length > 0; |
| 106 | |
| 107 | if (!hasVideos) { |
| 108 | return ( |
| 109 | <div className="flex flex-col items-center justify-center min-h-[400px] text-center p-6 bg-gray-50 border border-dashed border-gray-300 rounded-lg shadow-sm"> |
| 110 | <FileVideo className="size-12 text-gray-400 mb-4" /> |
| 111 | <h2 className="text-xl font-semibold text-gray-700 mb-2"> |
| 112 | No Videos Found |
| 113 | </h2> |
| 114 | <p className="text-muted-foreground mb-6 max-w-md"> |
| 115 | It looks like you haven't submitted any videos for analysis yet. |
| 116 | </p> |
| 117 | <Button asChild size="lg"> |
| 118 | <Link href={"/dashboard/create"} className="gap-2"> |
| 119 | <Plus className="size-4" /> |
| 120 | Submit Your First Video |
| 121 | </Link> |
| 122 | </Button> |
| 123 | </div> |
| 124 | ); |
| 125 | } |
| 126 | |
| 127 | return ( |
| 128 | <div className="space-y-6"> |
| 129 | <div className="flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4"> |
| 130 | <div> |
| 131 | <h1 className="text-2xl font-bold tracking-tight">My Videos</h1> |
| 132 | <p className="text-muted-foreground"> |
| 133 | Manage and review your analyzed video content. |
| 134 | </p> |
| 135 | </div> |
| 136 | <div className="flex items-center gap-2 w-full sm:w-auto"> |
| 137 | <Select value={filter} onValueChange={setFilter}> |
| 138 | <SelectTrigger className="w-full sm:w-[180px]"> |
| 139 | <SelectValue placeholder="Filter videos" /> |
| 140 | </SelectTrigger> |
| 141 | <SelectContent> |
| 142 | <SelectItem value="all">All Videos</SelectItem> |
| 143 | <SelectItem value="analyzed">Analyzed</SelectItem> |
| 144 | <SelectItem value="transcribed">Transcribed</SelectItem> |
| 145 | </SelectContent> |
| 146 | </Select> |
| 147 | <Button asChild className="flex-shrink-0"> |
| 148 | <Link href="/dashboard" className="gap-1.5"> |
| 149 | <Plus className="h-4 w-4" /> |
| 150 | Submit Video |
| 151 | </Link> |
| 152 | </Button> |
| 153 | </div> |
| 154 | </div> |
| 155 | |
| 156 | {hasFilteredVideos ? ( |
| 157 | <div className="grid grid-cols-1 lg:grid-cols-2 gap-4"> |
| 158 | {filteredVideos.map((video) => ( |
| 159 | <VideoCard key={video.id} video={video} /> |
| 160 | ))} |
| 161 | </div> |
| 162 | ) : ( |
| 163 | <div className="flex flex-col items-center justify-center min-h-[250px] text-center p-6 bg-gray-50/50 border border-dashed border-gray-200 rounded-lg"> |
| 164 | <FileVideo className="size-10 text-gray-400 mb-3" /> |
| 165 | <p className="text-muted-foreground"> |
| 166 | No videos found matching the filter "{filter}". |
| 167 | </p> |
| 168 | </div> |
| 169 | )} |
| 170 | </div> |
| 171 | ); |
| 172 | } |