import React, { useState, useEffect } from 'react'; const MusicApp = () => { const [songs, setSongs] = useState([ { id: 1, title: "Hallelujah", artist: "Leonard Cohen", year: "1984", lyrics: "Well, maybe there's a God above, but all I've ever learned from love...", description: "A beautiful song about love and spirituality" }, { id: 2, title: "Bohemian Rhapsody", artist: "Queen", year: "1975", lyrics: "Is this the real life? Is this just fantasy?", description: "Epic rock masterpiece" } ]); const [searchTerm, setSearchTerm] = useState(''); const [selectedSong, setSelectedSong] = useState(null); const [filteredSongs, setFilteredSongs] = useState(songs); // Filter songs based on search useEffect(() => { const results = songs.filter(song => song.title.toLowerCase().includes(searchTerm.toLowerCase()) || song.artist.toLowerCase().includes(searchTerm.toLowerCase()) ); setFilteredSongs(results); }, [searchTerm, songs]); const handleSearch = (e) => { setSearchTerm(e.target.value); }; const createSongImage = (song) => { const canvas = document.createElement('canvas'); canvas.width = 600; canvas.height = 400; const ctx = canvas.getContext('2d'); // Background ctx.fillStyle = '#1a202c'; ctx.fillRect(0, 0, canvas.width, canvas.height); // Title ctx.fillStyle = 'white'; ctx.font = 'bold 30px Arial'; ctx.fillText(song.title, 50, 100); // Artist and year ctx.font = '20px Arial'; ctx.fillText(`${song.artist} - ${song.year}`, 50, 140); // Lyrics snippet ctx.font = 'italic 18px Arial'; ctx.fillText(`"${song.lyrics.substring(0, 100)}..."`, 50, 200); // Convert to image and download const image = canvas.toDataURL('image/png'); const link = document.createElement('a'); link.download = `${song.title}.png`; link.href = image; link.click(); }; return (
Discover beautiful songs
{song.artist} • {song.year}
"{song.lyrics.substring(0, 80)}..."
{selectedSong.artist} • {selectedSong.year}
"{selectedSong.lyrics}"
{selectedSong.description}