Spaces:
Build error
Build error
File size: 7,748 Bytes
fa4dd74 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | "use client"
import { useState, useEffect } from "react"
import { Button } from "@/components/ui/button"
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card"
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
import { Badge } from "@/components/ui/badge"
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
import { toast } from "sonner"
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"
import axios from "axios"
import YouTube from "react-youtube"
const fetchReviewQueue = async () => {
const response = await axios.get("/api/review-queue")
return response.data
}
const updateReviewItem = async (id, status, metadata) => {
const response = await axios.put(`/api/review-queue/${id}`, { status, metadata })
return response.data
}
export function ReviewQueue() {
const [selectedItem, setSelectedItem] = useState(null)
const queryClient = useQueryClient()
const { data: queue, isLoading, error } = useQuery({
queryKey: ["reviewQueue"],
queryFn: fetchReviewQueue,
})
const mutation = useMutation({
mutationFn: updateReviewItem,
onSuccess: () => {
queryClient.invalidateQueries(["reviewQueue"])
toast.success("Item updated successfully")
setSelectedItem(null)
},
onError: (error) => {
toast.error(`Error updating item: ${error.message}`)
},
})
const handleApprove = (item) => {
mutation.mutate({ id: item.id, status: "approved", metadata: item.metadata })
}
const handleReject = (item) => {
mutation.mutate({ id: item.id, status: "rejected", metadata: item.metadata })
}
const handleEdit = (item) => {
setSelectedItem(item)
}
const handleSaveEdit = () => {
mutation.mutate({
id: selectedItem.id,
status: "approved",
metadata: selectedItem.metadata,
})
}
if (isLoading) return <div className="p-4">Loading...</div>
if (error) return <Alert variant="destructive"><AlertTitle>Error</AlertTitle><AlertDescription>{error.message}</AlertDescription></Alert>
return (
<div className="flex flex-col gap-4">
<Card>
<CardHeader>
<CardTitle>Review Queue</CardTitle>
<CardDescription>Manage content flagged for manual review</CardDescription>
</CardHeader>
<CardContent>
<Table>
<TableHeader>
<TableRow>
<TableHead>Title</TableHead>
<TableHead>Channel</TableHead>
<TableHead>Status</TableHead>
<TableHead>Actions</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{queue?.map((item) => (
<TableRow key={item.id}>
<TableCell className="font-medium">{item.title}</TableCell>
<TableCell>{item.channel}</TableCell>
<TableCell>
<Badge variant={item.status === "flagged" ? "destructive" : "secondary"}>
{item.status}
</Badge>
</TableCell>
<TableCell>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" className="h-8 w-8 p-0">
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
className="h-4 w-4"
>
<path d="M5 12h14" />
<path d="M12 5v14" />
</svg>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem onClick={() => handleApprove(item)}>Approve</DropdownMenuItem>
<DropdownMenuItem onClick={() => handleReject(item)}>Reject</DropdownMenuItem>
<DropdownMenuItem onClick={() => handleEdit(item)}>Edit Metadata</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</CardContent>
</Card>
{selectedItem && (
<Card>
<CardHeader>
<CardTitle>Edit Metadata</CardTitle>
<CardDescription>Review and edit content details</CardDescription>
</CardHeader>
<CardContent className="grid gap-4">
<div className="grid gap-2">
<div className="aspect-video">
<YouTube videoId={selectedItem.videoId} opts={{ width: "100%", height: "100%" }} />
</div>
<div className="grid gap-1">
<div className="font-medium">{selectedItem.title}</div>
<div className="text-sm text-muted-foreground">{selectedItem.channel}</div>
</div>
</div>
<div className="grid gap-2">
<div className="font-medium">Transcript</div>
<div className="rounded-md border p-4 text-sm">
{selectedItem.transcript}
</div>
</div>
<div className="grid gap-2">
<div className="font-medium">Extracted Metadata</div>
<div className="grid gap-2">
<div className="flex items-center gap-2">
<div className="text-sm text-muted-foreground">Series:</div>
<input
type="text"
value={selectedItem.metadata.series || ""}
onChange={(e) => setSelectedItem({
...selectedItem,
metadata: { ...selectedItem.metadata, series: e.target.value }
})}
className="rounded-md border px-2 py-1 text-sm"
/>
</div>
<div className="flex items-center gap-2">
<div className="text-sm text-muted-foreground">Characters:</div>
<input
type="text"
value={selectedItem.metadata.characters || ""}
onChange={(e) => setSelectedItem({
...selectedItem,
metadata: { ...selectedItem.metadata, characters: e.target.value }
})}
className="rounded-md border px-2 py-1 text-sm"
/>
</div>
<div className="flex items-center gap-2">
<div className="text-sm text-muted-foreground">Themes:</div>
<input
type="text"
value={selectedItem.metadata.themes || ""}
onChange={(e) => setSelectedItem({
...selectedItem,
metadata: { ...selectedItem.metadata, themes: e.target.value }
})}
className="rounded-md border px-2 py-1 text-sm"
/>
</div>
</div>
</div>
</CardContent> |