feat: enhance PlaylistEditPage with edit mode functionality; add cancel and save options for playlist details
This commit is contained in:
@@ -10,7 +10,7 @@ import { Label } from '@/components/ui/label'
|
|||||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||||
import { Badge } from '@/components/ui/badge'
|
import { Badge } from '@/components/ui/badge'
|
||||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'
|
||||||
import { AlertCircle, Save, ArrowLeft, Music, Clock, ChevronUp, ChevronDown, GripVertical, Trash2, RefreshCw } from 'lucide-react'
|
import { AlertCircle, Save, Music, Clock, ChevronUp, ChevronDown, Trash2, RefreshCw, Edit, X, ArrowLeft } from 'lucide-react'
|
||||||
import { toast } from 'sonner'
|
import { toast } from 'sonner'
|
||||||
import { formatDuration } from '@/utils/format-duration'
|
import { formatDuration } from '@/utils/format-duration'
|
||||||
|
|
||||||
@@ -25,6 +25,7 @@ export function PlaylistEditPage() {
|
|||||||
const [soundsLoading, setSoundsLoading] = useState(true)
|
const [soundsLoading, setSoundsLoading] = useState(true)
|
||||||
const [error, setError] = useState<string | null>(null)
|
const [error, setError] = useState<string | null>(null)
|
||||||
const [saving, setSaving] = useState(false)
|
const [saving, setSaving] = useState(false)
|
||||||
|
const [isEditMode, setIsEditMode] = useState(false)
|
||||||
|
|
||||||
// Form state
|
// Form state
|
||||||
const [formData, setFormData] = useState({
|
const [formData, setFormData] = useState({
|
||||||
@@ -109,8 +110,9 @@ export function PlaylistEditPage() {
|
|||||||
|
|
||||||
toast.success('Playlist updated successfully')
|
toast.success('Playlist updated successfully')
|
||||||
|
|
||||||
// Refresh playlist data
|
// Refresh playlist data and exit edit mode
|
||||||
await fetchPlaylist()
|
await fetchPlaylist()
|
||||||
|
setIsEditMode(false)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMessage = err instanceof Error ? err.message : 'Failed to update playlist'
|
const errorMessage = err instanceof Error ? err.message : 'Failed to update playlist'
|
||||||
toast.error(errorMessage)
|
toast.error(errorMessage)
|
||||||
@@ -119,6 +121,18 @@ export function PlaylistEditPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleCancelEdit = () => {
|
||||||
|
if (playlist) {
|
||||||
|
// Reset form data to original values
|
||||||
|
setFormData({
|
||||||
|
name: playlist.name,
|
||||||
|
description: playlist.description || '',
|
||||||
|
genre: playlist.genre || ''
|
||||||
|
})
|
||||||
|
setIsEditMode(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleSetCurrent = async () => {
|
const handleSetCurrent = async () => {
|
||||||
if (!playlist) return
|
if (!playlist) return
|
||||||
|
|
||||||
@@ -251,16 +265,24 @@ export function PlaylistEditPage() {
|
|||||||
<div className="flex-1 rounded-xl bg-muted/50 p-4">
|
<div className="flex-1 rounded-xl bg-muted/50 p-4">
|
||||||
<div className="flex items-center justify-between mb-6">
|
<div className="flex items-center justify-between mb-6">
|
||||||
<div className="flex items-center gap-4">
|
<div className="flex items-center gap-4">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => navigate('/playlists')}
|
||||||
|
>
|
||||||
|
<ArrowLeft className="h-4 w-4 mr-2" />
|
||||||
|
Back
|
||||||
|
</Button>
|
||||||
<div>
|
<div>
|
||||||
<h1 className="text-2xl font-bold">Edit Playlist</h1>
|
<h1 className="text-2xl font-bold">{playlist.name}</h1>
|
||||||
<p className="text-muted-foreground">
|
<p className="text-muted-foreground">
|
||||||
Modify playlist details and manage sounds
|
View and manage your playlist
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
{!playlist.is_current && (
|
{!playlist.is_current && !isEditMode && (
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
onClick={handleSetCurrent}
|
onClick={handleSetCurrent}
|
||||||
@@ -275,7 +297,7 @@ export function PlaylistEditPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
||||||
{/* Playlist Details Form */}
|
{/* Playlist Details */}
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle className="flex items-center gap-2">
|
<CardTitle className="flex items-center gap-2">
|
||||||
@@ -284,45 +306,96 @@ export function PlaylistEditPage() {
|
|||||||
</CardTitle>
|
</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="space-y-4">
|
<CardContent className="space-y-4">
|
||||||
<div className="space-y-2">
|
{isEditMode ? (
|
||||||
<Label htmlFor="name">Name *</Label>
|
<>
|
||||||
<Input
|
<div className="space-y-2">
|
||||||
id="name"
|
<Label htmlFor="name">Name *</Label>
|
||||||
value={formData.name}
|
<Input
|
||||||
onChange={(e) => handleInputChange('name', e.target.value)}
|
id="name"
|
||||||
placeholder="Playlist name"
|
value={formData.name}
|
||||||
/>
|
onChange={(e) => handleInputChange('name', e.target.value)}
|
||||||
</div>
|
placeholder="Playlist name"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="description">Description</Label>
|
<Label htmlFor="description">Description</Label>
|
||||||
<Textarea
|
<Textarea
|
||||||
id="description"
|
id="description"
|
||||||
value={formData.description}
|
value={formData.description}
|
||||||
onChange={(e) => handleInputChange('description', e.target.value)}
|
onChange={(e) => handleInputChange('description', e.target.value)}
|
||||||
placeholder="Playlist description"
|
placeholder="Playlist description"
|
||||||
className="min-h-[100px]"
|
className="min-h-[100px]"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="genre">Genre</Label>
|
<Label htmlFor="genre">Genre</Label>
|
||||||
<Input
|
<Input
|
||||||
id="genre"
|
id="genre"
|
||||||
value={formData.genre}
|
value={formData.genre}
|
||||||
onChange={(e) => handleInputChange('genre', e.target.value)}
|
onChange={(e) => handleInputChange('genre', e.target.value)}
|
||||||
placeholder="Electronic, Rock, Comedy, etc."
|
placeholder="Electronic, Rock, Comedy, etc."
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
</>
|
||||||
<div className="flex justify-end gap-2 pt-4">
|
) : (
|
||||||
<Button
|
<>
|
||||||
onClick={handleSave}
|
<div className="space-y-3">
|
||||||
disabled={!hasChanges || saving}
|
<div>
|
||||||
>
|
<Label className="text-sm font-medium text-muted-foreground">Name</Label>
|
||||||
<Save className="h-4 w-4 mr-2" />
|
<p className="text-lg font-semibold">{playlist.name}</p>
|
||||||
{saving ? 'Saving...' : 'Save Changes'}
|
</div>
|
||||||
</Button>
|
|
||||||
|
{playlist.description && (
|
||||||
|
<div>
|
||||||
|
<Label className="text-sm font-medium text-muted-foreground">Description</Label>
|
||||||
|
<p className="text-sm">{playlist.description}</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{playlist.genre && (
|
||||||
|
<div>
|
||||||
|
<Label className="text-sm font-medium text-muted-foreground">Genre</Label>
|
||||||
|
<Badge variant="secondary" className="mt-1">{playlist.genre}</Badge>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!playlist.description && !playlist.genre && (
|
||||||
|
<p className="text-sm text-muted-foreground italic">No additional details provided</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Edit/Save/Cancel buttons */}
|
||||||
|
<div className="pt-4 border-t">
|
||||||
|
{isEditMode ? (
|
||||||
|
<div className="flex justify-end gap-2">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
onClick={handleCancelEdit}
|
||||||
|
>
|
||||||
|
<X className="h-4 w-4 mr-2" />
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={handleSave}
|
||||||
|
disabled={!hasChanges || saving}
|
||||||
|
>
|
||||||
|
<Save className="h-4 w-4 mr-2" />
|
||||||
|
{saving ? 'Saving...' : 'Save Changes'}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<Button
|
||||||
|
onClick={() => setIsEditMode(true)}
|
||||||
|
className="w-full"
|
||||||
|
>
|
||||||
|
<Edit className="h-4 w-4 mr-2" />
|
||||||
|
Edit
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|||||||
Reference in New Issue
Block a user