import React, { useState, KeyboardEvent, useEffect } from 'react'; import { FaTimes, FaCheck } from 'react-icons/fa'; import { API, PlaylistItem, getDisplayTitle } from '../api/player'; interface RenameFavoriteModalProps { isOpen: boolean; onClose: () => void; favorite: PlaylistItem | null; } const RenameFavoriteModal: React.FC = ({ isOpen, onClose, favorite }) => { const [title, setTitle] = useState(''); const [isSaving, setIsSaving] = useState(false); useEffect(() => { if (favorite) { setTitle(getDisplayTitle(favorite)); } }, [favorite]); const handleSave = async () => { if (!favorite || !title.trim()) return; setIsSaving(true); try { await API.updateFavoriteTitle(favorite.filename, title); onClose(); } catch (error) { console.error('Failed to rename favorite:', error); } finally { setIsSaving(false); } }; const handleKeyDown = (e: KeyboardEvent) => { if (e.key === 'Enter') { handleSave(); } else if (e.key === 'Escape') { onClose(); } }; if (!isOpen || !favorite) return null; return (

Rename Favorite

{favorite.filename}
setTitle(e.target.value)} onKeyDown={handleKeyDown} placeholder="Enter new title..." className="p-2 rounded-lg border-2 border-violet-500 w-full bg-black/20 text-white" />
); }; export default RenameFavoriteModal;