Spaces:
Sleeping
Sleeping
File size: 3,529 Bytes
7afe4cc 54bd0d7 7afe4cc 54bd0d7 7afe4cc 5a1477e d3c2bc1 5a1477e d3c2bc1 5a1477e 7afe4cc 54bd0d7 7afe4cc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
'use client';
import { FC, useEffect, useState } from 'react';
import Image from 'next/image';
interface CourtSceneProps {
setNextScene: () => void;
currentQuestion: string;
reaction: string;
round: number;
}
const CourtScene: FC<CourtSceneProps> = ({
setNextScene,
currentQuestion,
reaction,
round
}) => {
const [showFirstImage, setShowFirstImage] = useState(true);
useEffect(() => {
const playAudio = async () => {
try {
if (!currentQuestion) return;
const response = await fetch('/api/voice', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
language: 'en', // You may want to make this configurable
text: reaction !== '' ? reaction + currentQuestion : currentQuestion,
role: 'judge'
})
});
if (!response.ok) {
throw new Error('Failed to generate audio');
}
const audioBlob = await response.blob();
const audioUrl = URL.createObjectURL(audioBlob);
const audio = new Audio(audioUrl);
audio.play();
} catch (error) {
console.error('Error playing audio:', error);
}
};
if (currentQuestion) {
playAudio();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [currentQuestion]);
useEffect(() => {
const timer = setTimeout(() => {
setShowFirstImage(false);
}, 2000);
return () => clearTimeout(timer);
}, []);
return (
<div className="relative w-screen h-screen">
{/* Image de fond statique */}
<Image
src="https://ik.imagekit.io/z0tzxea0wgx/MistralGameJam/DD_judge2_FoYazvSFmu.png?updatedAt=1737835883172"
alt="Background"
fill
className="object-cover"
priority
/>
{/* Image superposée avec transition */}
<div className={`absolute inset-0 transition-opacity duration-500 ${showFirstImage ? 'opacity-100' : 'opacity-0'}`}>
<Image
src="https://ik.imagekit.io/z0tzxea0wgx/MistralGameJam/DD_judge1_Bn04jNl_E.png?updatedAt=1737835883169"
alt="Overlay"
fill
className="object-cover"
priority
/>
</div>
{/* Rectangle noir en bas */}
<div className="absolute bottom-0 left-1/2 transform -translate-x-1/2 w-[80%] bg-black/60 border border-black border-8 mb-[8vh] p-6">
<div className="text-white roboto-slab">
<p className="text-4xl mb-4">
{reaction !== '' && round !== 1 ? reaction.replace(/\?/g, '') : ''} <br />
{currentQuestion ? currentQuestion : '...'}
</p>
{/* Flèche à droite */}
<div className="flex justify-end">
<button
onClick={setNextScene}
className="text-white hover:text-blue-400 transition-colors"
aria-label="Continuer"
>
<svg
xmlns="http://www.w3.org/2000/svg"
className="h-12 w-12"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M14 5l7 7m0 0l-7 7m7-7H3"
/>
</svg>
</button>
</div>
</div>
</div>
</div>
);
};
export default CourtScene; |