import { useEffect, useState } from 'react'; import { useGame } from '../context/GameContext'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faTrophy, faHome, faRedo, faChartLine } from '@fortawesome/free-solid-svg-icons'; import YouTubeEmbed from './YouTubeEmbed'; const ResultsScreen = () => { const { lobby, currentPlayer, leaveLobby } = useGame(); const [showBattleHistory, setShowBattleHistory] = useState(false); const [confetti, setConfetti] = useState(true); // Winner information const winner = lobby?.finalWinner; const winnerVideoId = getYouTubeId(winner?.youtubeLink); // Confetti effect for winner celebration useEffect(() => { if (confetti) { // Create confetti animation const createConfetti = () => { const confettiContainer = document.createElement('div'); confettiContainer.className = 'confetti'; // Random position and color const left = Math.random() * 100; const colors = ['#f94144', '#f3722c', '#f8961e', '#f9c74f', '#90be6d', '#43aa8b', '#577590']; const color = colors[Math.floor(Math.random() * colors.length)]; confettiContainer.style.left = `${left}%`; confettiContainer.style.backgroundColor = color; document.querySelector('.results-screen').appendChild(confettiContainer); // Remove after animation setTimeout(() => { confettiContainer.remove(); }, 5000); }; // Create multiple confetti pieces const confettiInterval = setInterval(() => { for (let i = 0; i < 3; i++) { createConfetti(); } }, 300); // Stop confetti after some time setTimeout(() => { clearInterval(confettiInterval); setConfetti(false); }, 10000); return () => { clearInterval(confettiInterval); }; } }, [confetti]); // Get YouTube video ID from link function getYouTubeId(url) { if (!url) return null; const regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/; const match = url.match(regExp); return (match && match[2].length === 11) ? match[2] : null; } if (!winner) { return (
Submitted by: {winner.submittedByName}
{battle.song1.artist}
{battle.song1Votes} votes{battle.song2.artist}
{battle.song2Votes} votes