Spaces:
Sleeping
Sleeping
File size: 5,528 Bytes
7afe4cc 54bd0d7 7afe4cc 321ba52 7afe4cc 321ba52 7afe4cc 54bd0d7 7afe4cc 54bd0d7 7afe4cc 54bd0d7 1d105b9 321ba52 1d105b9 5a1477e 1d105b9 321ba52 1d105b9 7afe4cc 54bd0d7 7afe4cc 54bd0d7 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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
'use client';
import { FC, useState, useEffect, Dispatch, SetStateAction } from 'react';
import Image from 'next/image';
interface Message {
content: string;
role: 'lawyer' | 'judge';
requiredWords?: string[];
}
interface Chat {
messages: Message[];
}
interface LawyerSceneProps {
language: 'fr' | 'en' | 'es';
chat: Chat;
setNextScene: () => void;
currentQuestion: string;
round: number;
setRound: Dispatch<SetStateAction<number>>;
}
const LawyerScene: FC<LawyerSceneProps> = ({
language,
chat,
setNextScene,
currentQuestion,
round,
setRound,
}) => {
const [visible, setVisible] = useState(false);
const [buttonEnabled, setButtonEnabled] = useState(false);
const [countdown, setCountdown] = useState(3);
const [question, setQuestion] = useState('');
const [answer, setAnswer] = useState('');
useEffect(() => {
const lastJudgeMessage = chat.messages.filter((message: Message) => message.role === 'judge').slice(-1)[0]?.content;
const lastLawyerMessage = chat.messages.filter((message: Message) => message.role === 'lawyer').slice(-1)[0]?.content;
setQuestion(lastJudgeMessage || '');
setAnswer(lastLawyerMessage || '');
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []); // Only run once on mount
useEffect(() => {
const playAudio = async () => {
try {
const response = await fetch('/api/voice', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
language,
text: answer,
role: 'lawyer'
})
});
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 (answer !== '') {
playAudio();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [answer])
useEffect(() => {
setVisible(true);
setRound(round + 1);
const timer = setInterval(() => {
setCountdown((prev) => {
if (prev <= 1) {
setButtonEnabled(true);
clearInterval(timer);
return 0;
}
return prev - 1;
});
}, 1000);
return () => clearInterval(timer);
}, []);
return (
<div className="relative w-screen h-screen">
{/* Image de fond */}
<Image
src="https://ik.imagekit.io/z0tzxea0wgx/MistralGameJam/DD_attorney1_k5DWtEzcV.png?updatedAt=1737835883169"
alt="Background"
fill
className="object-cover"
priority
/>
{/* Contenu avec overlay noir */}
<div className="absolute inset-0">
<div className="flex flex-col items-center justify-end h-full p-8">
<div className={`flex flex-col items-center justify-center space-y-8 transition-opacity duration-1000 ${
visible ? 'opacity-100' : 'opacity-0'
}`}>
{/* Question du juge */}
<div className="bg-black/60 border border-black border-8 p-6 mb-8 w-[80%]">
<h2 className="text-2xl font-bold mb-4 roboto-slab text-white">
{language === 'fr' ? 'Question du juge' : language === 'en' ? 'Judge\'s question' : 'Pregunta del juez'}:
</h2>
<p className="text-xl text-white roboto-slab">
{question}
</p>
</div>
{/* Réponse de l'avocat avec flèche */}
<div className="relative bg-black/60 border border-black border-8 p-6 mb-8 w-[80%]">
<h2 className="text-2xl font-bold mb-4 roboto-slab text-white">
{language === 'fr' ? 'Votre réponse' : language === 'en' ? 'Your answer' : 'Tu respuesta'}:
</h2>
<p className="text-xl text-white roboto-slab whitespace-pre-wrap mb-8">
{answer}
</p>
{/* Flèche à droite */}
<div className="absolute bottom-5 right-5">
<button
onClick={setNextScene}
disabled={!buttonEnabled || (currentQuestion === "" && round < 3)}
className={`text-white transition-colors ${
buttonEnabled && (currentQuestion !== "" || round === 3)
? 'hover:text-blue-400 cursor-pointer'
: 'text-gray-600 cursor-not-allowed'
}`}
aria-label="Continuer"
>
{!buttonEnabled ? (
<span className="text-2xl">{countdown}s</span>
) : (
<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>
</div>
</div>
);
};
export default LawyerScene; |