Only 1 msg at a time

This commit is contained in:
YasinOnm08 2024-09-24 09:51:16 +02:00
parent b034292e64
commit b4713ea3b2

View file

@ -3,7 +3,9 @@ import React, { useEffect, useRef, useState } from "react";
import ConversationFrontend from "../components/ConversationFrontend"; import ConversationFrontend from "../components/ConversationFrontend";
import InputFrontend from "../components/InputFrontend"; import InputFrontend from "../components/InputFrontend";
import axios from "axios"; import axios from "axios";
import { log } from 'console';
let sendable = true
const InputOutputBackend: React.FC = () => { const InputOutputBackend: React.FC = () => {
type Message = { type Message = {
@ -37,8 +39,10 @@ const InputOutputBackend: React.FC = () => {
postWorkerRef.current.onmessage = (event) => { postWorkerRef.current.onmessage = (event) => {
const status = event.data.status const status = event.data.status
if (status == 200) { if (status == 200) {
sendable = true
endGetWorker() endGetWorker()
} else if (status == 500) { } else if (status == 500) {
sendable = true
if (getWorkerRef.current) { if (getWorkerRef.current) {
addMessage("assistant", "There was an Error with the AI response") addMessage("assistant", "There was an Error with the AI response")
getWorkerRef.current.postMessage("terminate") getWorkerRef.current.postMessage("terminate")
@ -109,6 +113,8 @@ const InputOutputBackend: React.FC = () => {
setMessages(previous => [...previous,{role,content}]) setMessages(previous => [...previous,{role,content}])
} }
const handleSendClick = (inputValue: string) => { const handleSendClick = (inputValue: string) => {
if (sendable) {
sendable=false
if (postWorkerRef.current) { if (postWorkerRef.current) {
addMessage("user", inputValue) addMessage("user", inputValue)
console.log("input:",inputValue); console.log("input:",inputValue);
@ -116,6 +122,7 @@ const InputOutputBackend: React.FC = () => {
startGetWorker() startGetWorker()
} }
} }
}
const handleMicClick = () => { const handleMicClick = () => {
// do stuff // do stuff