page.tsx131 lines, 4.6 KB
| 1 | "use client"; |
| 2 | |
| 3 | import { Button } from "@/components/ui/button"; |
| 4 | import { Card } from "@/components/ui/card"; |
| 5 | import { Skeleton } from "@/components/ui/skeleton"; |
| 6 | import { useJobStatus } from "@/lib/hooks/queries/videos"; |
| 7 | import { ArrowLeft } from "lucide-react"; |
| 8 | import Link from "next/link"; |
| 9 | import { useParams } from "next/navigation"; |
| 10 | import { JobCard } from "../../components/job-card"; |
| 11 | import { Badge } from "@/components/ui/badge"; |
| 12 | |
| 13 | export default function HistoryIdPage() { |
| 14 | const { id } = useParams(); |
| 15 | const { data: job, isLoading, error } = useJobStatus(id as string); |
| 16 | |
| 17 | if (error) { |
| 18 | return ( |
| 19 | <div className="text-center py-12"> |
| 20 | <p className="text-red-500"> |
| 21 | Failed to load job details. Please try again later. |
| 22 | </p> |
| 23 | <Link href="/dashboard/history" className="mt-4 inline-block"> |
| 24 | <Button variant="outline"> |
| 25 | <ArrowLeft className="mr-2 h-4 w-4" /> |
| 26 | Back to History |
| 27 | </Button> |
| 28 | </Link> |
| 29 | </div> |
| 30 | ); |
| 31 | } |
| 32 | |
| 33 | if (isLoading || !job) { |
| 34 | return ( |
| 35 | <div className="space-y-6"> |
| 36 | <div className="flex items-center space-x-4"> |
| 37 | <Skeleton className="h-12 w-12 rounded-lg" /> |
| 38 | <div className="space-y-2"> |
| 39 | <Skeleton className="h-4 w-[250px]" /> |
| 40 | <Skeleton className="h-4 w-[150px]" /> |
| 41 | </div> |
| 42 | </div> |
| 43 | <Card className="p-6"> |
| 44 | <div className="space-y-4"> |
| 45 | <Skeleton className="h-4 w-[150px]" /> |
| 46 | <Skeleton className="h-2 w-full" /> |
| 47 | <Skeleton className="h-4 w-3/4" /> |
| 48 | </div> |
| 49 | </Card> |
| 50 | </div> |
| 51 | ); |
| 52 | } |
| 53 | |
| 54 | return ( |
| 55 | <div className="space-y-6"> |
| 56 | <Link href={"/dashboard/history"}> |
| 57 | <Button variant={"outline"} size={"sm"} className="gap-1.5"> |
| 58 | <ArrowLeft className="size-4" /> |
| 59 | Back to History |
| 60 | </Button> |
| 61 | </Link> |
| 62 | |
| 63 | <JobCard job={job} showDetails={false} /> |
| 64 | |
| 65 | {job.state === "completed" && job.result && ( |
| 66 | <div className="grid gap-6"> |
| 67 | {job.result.transcription && ( |
| 68 | <Card className="p-6"> |
| 69 | <div className="flex items-center justify-between mb-4"> |
| 70 | <h3 className="font-medium">Transcription Preview</h3> |
| 71 | {job.videoStatus?.hasTranscription && ( |
| 72 | <Link href={`/dashboard/videos/${job.videoStatus.id}`}> |
| 73 | <Button variant={"outline"} size={"sm"} className="gap-1.5"> |
| 74 | View Full Transcription |
| 75 | </Button> |
| 76 | </Link> |
| 77 | )} |
| 78 | </div> |
| 79 | <div className="max-h-40 overflow-y-hidden prose prose-sm"> |
| 80 | <p className="whitespace-pre-line"> |
| 81 | {job.result.transcription.text.slice(0, 300)} |
| 82 | {job.result.transcription.text.length > 300 && "..."} |
| 83 | </p> |
| 84 | </div> |
| 85 | </Card> |
| 86 | )} |
| 87 | |
| 88 | {job.result.analysis && ( |
| 89 | <Card className="p-6"> |
| 90 | <div className="flex items-center justify-between mb-4"> |
| 91 | <h3 className="font-medium">Analysis Preview</h3> |
| 92 | {job.videoStatus?.hasAnalysis && ( |
| 93 | <Link href={`/dashboard/videos/${job.videoStatus.id}`}> |
| 94 | <Button variant={"outline"} size={"sm"} className="gap-1.5"> |
| 95 | View Full Analysis |
| 96 | </Button> |
| 97 | </Link> |
| 98 | )} |
| 99 | </div> |
| 100 | <div className="max-h-40 overflow-y-hidden prose prose-sm"> |
| 101 | <p className="whitespace-pre-line"> |
| 102 | {job.result.analysis.summary.slice(0, 300)} |
| 103 | {job.result.analysis.summary.length > 300 && "..."} |
| 104 | </p> |
| 105 | </div> |
| 106 | {job.result.analysis.topics.length > 0 && ( |
| 107 | <div className="mt-4"> |
| 108 | <h4 className="font-medium mb-2">Topics</h4> |
| 109 | <div className="flex flex-wrap gap-2"> |
| 110 | {job.result.analysis.topics |
| 111 | .slice(0, 5) |
| 112 | .map((topic, index) => ( |
| 113 | <Badge key={index} variant={"secondary"}> |
| 114 | {topic} |
| 115 | </Badge> |
| 116 | ))} |
| 117 | {job.result.analysis.topics.length > 5 && ( |
| 118 | <Badge variant={"secondary"}> |
| 119 | +{job.result.analysis.topics.length - 5} more |
| 120 | </Badge> |
| 121 | )} |
| 122 | </div> |
| 123 | </div> |
| 124 | )} |
| 125 | </Card> |
| 126 | )} |
| 127 | </div> |
| 128 | )} |
| 129 | </div> |
| 130 | ); |
| 131 | } |