From 8e3c97f365768c5d6a355aec23f2abcdd1843df3 Mon Sep 17 00:00:00 2001
From: albin-karlsson <55614148+albin-karlsson@users.noreply.github.com>
Date: Thu, 25 Apr 2024 16:59:08 +0200
Subject: [PATCH] Add functionality for raising hand
---
.../src/components/ConversationControls.jsx | 11 +++++-
client/src/components/Council.jsx | 23 +++++++++++-
client/src/components/HumanInput.jsx | 15 ++++++++
client/src/components/Output.jsx | 36 +++++++++++++++++--
client/src/components/TextOutput.jsx | 11 ++++--
5 files changed, 89 insertions(+), 7 deletions(-)
create mode 100644 client/src/components/HumanInput.jsx
diff --git a/client/src/components/ConversationControls.jsx b/client/src/components/ConversationControls.jsx
index e7afbf9..1d157d3 100644
--- a/client/src/components/ConversationControls.jsx
+++ b/client/src/components/ConversationControls.jsx
@@ -1,10 +1,19 @@
import React from "react";
-function ConversationControls({ isPaused, onPauseResume, onSkipForward }) {
+function ConversationControls({
+ isPaused,
+ onPauseResume,
+ onSkipForward,
+ onRaiseHandOrNevermind,
+ isRaisedHand,
+}) {
return (
{foods.map((food, index) => (
diff --git a/client/src/components/HumanInput.jsx b/client/src/components/HumanInput.jsx
new file mode 100644
index 0000000..4763592
--- /dev/null
+++ b/client/src/components/HumanInput.jsx
@@ -0,0 +1,15 @@
+import React from "react";
+
+function HumanInput() {
+ return (
+
+
+
+ );
+}
+
+export default HumanInput;
diff --git a/client/src/components/Output.jsx b/client/src/components/Output.jsx
index bb443f6..caac28b 100644
--- a/client/src/components/Output.jsx
+++ b/client/src/components/Output.jsx
@@ -2,14 +2,44 @@ import React, { useState, useEffect } from "react";
import TextOutput from "./TextOutput";
import AudioOutput from "./AudioOutput";
-function Output({ textMessages, audioMessages, isActiveOverlay }) {
+function Output({
+ textMessages,
+ audioMessages,
+ isActiveOverlay,
+ isRaisedHand,
+ onIsReady,
+}) {
const [currentMessageIndex, setCurrentMessageIndex] = useState(0);
const [currentTextMessage, setCurrentTextMessage] = useState(null);
const [currentAudioMessage, setCurrentAudioMessage] = useState(null);
+ // useEffect for raising hand or nevermind when a food is talking
+ useEffect(() => {
+ if (!isRaisedHand) {
+ tryFindTextAndAudio();
+ } else {
+ console.log("Human interjection time!");
+ }
+ }, [currentMessageIndex]);
+
+ // useEffect for nevermind when adding new input
+ useEffect(() => {
+ if (
+ !isRaisedHand &&
+ currentTextMessage === null &&
+ currentAudioMessage === null
+ ) {
+ tryFindTextAndAudio();
+ }
+ }, [isRaisedHand]);
+
useEffect(() => {
tryFindTextAndAudio();
- }, [currentMessageIndex, textMessages, audioMessages]);
+ }, [textMessages, audioMessages]);
+
+ useEffect(() => {
+ console.log("Hand raised: ", isRaisedHand);
+ }, [isRaisedHand]);
function tryFindTextAndAudio() {
const textMessage = textMessages[currentMessageIndex];
@@ -25,6 +55,8 @@ function Output({ textMessages, audioMessages, isActiveOverlay }) {
) {
console.log("Both found!");
+ onIsReady();
+
setCurrentTextMessage((prev) => textMessage);
setCurrentAudioMessage((prev) => audioMessage);
}
diff --git a/client/src/components/TextOutput.jsx b/client/src/components/TextOutput.jsx
index 4563ff2..f5632f8 100644
--- a/client/src/components/TextOutput.jsx
+++ b/client/src/components/TextOutput.jsx
@@ -1,6 +1,6 @@
import React, { useState, useEffect } from "react";
-function TextOutput({ currentTextMessage }) {
+function TextOutput({ currentTextMessage, currentAudioMessage }) {
const [currentSnippetIndex, setCurrentSnippetIndex] = useState(0);
const [currentSnippet, setCurrentSnippet] = useState("");
@@ -10,7 +10,7 @@ function TextOutput({ currentTextMessage }) {
}, [currentTextMessage]);
useEffect(() => {
- if (currentTextMessage && currentTextMessage.text) {
+ if (currentTextMessage && currentTextMessage.text && currentAudioMessage) {
const text = currentTextMessage.text;
// Split the text into sentences, ignoring periods followed by a number
const sentences = text.split(/(?<=[.!?])(?=\s+(?![0-9]))/);
@@ -23,7 +23,12 @@ function TextOutput({ currentTextMessage }) {
}, calculateDisplayTime(currentSnippet) * 1000);
return () => clearInterval(interval);
}
- }, [currentTextMessage, currentSnippetIndex]);
+ }, [
+ currentTextMessage,
+ currentSnippetIndex,
+ currentAudioMessage,
+ currentSnippet,
+ ]);
// Calculate the display time based on the number of characters in the snippet
const calculateDisplayTime = (text) => {