Skip to content

Commit

Permalink
Merge pull request #13 from Nonhuman-Nonsense/albin
Browse files Browse the repository at this point in the history
Hide conversation controls when last message is playing
  • Loading branch information
albin-karlsson authored Apr 26, 2024
2 parents 10aa2fd + 60a598b commit e778e4c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
4 changes: 2 additions & 2 deletions client/src/components/Council.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ function Council({ options }) {
setInterjectionReplyRecieved(false);
}

function handleOnIsReady() {
setIsReady(true);
function handleOnIsReady(value) {
setIsReady(value);
}

function handleOnSkipForward() {
Expand Down
41 changes: 21 additions & 20 deletions client/src/components/Output.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ function Output({

useEffect(() => {
if (interjectionReplyRecieved) {
console.log(
"Should be about dancing: ",
textMessages[textMessages.length - 1].text
);

setCurrentTextMessage(textMessages[textMessages.length - 1]);
setCurrentAudioMessage(audioMessages[audioMessages.length - 1]);

Expand All @@ -44,13 +39,26 @@ function Output({

// useEffect for checking for raised hand when changing message index (inbetween food talking)
useEffect(() => {
// Check to see if the hand is raised
if (isRaisedHand) {
setStopAudio(!stopAudio);
onHumanInterjection(true);
} else {
findTextAndAudio();
const maxIndex = textMessages.length - totalInterjections - 1;

if (
textMessages.length > 0 &&
audioMessages.length > 0 &&
currentMessageIndex >= maxIndex
) {
// Max index reached

onIsReady(false);
}

if (currentMessageIndex)
if (isRaisedHand) {
// Check to see if the hand is raised
setStopAudio(!stopAudio);
onHumanInterjection(true);
} else {
findTextAndAudio();
}
}, [currentMessageIndex]);

// useEffect for nevermind when adding new input
Expand All @@ -67,12 +75,6 @@ function Output({
}, [isRaisedHand]);

useEffect(() => {
console.log("Amount of text messages :", textMessages.length);
console.log("Amount of voice messages :", audioMessages.length);

console.log("Text messages:", textMessages);
console.log("Audio messages:", audioMessages);

findTextAndAudio();
}, [textMessages, audioMessages]);

Expand All @@ -88,10 +90,8 @@ function Output({
!isRaisedHand &&
!interjectionReplyRecieved
) {
console.log("Both found!");

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

setCurrentTextMessage(() => textMessage);
setCurrentAudioMessage(() => audioMessage);
Expand All @@ -108,6 +108,7 @@ function Output({
setCurrentMessageIndex((prev) => {
// Calculate the maximum index allowed based on the length of the messages and total interjections
const maxIndex = textMessages.length - totalInterjections - 1;

// Increment the index if it's within the bounds, otherwise keep it at the maximum allowed index
return prev < maxIndex ? prev + 1 : maxIndex;
});
Expand Down

0 comments on commit e778e4c

Please sign in to comment.