Skip to content

Commit

Permalink
Fix bug with audio playing if adding new input
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-karlsson committed Apr 25, 2024
1 parent 16a8ef9 commit ce22340
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
2 changes: 2 additions & 0 deletions client/src/components/AudioOutput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ function AudioOutput({ currentAudioMessage, onFinishedPlaying, stopAudio }) {

useEffect(() => {
audioRef.current && audioRef.current.pause();

console.log("Stopping audio...");
}, [stopAudio]);

useEffect(() => {
Expand Down
2 changes: 2 additions & 0 deletions client/src/components/ConversationControls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ function ConversationControls({
onPauseResume,
onSkipForward,
onRaiseHandOrNevermind,
onSubmit,
isRaisedHand,
humanInterjection,
}) {
Expand All @@ -14,6 +15,7 @@ function ConversationControls({
{!humanInterjection && (
<button onClick={onSkipForward}>Skip forward</button>
)}
{humanInterjection && <button onClick={onSubmit}>Submit</button>}
<button onClick={onRaiseHandOrNevermind}>
{isRaisedHand ? "Nevermind" : "Raise hand"}
</button>
Expand Down
5 changes: 5 additions & 0 deletions client/src/components/Council.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ function Council({ options }) {
setSkipForward(!skipForward);
}

function handleOnSubmit() {
console.log("Submitting new issue");
}

function handleOnRaiseHandOrNevermind() {
setIsRaisedHand((prev) => !prev);
}
Expand Down Expand Up @@ -120,6 +124,7 @@ function Council({ options }) {
<ConversationControls
onSkipForward={handleOnSkipForward}
onRaiseHandOrNevermind={handleOnRaiseHandOrNevermind}
onSubmit={handleOnSubmit}
isRaisedHand={isRaisedHand}
humanInterjection={humanInterjection}
/>
Expand Down
22 changes: 12 additions & 10 deletions client/src/components/Output.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ function Output({

useEffect(() => {
if (currentTextMessage && currentAudioMessage) {
console.log("Skipping forward");
proceedToNextMessage();
}
}, [skipForward]);

// useEffect for checking for raised hand when changing message index (inbetween food talking)
useEffect(() => {
if (!isRaisedHand) {
tryFindTextAndAudio();
} else {
// Check to see if the hand is raised
if (isRaisedHand) {
setStopAudio(!stopAudio);
onHumanInterjection(true);
} else {
findTextAndAudio();
}
}, [currentMessageIndex]);

Expand All @@ -42,15 +42,15 @@ function Output({
currentAudioMessage === null
) {
onHumanInterjection(false);
tryFindTextAndAudio();
findTextAndAudio();
}
}, [isRaisedHand]);

useEffect(() => {
tryFindTextAndAudio();
findTextAndAudio();
}, [textMessages, audioMessages]);

function tryFindTextAndAudio() {
function findTextAndAudio() {
const textMessage = textMessages[currentMessageIndex];
const audioMessage = audioMessages.find(
(a) => a.message_index === currentMessageIndex
Expand All @@ -60,10 +60,12 @@ function Output({
textMessage &&
audioMessage &&
!currentTextMessage &&
!currentAudioMessage
!currentAudioMessage &&
!isRaisedHand
) {
console.log("Both found!");

// Set isReady to true in the parent component to render the controls (for skipping forward et.c.)
onIsReady();

setCurrentTextMessage((prev) => textMessage);
Expand All @@ -72,8 +74,8 @@ function Output({
}

function proceedToNextMessage() {
setCurrentTextMessage((prev) => null);
setCurrentAudioMessage((prev) => null);
setCurrentTextMessage(() => null);
setCurrentAudioMessage(() => null);
setCurrentMessageIndex((prev) => prev + 1);
}

Expand Down

0 comments on commit ce22340

Please sign in to comment.