feat: implement extraction management features including creation, loading states, and filtering

This commit is contained in:
JSC
2025-08-17 01:27:51 +02:00
parent 0024f1d647
commit ed888dd8d1
7 changed files with 604 additions and 263 deletions

View File

@@ -0,0 +1,82 @@
import { Button } from '@/components/ui/button'
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import { Loader2 } from 'lucide-react'
interface CreateExtractionDialogProps {
open: boolean
onOpenChange: (open: boolean) => void
loading: boolean
url: string
onUrlChange: (url: string) => void
onSubmit: () => void
onCancel: () => void
}
export function CreateExtractionDialog({
open,
onOpenChange,
loading,
url,
onUrlChange,
onSubmit,
onCancel,
}: CreateExtractionDialogProps) {
const handleKeyDown = (e: React.KeyboardEvent) => {
if (e.key === 'Enter' && !loading) {
onSubmit()
}
}
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-[425px]">
<DialogHeader>
<DialogTitle>Create New Extraction</DialogTitle>
<DialogDescription>
Extract audio from YouTube, SoundCloud, Vimeo, TikTok, Twitter,
Instagram, and many other platforms.
</DialogDescription>
</DialogHeader>
<div className="space-y-4">
<div>
<Label htmlFor="url">URL</Label>
<Input
id="url"
placeholder="https://www.youtube.com/watch?v=..."
value={url}
onChange={e => onUrlChange(e.target.value)}
onKeyDown={handleKeyDown}
/>
<p className="text-sm text-muted-foreground mt-1">
Paste a link to extract audio from the media
</p>
</div>
</div>
<DialogFooter>
<Button variant="outline" onClick={onCancel} disabled={loading}>
Cancel
</Button>
<Button onClick={onSubmit} disabled={loading || !url.trim()}>
{loading ? (
<>
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
Creating...
</>
) : (
'Create Extraction'
)}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}

View File

@@ -0,0 +1,157 @@
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/select'
import type { ExtractionSortField, ExtractionSortOrder, ExtractionStatus } from '@/lib/api/services/extractions'
import { Filter, Plus, RefreshCw, Search, SortAsc, SortDesc, X } from 'lucide-react'
interface ExtractionsHeaderProps {
searchQuery: string
onSearchChange: (query: string) => void
sortBy: ExtractionSortField
onSortByChange: (sortBy: ExtractionSortField) => void
sortOrder: ExtractionSortOrder
onSortOrderChange: (order: ExtractionSortOrder) => void
statusFilter: ExtractionStatus | 'all'
onStatusFilterChange: (status: ExtractionStatus | 'all') => void
onRefresh: () => void
onCreateClick: () => void
loading: boolean
error: string | null
extractionCount: number
}
export function ExtractionsHeader({
searchQuery,
onSearchChange,
sortBy,
onSortByChange,
sortOrder,
onSortOrderChange,
statusFilter,
onStatusFilterChange,
onRefresh,
onCreateClick,
loading,
error,
extractionCount,
}: ExtractionsHeaderProps) {
return (
<>
{/* Header */}
<div className="flex items-center justify-between mb-6">
<div>
<h1 className="text-2xl font-bold">Audio Extractions</h1>
<p className="text-muted-foreground">
Extract audio from YouTube, SoundCloud, and other platforms
</p>
</div>
<div className="flex items-center gap-4">
{!loading && !error && (
<div className="text-sm text-muted-foreground">
{statusFilter !== 'all'
? `${extractionCount} ${statusFilter} extraction${extractionCount !== 1 ? 's' : ''}`
: `${extractionCount} extraction${extractionCount !== 1 ? 's' : ''}`
}
</div>
)}
<Button onClick={onCreateClick}>
<Plus className="h-4 w-4 mr-2" />
Add Extraction
</Button>
</div>
</div>
{/* Search and Sort Controls */}
<div className="flex flex-col sm:flex-row gap-4 mb-6">
<div className="flex-1">
<div className="relative">
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground" />
<Input
placeholder="Search extractions..."
value={searchQuery}
onChange={e => onSearchChange(e.target.value)}
className="pl-9 pr-9"
/>
{searchQuery && (
<Button
variant="ghost"
size="sm"
onClick={() => onSearchChange('')}
className="absolute right-1 top-1/2 transform -translate-y-1/2 h-7 w-7 p-0 hover:bg-muted"
title="Clear search"
>
<X className="h-3 w-3" />
</Button>
)}
</div>
</div>
<div className="flex gap-2">
<Select
value={sortBy}
onValueChange={value => onSortByChange(value as ExtractionSortField)}
>
<SelectTrigger className="w-[180px]">
<SelectValue placeholder="Sort by" />
</SelectTrigger>
<SelectContent>
<SelectItem value="title">Title</SelectItem>
<SelectItem value="status">Status</SelectItem>
<SelectItem value="service">Service</SelectItem>
<SelectItem value="created_at">Created Date</SelectItem>
<SelectItem value="updated_at">Updated Date</SelectItem>
</SelectContent>
</Select>
<Button
variant="outline"
size="icon"
onClick={() => onSortOrderChange(sortOrder === 'asc' ? 'desc' : 'asc')}
title={sortOrder === 'asc' ? 'Sort ascending' : 'Sort descending'}
>
{sortOrder === 'asc' ? (
<SortAsc className="h-4 w-4" />
) : (
<SortDesc className="h-4 w-4" />
)}
</Button>
<Select
value={statusFilter}
onValueChange={value => onStatusFilterChange(value as ExtractionStatus | 'all')}
>
<SelectTrigger className="w-[120px]">
<Filter className="h-4 w-4 mr-2" />
<SelectValue placeholder="Status" />
</SelectTrigger>
<SelectContent>
<SelectItem value="all">All Status</SelectItem>
<SelectItem value="pending">Pending</SelectItem>
<SelectItem value="processing">Processing</SelectItem>
<SelectItem value="completed">Completed</SelectItem>
<SelectItem value="failed">Failed</SelectItem>
</SelectContent>
</Select>
<Button
variant="outline"
size="icon"
onClick={onRefresh}
disabled={loading}
title="Refresh extractions"
>
<RefreshCw
className={`h-4 w-4 ${loading ? 'animate-spin' : ''}`}
/>
</Button>
</div>
</div>
</>
)
}

View File

@@ -0,0 +1,67 @@
import { Skeleton } from '@/components/ui/skeleton'
import { AlertCircle, Download } from 'lucide-react'
import type { ExtractionStatus } from '@/lib/api/services/extractions'
interface ExtractionsLoadingProps {
count?: number
}
export function ExtractionsLoading({ count = 5 }: ExtractionsLoadingProps) {
return (
<div className="space-y-3">
<Skeleton className="h-12 w-full" />
{Array.from({ length: count }).map((_, i) => (
<Skeleton key={i} className="h-16 w-full" />
))}
</div>
)
}
interface ExtractionsErrorProps {
error: string
onRetry: () => void
}
export function ExtractionsError({ error, onRetry }: ExtractionsErrorProps) {
return (
<div className="flex flex-col items-center justify-center py-12 text-center">
<AlertCircle className="h-12 w-12 text-muted-foreground mb-4" />
<h3 className="text-lg font-semibold mb-2">Failed to load extractions</h3>
<p className="text-muted-foreground mb-4">{error}</p>
<button
onClick={onRetry}
className="text-primary hover:underline"
>
Try again
</button>
</div>
)
}
interface ExtractionsEmptyProps {
searchQuery: string
statusFilter?: ExtractionStatus | 'all'
}
export function ExtractionsEmpty({ searchQuery, statusFilter = 'all' }: ExtractionsEmptyProps) {
const isFiltered = searchQuery || statusFilter !== 'all'
return (
<div className="flex flex-col items-center justify-center py-12 text-center">
<div className="h-12 w-12 rounded-full bg-muted flex items-center justify-center mb-4">
<Download className="h-6 w-6 text-muted-foreground" />
</div>
<h3 className="text-lg font-semibold mb-2">
{isFiltered ? 'No extractions found' : 'No extractions yet'}
</h3>
<p className="text-muted-foreground">
{isFiltered
? statusFilter !== 'all'
? `No ${statusFilter} extractions match your search criteria.`
: 'No extractions match your search criteria.'
: 'Start by adding a URL to extract audio from your favorite platforms'
}
</p>
</div>
)
}

View File

@@ -0,0 +1,126 @@
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import { TableCell, TableRow } from '@/components/ui/table'
import type { ExtractionInfo } from '@/lib/api/services/extractions'
import { formatDateDistanceToNow } from '@/utils/format-date'
import {
AlertCircle,
Calendar,
CheckCircle,
Clock,
ExternalLink,
Loader2
} from 'lucide-react'
interface ExtractionsRowProps {
extraction: ExtractionInfo
}
export function ExtractionsRow({ extraction }: ExtractionsRowProps) {
const getStatusBadge = (status: ExtractionInfo['status']) => {
switch (status) {
case 'pending':
return (
<Badge variant="secondary" className="gap-1">
<Clock className="h-3 w-3" />
Pending
</Badge>
)
case 'processing':
return (
<Badge variant="outline" className="gap-1">
<Loader2 className="h-3 w-3 animate-spin" />
Processing
</Badge>
)
case 'completed':
return (
<Badge variant="default" className="gap-1">
<CheckCircle className="h-3 w-3" />
Completed
</Badge>
)
case 'failed':
return (
<Badge variant="destructive" className="gap-1">
<AlertCircle className="h-3 w-3" />
Failed
</Badge>
)
}
}
const getServiceBadge = (service: string | undefined) => {
if (!service) return <span className="text-muted-foreground">-</span>
const serviceColors: Record<string, string> = {
youtube: 'bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-300',
soundcloud: 'bg-orange-100 text-orange-800 dark:bg-orange-900 dark:text-orange-300',
vimeo: 'bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300',
tiktok: 'bg-pink-100 text-pink-800 dark:bg-pink-900 dark:text-pink-300',
twitter: 'bg-sky-100 text-sky-800 dark:bg-sky-900 dark:text-sky-300',
instagram: 'bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-300',
}
const colorClass =
serviceColors[service.toLowerCase()] ||
'bg-gray-100 text-gray-800 dark:bg-gray-900 dark:text-gray-300'
return (
<Badge variant="outline" className={colorClass}>
{service.toUpperCase()}
</Badge>
)
}
return (
<TableRow className="hover:bg-muted/50">
<TableCell>
<div className="min-w-0">
<div className="font-medium truncate">
{extraction.title || 'Extracting...'}
</div>
<div className="text-sm text-muted-foreground truncate max-w-64">
{extraction.url}
</div>
</div>
</TableCell>
<TableCell className="text-center">
{getServiceBadge(extraction.service)}
</TableCell>
<TableCell>
<div className="space-y-1">
{getStatusBadge(extraction.status)}
{extraction.error && (
<div
className="text-xs text-destructive max-w-48 truncate"
title={extraction.error}
>
{extraction.error}
</div>
)}
</div>
</TableCell>
<TableCell>
<div className="flex items-center gap-1 text-sm text-muted-foreground">
<Calendar className="h-3 w-3" />
{formatDateDistanceToNow(extraction.created_at)}
</div>
</TableCell>
<TableCell className="text-center">
<div className="flex items-center justify-center gap-1">
<Button variant="ghost" size="sm" asChild>
<a
href={extraction.url}
target="_blank"
rel="noopener noreferrer"
title="Open original URL"
>
<ExternalLink className="h-4 w-4" />
</a>
</Button>
</div>
</TableCell>
</TableRow>
)
}

View File

@@ -0,0 +1,39 @@
import { ExtractionsRow } from '@/components/extractions/ExtractionsRow'
import {
Table,
TableBody,
TableHead,
TableHeader,
TableRow,
} from '@/components/ui/table'
import type { ExtractionInfo } from '@/lib/api/services/extractions'
interface ExtractionsTableProps {
extractions: ExtractionInfo[]
}
export function ExtractionsTable({ extractions }: ExtractionsTableProps) {
return (
<div className="rounded-md border">
<Table>
<TableHeader>
<TableRow>
<TableHead>Title</TableHead>
<TableHead className="text-center">Service</TableHead>
<TableHead>Status</TableHead>
<TableHead>Created</TableHead>
<TableHead className="text-center">Actions</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{extractions.map(extraction => (
<ExtractionsRow
key={extraction.id}
extraction={extraction}
/>
))}
</TableBody>
</Table>
</div>
)
}