diff --git a/src/components/CardModal.tsx b/src/components/CardModal.tsx index 4289e11..3a8fa89 100644 --- a/src/components/CardModal.tsx +++ b/src/components/CardModal.tsx @@ -330,7 +330,15 @@ const CardModal: React.FC = ({ style={{ color: "black" }} onClick={() => { if (currentIndex > 0) { + if (currentIndex < audios.length) { + const currentAudio = audios[currentIndex]; + if (currentAudio) { + currentAudio.pause(); + currentAudio.currentTime = 0; // Reset audio to start + } + } setCurrentIndex(currentIndex - 1); + setIsPlaying(true); } }} > @@ -355,7 +363,15 @@ const CardModal: React.FC = ({ style={{ color: "black" }} onClick={() => { if (currentIndex < sentenceRefs.current.length - 1) { + if (currentIndex < audios.length) { + const currentAudio = audios[currentIndex]; + if (currentAudio) { + currentAudio.pause(); + currentAudio.currentTime = 0; // Reset audio to start + } + } setCurrentIndex(currentIndex + 1); + setIsPlaying(true); } }} >