Skip to content

Commit

Permalink
Done
Browse files Browse the repository at this point in the history
  • Loading branch information
sonuku092 committed Feb 29, 2024
1 parent 4af8bdb commit 7032e5b
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion backend/src/chats/websocket.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Socket } from 'socket.io';

@WebSocketGateway()
export class MyWebSocketGateway implements OnGatewayInit, OnGatewayConnection, OnGatewayDisconnect {
@WebSocketServer() server;
@WebSocketServer() server: any;

handleConnection(client: Socket) {
console.log(`Client connected: ${client.id}`);
Expand Down
1 change: 1 addition & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^1.6.7",
"boundary": "^2.0.0",
"firebase": "^10.8.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
36 changes: 17 additions & 19 deletions frontend/src/components/Chats/Chats.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect, useMemo, useRef } from "react";
import React, { useState, useEffect, useMemo, useCallback, useRef } from "react";
import { useNavigate } from 'react-router-dom';
import { signOut } from "firebase/auth";
import { auth } from "../../firebase";
Expand All @@ -8,7 +8,6 @@ import { useSpeechSynthesis } from 'react-speech-kit';
import { useSpeechRecognition } from 'react-speech-recognition';
import { split } from 'sentence-splitter';
import SpeechRecognition from 'react-speech-recognition';
import axios from 'axios'; // Import Axios

function Chats(props) {
const [userName, setUserName] = useState("");
Expand All @@ -26,12 +25,12 @@ function Chats(props) {
const { speak } = useSpeechSynthesis();
const { transcript, listening } = useSpeechRecognition();

const predefinedAnswers = {
const predefinedAnswers = useMemo(() => ({
"What is your name?": "My name is Chatbot.",
// Define your predefined answers here
};
}), []);

const handleUserInput = async () => {
const handleUserInput = useCallback(async () => {
const userMessage = input.trim();

if (userMessage) {
Expand All @@ -44,7 +43,6 @@ function Chats(props) {
]);
speak({ text: predefinedAnswer });
} else {
// Handle other user messages
setIsTyping(true);
const userMessage = input;
setInput('');
Expand All @@ -64,7 +62,14 @@ function Chats(props) {

setInput('');
}
};
}, [input, speak, socket, predefinedAnswers]);

const handleSubmit = useCallback((event) => {
if (event) {
event.preventDefault();
}
handleUserInput();
}, [handleUserInput]);

useEffect(() => {
if (transcript) {
Expand All @@ -78,7 +83,7 @@ function Chats(props) {
if (!listening && input.trim() !== '') {
handleSubmit();
}
}, [listening]);
}, [listening, input, handleSubmit]);

const isProcessingRef = useRef(false);

Expand Down Expand Up @@ -106,7 +111,7 @@ function Chats(props) {
},
]);

setLastBotMessage(sentence); // Set the last bot message
setLastBotMessage(sentence);
}
}

Expand All @@ -116,7 +121,7 @@ function Chats(props) {
isProcessingRef.current = false;
}
});
}, [socket]);
}, [socket, isTyping]);

const lastSpokenMessageRef = useRef(null);

Expand All @@ -131,13 +136,6 @@ function Chats(props) {
setInput(event.target.value);
};

const handleSubmit = (event) => {
if (event) {
event.preventDefault();
}
handleUserInput();
};

useEffect(() => {
setUserName(localStorage.getItem("userName"));

Expand All @@ -148,7 +146,7 @@ function Chats(props) {
return () => {
socket.disconnect();
};
}, []);
}, [socket]);

const handleSignout = () => {
localStorage.removeItem("token");
Expand Down Expand Up @@ -211,7 +209,7 @@ function Chats(props) {
<button onClick={toggleVoice} className="bg-blue-600 text-white p-1 rounded-lg"> Voice </button>
</div>

<div className="h-[500px] rounded-lg overflow-y-scroll" style={{ color: 'whitesmoke', color: 'black' }}>
<div className="h-[500px] rounded-lg overflow-y-scroll">

{messages.map((message, index) => (
<div
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Login/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function Login() {
if (token) {
navigate('/');
}
}, []);
}, [navigate]);

const [errorMsg, setErrorMsg] = useState('');
const [summitButtonDisabled, setSummitButtonDisabled] = useState(false);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Signup/Signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function Signup() {

const val = doc(db, "Users", docRef.id);
const collectionVal = collection(val, "Chats");
const newDoc = await addDoc(collectionVal, {
addDoc(collectionVal, {
User_ID: user.uid,
Message: "Hello",
});
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/firebase.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { initializeApp } from "firebase/app";
import { getAnalytics } from "firebase/analytics";
// import { getAnalytics } from "firebase/analytics";
import { getAuth } from "firebase/auth";
import { getFirestore } from 'firebase/firestore';

Expand All @@ -14,7 +14,7 @@ const firebaseConfig = {
};

const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
// const analytics = getAnalytics(app);

const auth = getAuth(app);

Expand Down

0 comments on commit 7032e5b

Please sign in to comment.