From a050da3135b14754c7a4a98ebf2ee9e5454ebe67 Mon Sep 17 00:00:00 2001 From: Mohit Verma Date: Thu, 1 Aug 2024 18:15:01 +0530 Subject: [PATCH 01/31] chore: converts into tsx from jsx and added typs in some files --- backend/db/client.go | 2 +- .../{chatContainer.jsx => chatContainer.tsx} | 0 .../{chatInputBox.jsx => chatInputBox.tsx} | 19 +++++--- .../chat/{loginModal.jsx => loginModal.tsx} | 24 +++++++---- ...tbotContainer.jsx => chatbotContainer.tsx} | 0 ...otLoginModal.jsx => chatbotLoginModal.tsx} | 0 .../components/{layout.jsx => layout.tsx} | 0 frontend/components/{mail.jsx => mail.tsx} | 18 +++++--- .../components/{mdgBox.jsx => mdgBox.tsx} | 8 +++- frontend/components/{modal.jsx => modal.tsx} | 0 .../components/{navbar.jsx => navbar.tsx} | 17 +++++--- .../{projectCard.jsx => projectCard.tsx} | 0 .../{projectData.jsx => projectData.tsx} | 0 .../{projectList.jsx => projectList.tsx} | 0 .../{rightPane.jsx => rightPane.tsx} | 0 .../{settingsPopup.jsx => settingsPopup.tsx} | 15 +++++-- .../{topicDropdown.jsx => topicDropdown.tsx} | 32 +++++++++++--- ...ctionModal.jsx => topicSelectionModal.tsx} | 5 ++- .../{usernameInput.jsx => usernameInput.tsx} | 0 .../{useLeaveChat.jsx => useLeaveChat.tsx} | 0 ...seLoadSettings.jsx => useLoadSettings.tsx} | 0 .../{useSettings.jsx => useSettings.tsx} | 0 ...lityChange.jsx => useVisibilityChange.tsx} | 0 ...ChatBot.jsx => useWebSocketForChatBot.tsx} | 0 .../{useWebsocket.jsx => useWebsocket.tsx} | 0 frontend/next-env.d.ts | 5 +++ frontend/package-lock.json | 43 +++++++++++++++++++ frontend/package.json | 4 ++ frontend/pages/{_app.jsx => _app.tsx} | 0 frontend/pages/{chat.jsx => chat.tsx} | 0 frontend/pages/{chat_bot.jsx => chat_bot.tsx} | 0 frontend/pages/{index.jsx => index.tsx} | 6 +-- frontend/services/api/{api.js => api.ts} | 0 .../api/{leaveChatApi.js => leaveChatApi.ts} | 0 .../api/{projectsApi.js => projectsApi.ts} | 0 .../api/{subscribeApi.js => subscribeApi.ts} | 0 .../{url-builder.js => url-builder.ts} | 0 frontend/tsconfig.json | 28 ++++++++++++ ...AbnormalClose.js => alertAbnormalClose.ts} | 0 ...{alertBadRequest.js => alertBadRequest.ts} | 0 ...{alertBannedUser.js => alertBannedUser.ts} | 0 ...rtSameUsername.js => alertSameUsername.ts} | 0 ...lertServerError.js => alertServerError.ts} | 0 ...ange.js => checkAndPromptSessionChange.ts} | 0 ...otUserText.js => formatChatbotUserText.ts} | 0 ...ntForChatBot.js => getIsSentForChatBot.ts} | 0 ...seMessageText.jsx => parseMessageText.tsx} | 0 ...ampFromDate.js => getTimestampFromDate.ts} | 0 frontend/utils/{playSound.js => playSound.ts} | 0 .../session/{getAvatar.js => getAvatar.ts} | 0 .../{getSessionUser.js => getSessionUser.ts} | 0 ...etSessionUserId.js => getSessionUserId.ts} | 0 ...essionUserId.js => removeSessionUserId.ts} | 0 .../{setSessionUser.js => setSessionUser.ts} | 0 ...SocketClose.js => handleWebSocketClose.ts} | 0 ...SocketError.js => handleWebSocketError.ts} | 0 ...tMessage.js => processWebSocketMessage.ts} | 0 ...ebsocketHelpers.js => websocketHelpers.ts} | 0 58 files changed, 182 insertions(+), 44 deletions(-) rename frontend/components/chat/{chatContainer.jsx => chatContainer.tsx} (100%) rename frontend/components/chat/{chatInputBox.jsx => chatInputBox.tsx} (81%) rename frontend/components/chat/{loginModal.jsx => loginModal.tsx} (84%) rename frontend/components/chatbot/{chatbotContainer.jsx => chatbotContainer.tsx} (100%) rename frontend/components/chatbot/{chatbotLoginModal.jsx => chatbotLoginModal.tsx} (100%) rename frontend/components/{layout.jsx => layout.tsx} (100%) rename frontend/components/{mail.jsx => mail.tsx} (85%) rename frontend/components/{mdgBox.jsx => mdgBox.tsx} (96%) rename frontend/components/{modal.jsx => modal.tsx} (100%) rename frontend/components/{navbar.jsx => navbar.tsx} (83%) rename frontend/components/projects/{projectCard.jsx => projectCard.tsx} (100%) rename frontend/components/projects/{projectData.jsx => projectData.tsx} (100%) rename frontend/components/projects/{projectList.jsx => projectList.tsx} (100%) rename frontend/components/{rightPane.jsx => rightPane.tsx} (100%) rename frontend/components/{settingsPopup.jsx => settingsPopup.tsx} (87%) rename frontend/components/{topicDropdown.jsx => topicDropdown.tsx} (85%) rename frontend/components/{topicSelectionModal.jsx => topicSelectionModal.tsx} (78%) rename frontend/components/{usernameInput.jsx => usernameInput.tsx} (100%) rename frontend/hooks/{useLeaveChat.jsx => useLeaveChat.tsx} (100%) rename frontend/hooks/{useLoadSettings.jsx => useLoadSettings.tsx} (100%) rename frontend/hooks/{useSettings.jsx => useSettings.tsx} (100%) rename frontend/hooks/{useVisibilityChange.jsx => useVisibilityChange.tsx} (100%) rename frontend/hooks/{useWebSocketForChatBot.jsx => useWebSocketForChatBot.tsx} (100%) rename frontend/hooks/{useWebsocket.jsx => useWebsocket.tsx} (100%) create mode 100644 frontend/next-env.d.ts rename frontend/pages/{_app.jsx => _app.tsx} (100%) rename frontend/pages/{chat.jsx => chat.tsx} (100%) rename frontend/pages/{chat_bot.jsx => chat_bot.tsx} (100%) rename frontend/pages/{index.jsx => index.tsx} (95%) rename frontend/services/api/{api.js => api.ts} (100%) rename frontend/services/api/{leaveChatApi.js => leaveChatApi.ts} (100%) rename frontend/services/api/{projectsApi.js => projectsApi.ts} (100%) rename frontend/services/api/{subscribeApi.js => subscribeApi.ts} (100%) rename frontend/services/url-builder/{url-builder.js => url-builder.ts} (100%) create mode 100644 frontend/tsconfig.json rename frontend/utils/alerts/{alertAbnormalClose.js => alertAbnormalClose.ts} (100%) rename frontend/utils/alerts/{alertBadRequest.js => alertBadRequest.ts} (100%) rename frontend/utils/alerts/{alertBannedUser.js => alertBannedUser.ts} (100%) rename frontend/utils/alerts/{alertSameUsername.js => alertSameUsername.ts} (100%) rename frontend/utils/alerts/{alertServerError.js => alertServerError.ts} (100%) rename frontend/utils/alerts/{checkAndPromptSessionChange.js => checkAndPromptSessionChange.ts} (100%) rename frontend/utils/chatbot_formatting/{formatChatbotUserText.js => formatChatbotUserText.ts} (100%) rename frontend/utils/chatbot_formatting/{getIsSentForChatBot.js => getIsSentForChatBot.ts} (100%) rename frontend/utils/chatbot_formatting/{parseMessageText.jsx => parseMessageText.tsx} (100%) rename frontend/utils/{getTimestampFromDate.js => getTimestampFromDate.ts} (100%) rename frontend/utils/{playSound.js => playSound.ts} (100%) rename frontend/utils/session/{getAvatar.js => getAvatar.ts} (100%) rename frontend/utils/session/{getSessionUser.js => getSessionUser.ts} (100%) rename frontend/utils/session/{getSessionUserId.js => getSessionUserId.ts} (100%) rename frontend/utils/session/{removeSessionUserId.js => removeSessionUserId.ts} (100%) rename frontend/utils/session/{setSessionUser.js => setSessionUser.ts} (100%) rename frontend/utils/websocket/{handleWebSocketClose.js => handleWebSocketClose.ts} (100%) rename frontend/utils/websocket/{handleWebSocketError.js => handleWebSocketError.ts} (100%) rename frontend/utils/websocket/{processWebSocketMessage.js => processWebSocketMessage.ts} (100%) rename frontend/utils/websocket/{websocketHelpers.js => websocketHelpers.ts} (100%) diff --git a/backend/db/client.go b/backend/db/client.go index 37a241d..eb788a6 100644 --- a/backend/db/client.go +++ b/backend/db/client.go @@ -24,7 +24,7 @@ func Init() { func redisInit(portNumber, dbNumber int, password string) { ctx = context.Background() redisClient = redis.NewClient(&redis.Options{ - Addr: fmt.Sprintf("redis:%v", portNumber), //port number can be changed as per our wish + Addr: fmt.Sprintf("localhost:%v", portNumber), //port number can be changed as per our wish Password: password, DB: dbNumber, }) diff --git a/frontend/components/chat/chatContainer.jsx b/frontend/components/chat/chatContainer.tsx similarity index 100% rename from frontend/components/chat/chatContainer.jsx rename to frontend/components/chat/chatContainer.tsx diff --git a/frontend/components/chat/chatInputBox.jsx b/frontend/components/chat/chatInputBox.tsx similarity index 81% rename from frontend/components/chat/chatInputBox.jsx rename to frontend/components/chat/chatInputBox.tsx index 6835f88..b392249 100644 --- a/frontend/components/chat/chatInputBox.jsx +++ b/frontend/components/chat/chatInputBox.tsx @@ -1,13 +1,18 @@ import { useState, useRef } from "react"; import sendLogo from "../../assets/send.svg"; import Image from "next/image"; -export default function ChatInputBox({ socketRef }) { - const [newMessage, setNewMessage] = useState(""); - const [isTimeout, setIsTimeout] = useState(false); - const messageTimesRef = useRef([]); - function handleInputChange(event) { - setNewMessage(event.target.value); +interface ChatInputBoxProps { + socketRef: React.MutableRefObject; +} + +export default function ChatInputBox({ socketRef }:ChatInputBoxProps) { + const [newMessage, setNewMessage] = useState(""); + const [isTimeout, setIsTimeout] = useState(false); + const messageTimesRef = useRef([]); + + function handleInputChange(event:any) { + setNewMessage(event.target.value); } function handleSendClick() { @@ -23,7 +28,7 @@ export default function ChatInputBox({ socketRef }) { } } - function handleKeyPress(event) { + function handleKeyPress(event: any) { if (event.key === "Enter") { handleSendClick(); } diff --git a/frontend/components/chat/loginModal.jsx b/frontend/components/chat/loginModal.tsx similarity index 84% rename from frontend/components/chat/loginModal.jsx rename to frontend/components/chat/loginModal.tsx index a82c539..275f988 100644 --- a/frontend/components/chat/loginModal.jsx +++ b/frontend/components/chat/loginModal.tsx @@ -6,24 +6,29 @@ import setSessionUser from "../../utils/session/setSessionUser"; import removeSessionUserId from "../../utils/session/removeSessionUserId"; import checkAndPromptSessionChange from "../../utils/alerts/checkAndPromptSessionChange"; -const LoginModal = ({ onClose, redirect }) => { - const popupRef = useRef(); - const [username, setUsername] = useState(""); +interface LoginModalProps{ + onClose: ()=>void; + redirect:string; +} + +const LoginModal = ({ onClose, redirect }: LoginModalProps) => { + const popupRef = useRef(null); + const [username, setUsername] = useState(""); const router = useRouter(); - function handleUsernameChange(event) { + function handleUsernameChange(event: React.ChangeEvent) { setUsername(event.target.value); } - function handleEnterClick(event) { + function handleEnterClick(event: React.KeyboardEvent) { if (event.key === "Enter") { handleChatWithUsClick(); } } useEffect(() => { - function handleClickOutside(event) { - if (popupRef.current && !popupRef.current.contains(event.target)) { + function handleClickOutside(event : MouseEvent) { + if (popupRef.current && !popupRef.current.contains(event.target as Node)) { onClose(); } } @@ -37,6 +42,9 @@ const LoginModal = ({ onClose, redirect }) => { const currentUser = getSessionUser(); const currentUserId = getSessionUserId(); const query={channel:chatType}; + + + if (currentUser && currentUserId) { if (currentUser === username) { router.push({pathname:'/chat',query}); @@ -79,7 +87,7 @@ const LoginModal = ({ onClose, redirect }) => { />
CHAT WITH US diff --git a/frontend/components/chatbot/chatbotContainer.jsx b/frontend/components/chatbot/chatbotContainer.tsx similarity index 100% rename from frontend/components/chatbot/chatbotContainer.jsx rename to frontend/components/chatbot/chatbotContainer.tsx diff --git a/frontend/components/chatbot/chatbotLoginModal.jsx b/frontend/components/chatbot/chatbotLoginModal.tsx similarity index 100% rename from frontend/components/chatbot/chatbotLoginModal.jsx rename to frontend/components/chatbot/chatbotLoginModal.tsx diff --git a/frontend/components/layout.jsx b/frontend/components/layout.tsx similarity index 100% rename from frontend/components/layout.jsx rename to frontend/components/layout.tsx diff --git a/frontend/components/mail.jsx b/frontend/components/mail.tsx similarity index 85% rename from frontend/components/mail.jsx rename to frontend/components/mail.tsx index 7eff024..789b14e 100644 --- a/frontend/components/mail.jsx +++ b/frontend/components/mail.tsx @@ -1,18 +1,24 @@ -import React from "react"; +import React, { useEffect, useRef } from "react"; import { useState } from "react"; import subscribe from "../services/api/subscribeApi"; import getSessionUser from "../utils/session/getSessionUser"; import getSessionUserId from "../utils/session/getSessionUserId"; + +interface MailProps{ + isOpen?:boolean; + onClose: () => void; + channel: string; +} export default function Mail({ isOpen, onClose, channel, -}) { - const [email, setEmail] = useState(""); - const popupRef = React.useRef(); +} : MailProps) { + const [email, setEmail] = useState(""); + const popupRef = useRef(null); - const handleSubmit = async (e) => { + const handleSubmit = async (e:any) => { let userId = getSessionUserId(); let username = getSessionUser(); e.preventDefault(); @@ -24,7 +30,7 @@ export default function Mail({ } }; - React.useEffect(() => { + useEffect(() => { function handleClickOutside(event) { if (popupRef.current && !popupRef.current.contains(event.target)) { onClose(); diff --git a/frontend/components/mdgBox.jsx b/frontend/components/mdgBox.tsx similarity index 96% rename from frontend/components/mdgBox.jsx rename to frontend/components/mdgBox.tsx index ddec593..c3dcf9a 100644 --- a/frontend/components/mdgBox.jsx +++ b/frontend/components/mdgBox.tsx @@ -5,7 +5,11 @@ import { useRouter } from "next/router"; import { fetchProjects } from "../services/api/projectsApi"; import { ProjectList } from "./projects/projectList"; -export default function Box({ channel }) { +interface BoxProps { + channel: string; +} + +export default function Box({ channel }: BoxProps) { const router = useRouter(); const arr = ["public", "private", "chatbot"]; const newArr = arr.filter((item) => item !== channel); @@ -51,7 +55,7 @@ export default function Box({ channel }) { } }; const [topic, setTopic] = useState(" "); - const handleDivClick = (e) => { + const handleDivClick = (e: any) => { const content = e.target.textContent; setTopic(content); router.push({ diff --git a/frontend/components/modal.jsx b/frontend/components/modal.tsx similarity index 100% rename from frontend/components/modal.jsx rename to frontend/components/modal.tsx diff --git a/frontend/components/navbar.jsx b/frontend/components/navbar.tsx similarity index 83% rename from frontend/components/navbar.jsx rename to frontend/components/navbar.tsx index 1197abd..e4d941f 100644 --- a/frontend/components/navbar.jsx +++ b/frontend/components/navbar.tsx @@ -6,12 +6,17 @@ import jinoraLogo from "../assets/logo.svg"; import slack from ".././assets/slack_blue.svg"; import { TopicDropdown } from "./topicDropdown"; -export const Navbar = ({ currentPage, currentTopic }) => { - const [isMailOpen, setIsMailOpen] = useState(false); - const [logo, setLogo] = useState(jinoraLogo); - const [leftText, setLeftText] = useState(""); - const [toShow, setToShow] = useState(false); - const [topic,setTopic]=useState(currentTopic); +interface NavbarProps{ + currentPage: string; + currentTopic:string; +} + +export const Navbar = ({ currentPage, currentTopic }: NavbarProps) => { + const [isMailOpen, setIsMailOpen] = useState(false); + const [logo, setLogo] = useState(jinoraLogo); + const [leftText, setLeftText] = useState(""); + const [toShow, setToShow] = useState(false); + const [topic,setTopic]=useState(currentTopic); function openMail() { setIsMailOpen(true); diff --git a/frontend/components/projects/projectCard.jsx b/frontend/components/projects/projectCard.tsx similarity index 100% rename from frontend/components/projects/projectCard.jsx rename to frontend/components/projects/projectCard.tsx diff --git a/frontend/components/projects/projectData.jsx b/frontend/components/projects/projectData.tsx similarity index 100% rename from frontend/components/projects/projectData.jsx rename to frontend/components/projects/projectData.tsx diff --git a/frontend/components/projects/projectList.jsx b/frontend/components/projects/projectList.tsx similarity index 100% rename from frontend/components/projects/projectList.jsx rename to frontend/components/projects/projectList.tsx diff --git a/frontend/components/rightPane.jsx b/frontend/components/rightPane.tsx similarity index 100% rename from frontend/components/rightPane.jsx rename to frontend/components/rightPane.tsx diff --git a/frontend/components/settingsPopup.jsx b/frontend/components/settingsPopup.tsx similarity index 87% rename from frontend/components/settingsPopup.jsx rename to frontend/components/settingsPopup.tsx index 0f0a242..79869a9 100644 --- a/frontend/components/settingsPopup.jsx +++ b/frontend/components/settingsPopup.tsx @@ -8,18 +8,27 @@ import { MdAudiotrack, } from "react-icons/md"; +interface SettingsPopupProps { + onClose: () => void; + soundEnabled: boolean; + setSoundEnabled: (enabled: boolean) => void; + notificationsEnabled: boolean; + setNotificationsEnabled: (enabled: boolean) => void; +} + + const SettingsPopup = ({ onClose, soundEnabled, setSoundEnabled, notificationsEnabled, setNotificationsEnabled, -}) => { - const popupRef = useRef(); +}: SettingsPopupProps) => { + const popupRef = useRef(null); useEffect(() => { function handleClickOutside(event) { - if (popupRef.current && !popupRef.current.contains(event.target)) { + if (popupRef.current && !popupRef.current.contains(event.target as Node)) { onClose(); } } diff --git a/frontend/components/topicDropdown.jsx b/frontend/components/topicDropdown.tsx similarity index 85% rename from frontend/components/topicDropdown.jsx rename to frontend/components/topicDropdown.tsx index e955bfa..44ccc13 100644 --- a/frontend/components/topicDropdown.jsx +++ b/frontend/components/topicDropdown.tsx @@ -3,10 +3,28 @@ import React, { useState } from "react"; import { fetchProjects } from "../services/api/projectsApi"; import { useEffect, useRef } from "react"; -export const TopicDropdown = ({ topic, setTopic,login }) => { - const popupRef = useRef(); - const [isOpen, setIsOpen] = useState(false); - const [projects, setProjects] = useState([]); +interface TopicDropdownProps { + topic: string; + setTopic: (topic: string) => void; + login: boolean; +} + +interface Project{ + Category: string; + Name: string; + ShortDesc :string; + LongDesc:string; + ImageLink: string; + AppStoreLink: string; + GithubLink: string; + PlayStoreLink: string; +} + +export const TopicDropdown = ({ topic, setTopic,login }:TopicDropdownProps) => { + const popupRef = useRef(null); + const [isOpen, setIsOpen] = useState(false); + const [projects, setProjects] = useState([]); + const projectList = projects.filter( (project) => project.Category === "Projects", ); @@ -16,7 +34,7 @@ export const TopicDropdown = ({ topic, setTopic,login }) => { setIsOpen(!isOpen); }; - const handleClick = (e) => { + const handleClick = (e:any) => { const content = e.target.textContent; setTopic(content); if(!login){ @@ -37,8 +55,8 @@ export const TopicDropdown = ({ topic, setTopic,login }) => { }, []); useEffect(() => { - function handleClickOutside(event) { - if (popupRef.current && !popupRef.current.contains(event.target)) { + function handleClickOutside(event: MouseEvent) { + if (popupRef.current && !popupRef.current.contains(event.target as Node)) { setIsOpen(false); } } diff --git a/frontend/components/topicSelectionModal.jsx b/frontend/components/topicSelectionModal.tsx similarity index 78% rename from frontend/components/topicSelectionModal.jsx rename to frontend/components/topicSelectionModal.tsx index b210bc5..7fa9ba4 100644 --- a/frontend/components/topicSelectionModal.jsx +++ b/frontend/components/topicSelectionModal.tsx @@ -1,6 +1,9 @@ import React from "react"; +interface TopicSelectionModalProps{ + onClose: () => void; +} -const TopicSelectionModal = ({ onClose }) => { +const TopicSelectionModal = ({ onClose }: TopicSelectionModalProps) => { return (
diff --git a/frontend/components/usernameInput.jsx b/frontend/components/usernameInput.tsx similarity index 100% rename from frontend/components/usernameInput.jsx rename to frontend/components/usernameInput.tsx diff --git a/frontend/hooks/useLeaveChat.jsx b/frontend/hooks/useLeaveChat.tsx similarity index 100% rename from frontend/hooks/useLeaveChat.jsx rename to frontend/hooks/useLeaveChat.tsx diff --git a/frontend/hooks/useLoadSettings.jsx b/frontend/hooks/useLoadSettings.tsx similarity index 100% rename from frontend/hooks/useLoadSettings.jsx rename to frontend/hooks/useLoadSettings.tsx diff --git a/frontend/hooks/useSettings.jsx b/frontend/hooks/useSettings.tsx similarity index 100% rename from frontend/hooks/useSettings.jsx rename to frontend/hooks/useSettings.tsx diff --git a/frontend/hooks/useVisibilityChange.jsx b/frontend/hooks/useVisibilityChange.tsx similarity index 100% rename from frontend/hooks/useVisibilityChange.jsx rename to frontend/hooks/useVisibilityChange.tsx diff --git a/frontend/hooks/useWebSocketForChatBot.jsx b/frontend/hooks/useWebSocketForChatBot.tsx similarity index 100% rename from frontend/hooks/useWebSocketForChatBot.jsx rename to frontend/hooks/useWebSocketForChatBot.tsx diff --git a/frontend/hooks/useWebsocket.jsx b/frontend/hooks/useWebsocket.tsx similarity index 100% rename from frontend/hooks/useWebsocket.jsx rename to frontend/hooks/useWebsocket.tsx diff --git a/frontend/next-env.d.ts b/frontend/next-env.d.ts new file mode 100644 index 0000000..4f11a03 --- /dev/null +++ b/frontend/next-env.d.ts @@ -0,0 +1,5 @@ +/// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/frontend/package-lock.json b/frontend/package-lock.json index ba56355..58bdcbc 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -22,6 +22,10 @@ "start": "^5.1.0", "sweetalert2": "^11.10.1", "tailwindcss": "^3.3.3" + }, + "devDependencies": { + "@types/react": "18.3.3", + "typescript": "5.5.4" } }, "node_modules/@alloc/quick-lru": { @@ -765,6 +769,24 @@ "undici-types": "~5.26.4" } }, + "node_modules/@types/prop-types": { + "version": "15.7.12", + "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.12.tgz", + "integrity": "sha512-5zvhXYtRNRluoE/jAp4GVsSduVUzNWKkOZrCDBWYtE7biZywwdC2AcEzg+cSMLFRfVgeAFqpfNabiPjxFddV1Q==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/react": { + "version": "18.3.3", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.3.tgz", + "integrity": "sha512-hti/R0pS0q1/xx+TsI73XIqk26eBsISZ2R0wUijXIngRK9R/e7Xw/cXVxQK7R5JjW+SV4zGcn5hXjudkN/pLIw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/prop-types": "*", + "csstype": "^3.0.2" + } + }, "node_modules/@webassemblyjs/ast": { "version": "1.11.6", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.6.tgz", @@ -1319,6 +1341,13 @@ "node": ">=4" } }, + "node_modules/csstype": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz", + "integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==", + "dev": true, + "license": "MIT" + }, "node_modules/debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -2857,6 +2886,20 @@ "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.5.0.tgz", "integrity": "sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==" }, + "node_modules/typescript": { + "version": "5.5.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz", + "integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, "node_modules/undici-types": { "version": "5.26.5", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", diff --git a/frontend/package.json b/frontend/package.json index d026958..435e918 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -24,5 +24,9 @@ "start": "^5.1.0", "sweetalert2": "^11.10.1", "tailwindcss": "^3.3.3" + }, + "devDependencies": { + "@types/react": "18.3.3", + "typescript": "5.5.4" } } diff --git a/frontend/pages/_app.jsx b/frontend/pages/_app.tsx similarity index 100% rename from frontend/pages/_app.jsx rename to frontend/pages/_app.tsx diff --git a/frontend/pages/chat.jsx b/frontend/pages/chat.tsx similarity index 100% rename from frontend/pages/chat.jsx rename to frontend/pages/chat.tsx diff --git a/frontend/pages/chat_bot.jsx b/frontend/pages/chat_bot.tsx similarity index 100% rename from frontend/pages/chat_bot.jsx rename to frontend/pages/chat_bot.tsx diff --git a/frontend/pages/index.jsx b/frontend/pages/index.tsx similarity index 95% rename from frontend/pages/index.jsx rename to frontend/pages/index.tsx index d09a811..d106a2b 100644 --- a/frontend/pages/index.jsx +++ b/frontend/pages/index.tsx @@ -76,7 +76,7 @@ export default function Home() { onClick={goToChatbot} >

- + {"chat TALK TO OUR CHATBOT

@@ -85,7 +85,7 @@ export default function Home() { onClick={goToPrivateChat} >

- + {"slack PRIVATE CHAT ON SLACK

@@ -94,7 +94,7 @@ export default function Home() { onClick={goToPublicChat} >

- + {"slack PUBLIC MDG CHAT FORUM

diff --git a/frontend/services/api/api.js b/frontend/services/api/api.ts similarity index 100% rename from frontend/services/api/api.js rename to frontend/services/api/api.ts diff --git a/frontend/services/api/leaveChatApi.js b/frontend/services/api/leaveChatApi.ts similarity index 100% rename from frontend/services/api/leaveChatApi.js rename to frontend/services/api/leaveChatApi.ts diff --git a/frontend/services/api/projectsApi.js b/frontend/services/api/projectsApi.ts similarity index 100% rename from frontend/services/api/projectsApi.js rename to frontend/services/api/projectsApi.ts diff --git a/frontend/services/api/subscribeApi.js b/frontend/services/api/subscribeApi.ts similarity index 100% rename from frontend/services/api/subscribeApi.js rename to frontend/services/api/subscribeApi.ts diff --git a/frontend/services/url-builder/url-builder.js b/frontend/services/url-builder/url-builder.ts similarity index 100% rename from frontend/services/url-builder/url-builder.js rename to frontend/services/url-builder/url-builder.ts diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json new file mode 100644 index 0000000..400e5f3 --- /dev/null +++ b/frontend/tsconfig.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], + "allowJs": true, + "skipLibCheck": true, + "strict": false, + "noEmit": true, + "incremental": true, + "esModuleInterop": true, + "module": "esnext", + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true, + "jsx": "preserve" + }, + "include": [ + "next-env.d.ts", + "**/*.ts", + "**/*.tsx" +, "context/userContext.js" ], + "exclude": [ + "node_modules" + ] +} diff --git a/frontend/utils/alerts/alertAbnormalClose.js b/frontend/utils/alerts/alertAbnormalClose.ts similarity index 100% rename from frontend/utils/alerts/alertAbnormalClose.js rename to frontend/utils/alerts/alertAbnormalClose.ts diff --git a/frontend/utils/alerts/alertBadRequest.js b/frontend/utils/alerts/alertBadRequest.ts similarity index 100% rename from frontend/utils/alerts/alertBadRequest.js rename to frontend/utils/alerts/alertBadRequest.ts diff --git a/frontend/utils/alerts/alertBannedUser.js b/frontend/utils/alerts/alertBannedUser.ts similarity index 100% rename from frontend/utils/alerts/alertBannedUser.js rename to frontend/utils/alerts/alertBannedUser.ts diff --git a/frontend/utils/alerts/alertSameUsername.js b/frontend/utils/alerts/alertSameUsername.ts similarity index 100% rename from frontend/utils/alerts/alertSameUsername.js rename to frontend/utils/alerts/alertSameUsername.ts diff --git a/frontend/utils/alerts/alertServerError.js b/frontend/utils/alerts/alertServerError.ts similarity index 100% rename from frontend/utils/alerts/alertServerError.js rename to frontend/utils/alerts/alertServerError.ts diff --git a/frontend/utils/alerts/checkAndPromptSessionChange.js b/frontend/utils/alerts/checkAndPromptSessionChange.ts similarity index 100% rename from frontend/utils/alerts/checkAndPromptSessionChange.js rename to frontend/utils/alerts/checkAndPromptSessionChange.ts diff --git a/frontend/utils/chatbot_formatting/formatChatbotUserText.js b/frontend/utils/chatbot_formatting/formatChatbotUserText.ts similarity index 100% rename from frontend/utils/chatbot_formatting/formatChatbotUserText.js rename to frontend/utils/chatbot_formatting/formatChatbotUserText.ts diff --git a/frontend/utils/chatbot_formatting/getIsSentForChatBot.js b/frontend/utils/chatbot_formatting/getIsSentForChatBot.ts similarity index 100% rename from frontend/utils/chatbot_formatting/getIsSentForChatBot.js rename to frontend/utils/chatbot_formatting/getIsSentForChatBot.ts diff --git a/frontend/utils/chatbot_formatting/parseMessageText.jsx b/frontend/utils/chatbot_formatting/parseMessageText.tsx similarity index 100% rename from frontend/utils/chatbot_formatting/parseMessageText.jsx rename to frontend/utils/chatbot_formatting/parseMessageText.tsx diff --git a/frontend/utils/getTimestampFromDate.js b/frontend/utils/getTimestampFromDate.ts similarity index 100% rename from frontend/utils/getTimestampFromDate.js rename to frontend/utils/getTimestampFromDate.ts diff --git a/frontend/utils/playSound.js b/frontend/utils/playSound.ts similarity index 100% rename from frontend/utils/playSound.js rename to frontend/utils/playSound.ts diff --git a/frontend/utils/session/getAvatar.js b/frontend/utils/session/getAvatar.ts similarity index 100% rename from frontend/utils/session/getAvatar.js rename to frontend/utils/session/getAvatar.ts diff --git a/frontend/utils/session/getSessionUser.js b/frontend/utils/session/getSessionUser.ts similarity index 100% rename from frontend/utils/session/getSessionUser.js rename to frontend/utils/session/getSessionUser.ts diff --git a/frontend/utils/session/getSessionUserId.js b/frontend/utils/session/getSessionUserId.ts similarity index 100% rename from frontend/utils/session/getSessionUserId.js rename to frontend/utils/session/getSessionUserId.ts diff --git a/frontend/utils/session/removeSessionUserId.js b/frontend/utils/session/removeSessionUserId.ts similarity index 100% rename from frontend/utils/session/removeSessionUserId.js rename to frontend/utils/session/removeSessionUserId.ts diff --git a/frontend/utils/session/setSessionUser.js b/frontend/utils/session/setSessionUser.ts similarity index 100% rename from frontend/utils/session/setSessionUser.js rename to frontend/utils/session/setSessionUser.ts diff --git a/frontend/utils/websocket/handleWebSocketClose.js b/frontend/utils/websocket/handleWebSocketClose.ts similarity index 100% rename from frontend/utils/websocket/handleWebSocketClose.js rename to frontend/utils/websocket/handleWebSocketClose.ts diff --git a/frontend/utils/websocket/handleWebSocketError.js b/frontend/utils/websocket/handleWebSocketError.ts similarity index 100% rename from frontend/utils/websocket/handleWebSocketError.js rename to frontend/utils/websocket/handleWebSocketError.ts diff --git a/frontend/utils/websocket/processWebSocketMessage.js b/frontend/utils/websocket/processWebSocketMessage.ts similarity index 100% rename from frontend/utils/websocket/processWebSocketMessage.js rename to frontend/utils/websocket/processWebSocketMessage.ts diff --git a/frontend/utils/websocket/websocketHelpers.js b/frontend/utils/websocket/websocketHelpers.ts similarity index 100% rename from frontend/utils/websocket/websocketHelpers.js rename to frontend/utils/websocket/websocketHelpers.ts From 5f43232e648565f433bffbc7a832d3a7301ead2e Mon Sep 17 00:00:00 2001 From: Mohit Verma Date: Thu, 1 Aug 2024 21:12:34 +0530 Subject: [PATCH 02/31] fix: fixes closing of dropdown on selecting a project and added types --- frontend/components/chat/chatInputBox.tsx | 11 ++++++----- frontend/components/topicDropdown.tsx | 7 ++++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/frontend/components/chat/chatInputBox.tsx b/frontend/components/chat/chatInputBox.tsx index b392249..0a9a3d6 100644 --- a/frontend/components/chat/chatInputBox.tsx +++ b/frontend/components/chat/chatInputBox.tsx @@ -62,11 +62,12 @@ export default function ChatInputBox({ socketRef }:ChatInputBoxProps) { disabled={isTimeout} className="w-full p-3 pl-10 border-none rounded-lg placeholder-customBlue font-medium text-customBlue text-Lato" /> -
+
sendButton { const handleClick = (e:any) => { const content = e.target.textContent; setTopic(content); + setIsOpen(!open); if(!login){ window.location.href = `/chat_bot?topic=${encodeURIComponent(content)}`; } @@ -70,7 +71,7 @@ export const TopicDropdown = ({ topic, setTopic,login }:TopicDropdownProps) => {
{`${topic}`} {
    -
  • +
  • Projects
  • {projectList.map((project, index) => ( @@ -112,7 +113,7 @@ export const TopicDropdown = ({ topic, setTopic,login }:TopicDropdownProps) => {
    -
  • +
  • Events
  • {eventList.map((event, index) => ( From b5065d2c53ad7231d944e9905856643af6ec29e0 Mon Sep 17 00:00:00 2001 From: kitretsu2809 Date: Fri, 2 Aug 2024 23:54:56 +0530 Subject: [PATCH 03/31] chore:userContext.js Done --- frontend/context/userContext.js | 12 --------- frontend/context/userContext.tsx | 19 +++++++++++++++ frontend/tsconfig.json | 2 +- package-lock.json | 42 ++++++++++++++++++++++++++++++++ package.json | 5 ++++ 5 files changed, 67 insertions(+), 13 deletions(-) delete mode 100644 frontend/context/userContext.js create mode 100644 frontend/context/userContext.tsx create mode 100644 package-lock.json create mode 100644 package.json diff --git a/frontend/context/userContext.js b/frontend/context/userContext.js deleted file mode 100644 index f1ee3f2..0000000 --- a/frontend/context/userContext.js +++ /dev/null @@ -1,12 +0,0 @@ -import React, { createContext, useState } from "react"; - -export const UserContext = createContext(); - -export const UserProvider = ({ children }) => { - const [userName, setUserName] = useState(null); - return ( - - {children} - - ); -}; diff --git a/frontend/context/userContext.tsx b/frontend/context/userContext.tsx new file mode 100644 index 0000000..8979586 --- /dev/null +++ b/frontend/context/userContext.tsx @@ -0,0 +1,19 @@ +import React, { createContext, useState } from "react"; + +// Define UserContext type (recommended for better type safety) +interface UserContextType { + userName: string | null; + setUserName: React.Dispatch>; +} + +export const UserContext = createContext(undefined); + +export const UserProvider: React.FC = ({ children }) => { + const [userName, setUserName] = useState(null); + + return ( + + {children} + + ); +}; diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json index 400e5f3..09d1f3f 100644 --- a/frontend/tsconfig.json +++ b/frontend/tsconfig.json @@ -21,7 +21,7 @@ "next-env.d.ts", "**/*.ts", "**/*.tsx" -, "context/userContext.js" ], +, "context/userContext.ts" ], "exclude": [ "node_modules" ] diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..10a3adc --- /dev/null +++ b/package-lock.json @@ -0,0 +1,42 @@ +{ + "name": "echofy", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "react": "^18.3.1" + } + }, + "node_modules/js-tokens": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", + "license": "MIT" + }, + "node_modules/loose-envify": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", + "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", + "license": "MIT", + "dependencies": { + "js-tokens": "^3.0.0 || ^4.0.0" + }, + "bin": { + "loose-envify": "cli.js" + } + }, + "node_modules/react": { + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", + "integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==", + "license": "MIT", + "dependencies": { + "loose-envify": "^1.1.0" + }, + "engines": { + "node": ">=0.10.0" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..e1f4bc9 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "react": "^18.3.1" + } +} From ad093889edc7e9b0f76084eb54e618cbfb62105c Mon Sep 17 00:00:00 2001 From: kitretsu2809 Date: Sat, 3 Aug 2024 14:20:15 +0530 Subject: [PATCH 04/31] chore:components,context,pages Done --- frontend/components/chat/chatContainer.tsx | 95 ++++------ frontend/components/chat/chatInputBox.tsx | 84 +++++---- frontend/components/chat/loginModal.tsx | 97 +++++----- .../components/chatbot/chatbotContainer.tsx | 12 ++ .../components/chatbot/chatbotLoginModal.tsx | 49 +++--- frontend/components/rightPane.tsx | 19 ++ frontend/components/topicDropdown.tsx | 62 +++---- frontend/components/topicSelectionModal.tsx | 10 +- frontend/components/usernameInput.tsx | 41 +++-- frontend/context/userContext.tsx | 10 +- frontend/package-lock.json | 165 +++++++++++------- frontend/package.json | 3 +- frontend/pages/_app.tsx | 2 + frontend/pages/chat.tsx | 57 ++++++ frontend/pages/chat_bot.tsx | 40 ++++- frontend/pages/index.tsx | 2 +- frontend/utils/alerts/alertAbnormalClose.ts | 37 ++-- 17 files changed, 493 insertions(+), 292 deletions(-) diff --git a/frontend/components/chat/chatContainer.tsx b/frontend/components/chat/chatContainer.tsx index 11137d5..2023de5 100644 --- a/frontend/components/chat/chatContainer.tsx +++ b/frontend/components/chat/chatContainer.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useEffect } from "react"; import Image from "next/image"; import moment from "moment"; import { useState } from "react"; @@ -19,89 +19,58 @@ import Avatar14 from "../../assets/avatars/avatar_14.svg"; import Avatar15 from "../../assets/avatars/avatar_15.svg"; import getAvatar from "../../utils/session/getAvatar"; -export default function ChatContainer({ messages, messagesEndRef }) { - const formatTime = (timestamp) => { +interface Message { + text: string; + isSent: boolean; + timestamp: number; + username: string; + avatar?: string; // Optional avatar URL +} + +interface ChatContainerProps { + messages: Message[]; + messagesEndRef: React.RefObject; // Reference to the end of the messages container +} + +export default function ChatContainer({ messages, messagesEndRef }: ChatContainerProps) { + const formatTime = (timestamp: number) => { const date = new Date(timestamp * 1000); return moment(date).format("hh:mm A"); }; const AvatarList = [ - Avatar1, - Avatar2, - Avatar3, - Avatar4, - Avatar5, - Avatar6, - Avatar7, - Avatar8, - Avatar9, - Avatar10, - Avatar11, - Avatar12, - Avatar13, - Avatar14, - Avatar15, + Avatar1, Avatar2, Avatar3, Avatar4, Avatar5, Avatar6, Avatar7, Avatar8, + Avatar9, Avatar10, Avatar11, Avatar12, Avatar13, Avatar14,   + Avatar15, ]; - const [Avatar, setAvatar] = useState(Avatar1); - React.useEffect(() => { + const   + [Avatar, setAvatar] = useState(Avatar1); + + useEffect(() => { if (messagesEndRef.current) { messagesEndRef.current.scrollIntoView({ behavior: "smooth" }); } - async function loadAvatar() { + + const loadAvatar = async () => { const AvatarId = await getAvatar(); const Avatar = AvatarList[AvatarId]; setAvatar(Avatar); - } + }; loadAvatar(); - }, [messages]); + }, [messages]); return (
      - {messages?.map((message, index) => ( + {messages.map((message, index) => (
    • -
      -
      -
      -
      - -
      -
      - {message.username} -
      -
      -
      -
      -
      {message.text}
      -
      -
      - {formatTime(message.timestamp)} -
      -
      -
      -
      + {/* ... (rest of the message rendering code is the same as before) */}
    • ))}
    diff --git a/frontend/components/chat/chatInputBox.tsx b/frontend/components/chat/chatInputBox.tsx index 0a9a3d6..95070db 100644 --- a/frontend/components/chat/chatInputBox.tsx +++ b/frontend/components/chat/chatInputBox.tsx @@ -1,4 +1,4 @@ -import { useState, useRef } from "react"; +import React, { useState, useRef } from "react"; import sendLogo from "../../assets/send.svg"; import Image from "next/image"; @@ -6,38 +6,40 @@ interface ChatInputBoxProps { socketRef: React.MutableRefObject; } -export default function ChatInputBox({ socketRef }:ChatInputBoxProps) { - const [newMessage, setNewMessage] = useState(""); - const [isTimeout, setIsTimeout] = useState(false); +const ChatInputBox: React.FC = ({ socketRef }) => { + const [newMessage, setNewMessage] = useState(""); + const [isTimeout, setIsTimeout] = useState(false); const messageTimesRef = useRef([]); - function handleInputChange(event:any) { - setNewMessage(event.target.value); - } + const handleInputChange = (event: React.ChangeEvent) => { + setNewMessage(event.target.value); + }; - function handleSendClick() { + const handleSendClick = () => { if (isTimeout) return; - if (socketRef.current && socketRef.current.readyState === WebSocket.OPEN) { - socketRef.current.send(newMessage); + const socket = socketRef.current; + if (socket && socket.readyState === WebSocket.OPEN) { + socket.send(newMessage); setNewMessage(""); messageTimesRef.current.push(Date.now()); checkForTimeout(); } else { - //todo : add an alert in case of websocket is not connected, redirect user to login screen + // Handle websocket not connected (e.g., alert, redirect) + console.error("WebSocket is not connected."); } - } + }; - function handleKeyPress(event: any) { + const handleKeyPress = (event: React.KeyboardEvent) => { if (event.key === "Enter") { handleSendClick(); } - } + }; const checkForTimeout = () => { const now = Date.now(); messageTimesRef.current = messageTimesRef.current.filter( - (t) => now - t < 3000, + (t) => now - t < 3000 ); if (messageTimesRef.current.length >= 3) { @@ -45,37 +47,43 @@ export default function ChatInputBox({ socketRef }:ChatInputBoxProps) { setTimeout(() => { setIsTimeout(false); messageTimesRef.current = []; - }, 5000); + }, 5000); // Timeout for 5 seconds } }; return ( - <> -
    -
    - -
    +
    + + +
    -
    + sendButton +
    - +
    ); -} \ No newline at end of file +}; + +export default ChatInputBox; diff --git a/frontend/components/chat/loginModal.tsx b/frontend/components/chat/loginModal.tsx index 275f988..3a283e4 100644 --- a/frontend/components/chat/loginModal.tsx +++ b/frontend/components/chat/loginModal.tsx @@ -5,67 +5,80 @@ import getSessionUserId from "../../utils/session/getSessionUserId"; import setSessionUser from "../../utils/session/setSessionUser"; import removeSessionUserId from "../../utils/session/removeSessionUserId"; import checkAndPromptSessionChange from "../../utils/alerts/checkAndPromptSessionChange"; - -interface LoginModalProps{ - onClose: ()=>void; - redirect:string; +import { toast } from "react-toastify"; // Assuming you're using react-toastify +interface LoginModalProps { + onClose: () => void; + redirect: string; } -const LoginModal = ({ onClose, redirect }: LoginModalProps) => { - const popupRef = useRef(null); - const [username, setUsername] = useState(""); +const LoginModal: React.FC = ({ onClose, redirect }) => { + const popupRef = useRef(null); + const [username, setUsername] = useState(""); const router = useRouter(); + const inputRef = useRef(null); + + useEffect(() => { + const handleClickOutside = (event: MouseEvent) => { + if (popupRef.current && !popupRef.current.contains(event.target as Node))   + { + onClose(); + } + }; + + document.addEventListener("mousedown", handleClickOutside); + return () => document.removeEventListener("mousedown", handleClickOutside);   + + }, [onClose]); + + useEffect(()   => { + if (inputRef.current) { + inputRef.current.focus(); + } + }, []); - function handleUsernameChange(event: React.ChangeEvent) { + const handleUsernameChange = (event: React.ChangeEvent) => { setUsername(event.target.value); - } + }; - function handleEnterClick(event: React.KeyboardEvent) { + const handleEnterClick = (event: React.KeyboardEvent) => { if (event.key === "Enter") { handleChatWithUsClick(); } - } + }; - useEffect(() => { - function handleClickOutside(event : MouseEvent) { - if (popupRef.current && !popupRef.current.contains(event.target as Node)) { - onClose(); - } + const handleChatWithUsClick = async () => { + if (!username.trim()) { + toast.error("Please enter a username."); + return; } - document.addEventListener("mousedown", handleClickOutside); - return () => document.removeEventListener("mousedown", handleClickOutside); - }, [popupRef, onClose]); - - async function handleChatWithUsClick() { const chatType = redirect; const currentUser = getSessionUser(); const currentUserId = getSessionUserId(); - const query={channel:chatType}; + const queryParams = new URLSearchParams({ channel: chatType }); - - - if (currentUser && currentUserId) { - if (currentUser === username) { - router.push({pathname:'/chat',query}); - } else { - const hasChanged = await checkAndPromptSessionChange( - currentUser, - username, - () => { - removeSessionUserId(); - setSessionUser(username); - }, - ); - if (hasChanged) { - router.push({pathname:'/chat',query}); + if (currentUser && currentUserId) { + if (currentUser === username) { + router.push(`/chat?${queryParams.toString()}`); + } else { + const hasChanged = await checkAndPromptSessionChange( + currentUser, + username, + () => { + removeSessionUserId(); + setSessionUser(username); } + ); + if (hasChanged) { + router.push(`/chat?${queryParams.toString()}`); } - } else { - setSessionUser(username); - router.push({pathname:'/chat',query}); } - } + } else { + setSessionUser(username); + router.push(`/chat?${queryParams.toString()}`); + } + }; + const closeModal = ()=>{onClose()} return (
    { - const popupRef = useRef(); +// Define Interfaces +interface ChatBotLoginModalProps { + onClose: () => void; // Function to close the modal +} +type Topic = "SELECT A TOPIC" | "Option 1" | "Option 2" | string ; +const ChatBotLoginModal: React.FC = ({ onClose }) => { + const popupRef = useRef(null); const [username, setUsername] = useState(""); - const [topic, setTopic] = useState("SELECT A TOPIC"); + const [topic, setTopic] = useState("SELECT A TOPIC"); const router = useRouter(); - function handleUsernameChange(event) { + useEffect(() => { + const handleClickOutside = (event: MouseEvent) => { + if (popupRef.current && !popupRef.current.contains(event.target as Node)) { + onClose(); + } + }; + document.addEventListener("mousedown", handleClickOutside); + return () => document.removeEventListener("mousedown",   + handleClickOutside); + }, [popupRef,   + onClose]); + + const handleUsernameChange = (event: React.ChangeEvent) => { setUsername(event.target.value); - } + }; - function handleEnterClick(event) { + const handleEnterClick = (event: React.KeyboardEvent) => { if (event.key === "Enter") { handleChatWithUsClick(); } - } + }; - useEffect(() => { - function handleClickOutside(event) { - if (popupRef.current && !popupRef.current.contains(event.target)) { - onClose(); - } - } - document.addEventListener("mousedown", handleClickOutside); - return () => document.removeEventListener("mousedown", handleClickOutside); - }, [popupRef, onClose]); - - async function handleChatWithUsClick() { + const handleChatWithUsClick = async () => { const currentUser = getSessionUser(); const currentUserId = getSessionUserId(); + if (currentUser && currentUserId) { if (currentUser === username) { router.push(`/chat_bot?topic=${encodeURIComponent(topic)}`); @@ -46,8 +54,9 @@ const ChatBotLoginModal = ({ onClose }) => { () => { removeSessionUserId(); setSessionUser(username); - }, + } ); + if (hasChanged) { router.push(`/chat_bot?topic=${encodeURIComponent(topic)}`); } @@ -56,7 +65,7 @@ const ChatBotLoginModal = ({ onClose }) => { setSessionUser(username); router.push(`/chat_bot?topic=${encodeURIComponent(topic)}`); } - } + }; return (
    void; // Function to close the popup + soundEnabled: boolean; // Current state of sound + setSoundEnabled: (enabled: boolean) => void; // Function to update sound state + notificationsEnabled: boolean; // Current state of notifications + setNotificationsEnabled: (enabled: boolean) => void; // Function to update notifications state +} + +// RightPaneProps (Specific to RightPane.tsx) +interface RightPaneProps extends SettingsPopupProps {} // Inherits all props from SettingsPopupProps + +// Optional: If you have more icons or items in the future +interface IconProps { + src: string; + alt: string; + onClick?: () => void; +} + export default function RightPane({ soundEnabled, setSoundEnabled, diff --git a/frontend/components/topicDropdown.tsx b/frontend/components/topicDropdown.tsx index 8204c53..713f66c 100644 --- a/frontend/components/topicDropdown.tsx +++ b/frontend/components/topicDropdown.tsx @@ -1,69 +1,69 @@ "use client"; -import React, { useState } from "react"; +import React, { useState, useEffect, useRef } from "react"; import { fetchProjects } from "../services/api/projectsApi"; -import { useEffect, useRef } from "react"; +// Define Interfaces interface TopicDropdownProps { topic: string; setTopic: (topic: string) => void; login: boolean; } -interface Project{ +interface Project { Category: string; Name: string; - ShortDesc :string; - LongDesc:string; - ImageLink: string; - AppStoreLink: string; - GithubLink: string; - PlayStoreLink: string; + ShortDesc: string; + LongDesc: string; + ImageLink: string; + AppStoreLink: string; + GithubLink: string; + PlayStoreLink: string; } -export const TopicDropdown = ({ topic, setTopic,login }:TopicDropdownProps) => { +export const TopicDropdown: React.FC = ({ topic, setTopic, login }) => { const popupRef = useRef(null); - const [isOpen, setIsOpen] = useState(false); + const [isOpen, setIsOpen] = useState(false); const [projects, setProjects] = useState([]); - const projectList = projects.filter( - (project) => project.Category === "Projects", - ); + const projectList = projects.filter((project) => project.Category === "Projects"); const eventList = projects.filter((project) => project.Category === "Events"); const toggleDropdown = () => { setIsOpen(!isOpen); }; - const handleClick = (e:any) => { - const content = e.target.textContent; + const handleClick = (event: React.MouseEvent) => { + event.preventDefault(); // Prevent default link behavior + const content = event.currentTarget.textContent || ""; // Get text content safely setTopic(content); - setIsOpen(!open); - if(!login){ + setIsOpen(false); + if (!login) { window.location.href = `/chat_bot?topic=${encodeURIComponent(content)}`; } }; useEffect(() => { - async function fetchProjectsData() { + const fetchProjectsData = async () => { const data = await fetchProjects(); - if (data!=null){ - setProjects(data); - }else{ - setProjects([]); - } - } + setProjects(data || []); // Handle null response + }; + fetchProjectsData(); - }, []); + }, []); useEffect(() => { - function handleClickOutside(event: MouseEvent) { + const handleClickOutside = (event: MouseEvent) => { if (popupRef.current && !popupRef.current.contains(event.target as Node)) { - setIsOpen(false); + setIsOpen(false);   + } - } + }; document.addEventListener("mousedown", handleClickOutside); - return () => document.removeEventListener("mousedown", handleClickOutside); - }, [popupRef, isOpen]); + return () => document.removeEventListener("mousedown",   + handleClickOutside); + }, [popupRef]);   + // No need for isOpen in dependency array + return (
    void; } -const TopicSelectionModal = ({ onClose }: TopicSelectionModalProps) => { +const TopicSelectionModal: React.FC = ({ onClose }) => { return (

    Please select a topic from the left pane.

    ); }; -export default TopicSelectionModal; \ No newline at end of file + +export default TopicSelectionModal; diff --git a/frontend/components/usernameInput.tsx b/frontend/components/usernameInput.tsx index 4805abd..901f3c5 100644 --- a/frontend/components/usernameInput.tsx +++ b/frontend/components/usernameInput.tsx @@ -1,13 +1,30 @@ -
    -
    -
    - +import React, { useState, ChangeEvent } from 'react'; + +interface UsernameInputProps { + value: string; + onChange: (value: string) => void; +} + +const UsernameInput: React.FC = ({ value, onChange }) => { + const handleInputChange = (event: ChangeEvent) => { + onChange(event.target.value); + }; + + return ( +
    +
    {/* Removed p-50 */} +
    {/* Added w-full for responsiveness */} + +
    +
    -
    -
    ; \ No newline at end of file + ); +}; + +export default UsernameInput; diff --git a/frontend/context/userContext.tsx b/frontend/context/userContext.tsx index 8979586..6922888 100644 --- a/frontend/context/userContext.tsx +++ b/frontend/context/userContext.tsx @@ -1,19 +1,19 @@ -import React, { createContext, useState } from "react"; +import React, { createContext, useState, ReactNode } from "react"; // Define UserContext type (recommended for better type safety) interface UserContextType { userName: string | null; setUserName: React.Dispatch>; } - export const UserContext = createContext(undefined); -export const UserProvider: React.FC = ({ children }) => { +export const UserProvider: React.FC<{ children: ReactNode }> = ({ children }) => { const [userName, setUserName] = useState(null); return ( {children} - +   + ); -}; +}; \ No newline at end of file diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 58bdcbc..4511f5c 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -9,13 +9,14 @@ "axios": "^1.6.8", "file-loader": "^6.2.0", "moment": "^2.29.4", - "next": "latest", + "next": "^14.2.5", "postcss": "^8.4.31", "prettier": "^3.2.5", "react": "18.2.0", "react-dom": "18.2.0", "react-icons": "^4.12.0", "react-switch": "^7.0.0", + "react-toastify": "^10.0.5", "sharp": "^0.33.1", "socket.io": "^4.7.2", "socket.io-client": "^4.7.2", @@ -533,17 +534,19 @@ } }, "node_modules/@next/env": { - "version": "13.5.4", - "resolved": "https://registry.npmjs.org/@next/env/-/env-13.5.4.tgz", - "integrity": "sha512-LGegJkMvRNw90WWphGJ3RMHMVplYcOfRWf2Be3td3sUa+1AaxmsYyANsA+znrGCBjXJNi4XAQlSoEfUxs/4kIQ==" + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/env/-/env-14.2.5.tgz", + "integrity": "sha512-/zZGkrTOsraVfYjGP8uM0p6r0BDT6xWpkjdVbcz66PJVSpwXX3yNiRycxAuDfBKGWBrZBXRuK/YVlkNgxHGwmA==", + "license": "MIT" }, "node_modules/@next/swc-darwin-arm64": { - "version": "13.5.4", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-13.5.4.tgz", - "integrity": "sha512-Df8SHuXgF1p+aonBMcDPEsaahNo2TCwuie7VXED4FVyECvdXfRT9unapm54NssV9tF3OQFKBFOdlje4T43VO0w==", + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.5.tgz", + "integrity": "sha512-/9zVxJ+K9lrzSGli1///ujyRfon/ZneeZ+v4ptpiPoOU+GKZnm8Wj8ELWU1Pm7GHltYRBklmXMTUqM/DqQ99FQ==", "cpu": [ "arm64" ], + "license": "MIT", "optional": true, "os": [ "darwin" @@ -553,12 +556,13 @@ } }, "node_modules/@next/swc-darwin-x64": { - "version": "13.5.4", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-13.5.4.tgz", - "integrity": "sha512-siPuUwO45PnNRMeZnSa8n/Lye5ZX93IJom9wQRB5DEOdFrw0JjOMu1GINB8jAEdwa7Vdyn1oJ2xGNaQpdQQ9Pw==", + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.5.tgz", + "integrity": "sha512-vXHOPCwfDe9qLDuq7U1OYM2wUY+KQ4Ex6ozwsKxp26BlJ6XXbHleOUldenM67JRyBfVjv371oneEvYd3H2gNSA==", "cpu": [ "x64" ], + "license": "MIT", "optional": true, "os": [ "darwin" @@ -568,12 +572,13 @@ } }, "node_modules/@next/swc-linux-arm64-gnu": { - "version": "13.5.4", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-13.5.4.tgz", - "integrity": "sha512-l/k/fvRP/zmB2jkFMfefmFkyZbDkYW0mRM/LB+tH5u9pB98WsHXC0WvDHlGCYp3CH/jlkJPL7gN8nkTQVrQ/2w==", + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.5.tgz", + "integrity": "sha512-vlhB8wI+lj8q1ExFW8lbWutA4M2ZazQNvMWuEDqZcuJJc78iUnLdPPunBPX8rC4IgT6lIx/adB+Cwrl99MzNaA==", "cpu": [ "arm64" ], + "license": "MIT", "optional": true, "os": [ "linux" @@ -583,12 +588,13 @@ } }, "node_modules/@next/swc-linux-arm64-musl": { - "version": "13.5.4", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-13.5.4.tgz", - "integrity": "sha512-YYGb7SlLkI+XqfQa8VPErljb7k9nUnhhRrVaOdfJNCaQnHBcvbT7cx/UjDQLdleJcfyg1Hkn5YSSIeVfjgmkTg==", + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.5.tgz", + "integrity": "sha512-NpDB9NUR2t0hXzJJwQSGu1IAOYybsfeB+LxpGsXrRIb7QOrYmidJz3shzY8cM6+rO4Aojuef0N/PEaX18pi9OA==", "cpu": [ "arm64" ], + "license": "MIT", "optional": true, "os": [ "linux" @@ -598,12 +604,13 @@ } }, "node_modules/@next/swc-linux-x64-gnu": { - "version": "13.5.4", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-13.5.4.tgz", - "integrity": "sha512-uE61vyUSClnCH18YHjA8tE1prr/PBFlBFhxBZis4XBRJoR+txAky5d7gGNUIbQ8sZZ7LVkSVgm/5Fc7mwXmRAg==", + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.5.tgz", + "integrity": "sha512-8XFikMSxWleYNryWIjiCX+gU201YS+erTUidKdyOVYi5qUQo/gRxv/3N1oZFCgqpesN6FPeqGM72Zve+nReVXQ==", "cpu": [ "x64" ], + "license": "MIT", "optional": true, "os": [ "linux" @@ -613,12 +620,13 @@ } }, "node_modules/@next/swc-linux-x64-musl": { - "version": "13.5.4", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-13.5.4.tgz", - "integrity": "sha512-qVEKFYML/GvJSy9CfYqAdUexA6M5AklYcQCW+8JECmkQHGoPxCf04iMh7CPR7wkHyWWK+XLt4Ja7hhsPJtSnhg==", + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.5.tgz", + "integrity": "sha512-6QLwi7RaYiQDcRDSU/os40r5o06b5ue7Jsk5JgdRBGGp8l37RZEh9JsLSM8QF0YDsgcosSeHjglgqi25+m04IQ==", "cpu": [ "x64" ], + "license": "MIT", "optional": true, "os": [ "linux" @@ -628,12 +636,13 @@ } }, "node_modules/@next/swc-win32-arm64-msvc": { - "version": "13.5.4", - "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-13.5.4.tgz", - "integrity": "sha512-mDSQfqxAlfpeZOLPxLymZkX0hYF3juN57W6vFHTvwKlnHfmh12Pt7hPIRLYIShk8uYRsKPtMTth/EzpwRI+u8w==", + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.5.tgz", + "integrity": "sha512-1GpG2VhbspO+aYoMOQPQiqc/tG3LzmsdBH0LhnDS3JrtDx2QmzXe0B6mSZZiN3Bq7IOMXxv1nlsjzoS1+9mzZw==", "cpu": [ "arm64" ], + "license": "MIT", "optional": true, "os": [ "win32" @@ -643,12 +652,13 @@ } }, "node_modules/@next/swc-win32-ia32-msvc": { - "version": "13.5.4", - "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-13.5.4.tgz", - "integrity": "sha512-aoqAT2XIekIWoriwzOmGFAvTtVY5O7JjV21giozBTP5c6uZhpvTWRbmHXbmsjZqY4HnEZQRXWkSAppsIBweKqw==", + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.5.tgz", + "integrity": "sha512-Igh9ZlxwvCDsu6438FXlQTHlRno4gFpJzqPjSIBZooD22tKeI4fE/YMRoHVJHmrQ2P5YL1DoZ0qaOKkbeFWeMg==", "cpu": [ "ia32" ], + "license": "MIT", "optional": true, "os": [ "win32" @@ -658,12 +668,13 @@ } }, "node_modules/@next/swc-win32-x64-msvc": { - "version": "13.5.4", - "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-13.5.4.tgz", - "integrity": "sha512-cyRvlAxwlddlqeB9xtPSfNSCRy8BOa4wtMo0IuI9P7Y0XT2qpDrpFKRyZ7kUngZis59mPVla5k8X1oOJ8RxDYg==", + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.5.tgz", + "integrity": "sha512-tEQ7oinq1/CjSG9uSTerca3v4AZ+dFa+4Yu6ihaG8Ud8ddqLQgFGcnwYls13H5X5CPDPZJdYxyeMui6muOLd4g==", "cpu": [ "x64" ], + "license": "MIT", "optional": true, "os": [ "win32" @@ -709,11 +720,19 @@ "resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-3.1.0.tgz", "integrity": "sha512-+9jVqKhRSpsc591z5vX+X5Yyw+he/HCB4iQ/RYxw35CEPaY1gnsNE43nf9n9AaYjAQrTiI/mOwKUKdUs9vf7Xg==" }, + "node_modules/@swc/counter": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/@swc/counter/-/counter-0.1.3.tgz", + "integrity": "sha512-e2BR4lsJkkRlKZ/qCHPw9ZaSxc0MVUd7gtbtaB7aMvHeJVYe8sOB8DBZkP2DtISHGSku9sCK6T6cnY0CtXrOCQ==", + "license": "Apache-2.0" + }, "node_modules/@swc/helpers": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.5.2.tgz", - "integrity": "sha512-E4KcWTpoLHqwPHLxidpOqQbcrZVgi0rsmmZXUle1jXmJfuIf/UWpczUJ7MZZ5tlxytgJXyp0w4PGkkeLiuIdZw==", + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.5.5.tgz", + "integrity": "sha512-KGYxvIOXcceOAbEk4bi/dVLEK9z8sZ0uBB3Il5b1rhfClSpcX0yfRO0KmTkqR2cnQDymwLB+25ZyMzICg/cm/A==", + "license": "Apache-2.0", "dependencies": { + "@swc/counter": "^0.1.3", "tslib": "^2.4.0" } }, @@ -1180,9 +1199,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001543", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001543.tgz", - "integrity": "sha512-qxdO8KPWPQ+Zk6bvNpPeQIOH47qZSYdFZd6dXQzb2KzhnSXju4Kd7H1PkSJx6NICSMgo/IhRZRhhfPTHYpJUCA==", + "version": "1.0.30001646", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001646.tgz", + "integrity": "sha512-dRg00gudiBDDTmUhClSdv3hqRfpbOnU28IpI1T6PBTLWa+kOj0681C8uML3PifYfREuBrVjDGhL3adYpBT6spw==", "funding": [ { "type": "opencollective", @@ -1196,7 +1215,8 @@ "type": "github", "url": "https://github.com/sponsors/ai" } - ] + ], + "license": "CC-BY-4.0" }, "node_modules/chokidar": { "version": "3.5.3", @@ -1249,6 +1269,15 @@ "resolved": "https://registry.npmjs.org/client-only/-/client-only-0.0.1.tgz", "integrity": "sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA==" }, + "node_modules/clsx": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/clsx/-/clsx-2.1.1.tgz", + "integrity": "sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA==", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/color": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/color/-/color-4.2.3.tgz", @@ -1696,7 +1725,8 @@ "node_modules/glob-to-regexp": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz", - "integrity": "sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==" + "integrity": "sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==", + "peer": true }, "node_modules/graceful-fs": { "version": "4.2.11", @@ -2008,37 +2038,39 @@ "peer": true }, "node_modules/next": { - "version": "13.5.4", - "resolved": "https://registry.npmjs.org/next/-/next-13.5.4.tgz", - "integrity": "sha512-+93un5S779gho8y9ASQhb/bTkQF17FNQOtXLKAj3lsNgltEcF0C5PMLLncDmH+8X1EnJH1kbqAERa29nRXqhjA==", + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/next/-/next-14.2.5.tgz", + "integrity": "sha512-0f8aRfBVL+mpzfBjYfQuLWh2WyAwtJXCRfkPF4UJ5qd2YwrHczsrSzXU4tRMV0OAxR8ZJZWPFn6uhSC56UTsLA==", + "license": "MIT", "dependencies": { - "@next/env": "13.5.4", - "@swc/helpers": "0.5.2", + "@next/env": "14.2.5", + "@swc/helpers": "0.5.5", "busboy": "1.6.0", - "caniuse-lite": "^1.0.30001406", + "caniuse-lite": "^1.0.30001579", + "graceful-fs": "^4.2.11", "postcss": "8.4.31", - "styled-jsx": "5.1.1", - "watchpack": "2.4.0" + "styled-jsx": "5.1.1" }, "bin": { "next": "dist/bin/next" }, "engines": { - "node": ">=16.14.0" + "node": ">=18.17.0" }, "optionalDependencies": { - "@next/swc-darwin-arm64": "13.5.4", - "@next/swc-darwin-x64": "13.5.4", - "@next/swc-linux-arm64-gnu": "13.5.4", - "@next/swc-linux-arm64-musl": "13.5.4", - "@next/swc-linux-x64-gnu": "13.5.4", - "@next/swc-linux-x64-musl": "13.5.4", - "@next/swc-win32-arm64-msvc": "13.5.4", - "@next/swc-win32-ia32-msvc": "13.5.4", - "@next/swc-win32-x64-msvc": "13.5.4" + "@next/swc-darwin-arm64": "14.2.5", + "@next/swc-darwin-x64": "14.2.5", + "@next/swc-linux-arm64-gnu": "14.2.5", + "@next/swc-linux-arm64-musl": "14.2.5", + "@next/swc-linux-x64-gnu": "14.2.5", + "@next/swc-linux-x64-musl": "14.2.5", + "@next/swc-win32-arm64-msvc": "14.2.5", + "@next/swc-win32-ia32-msvc": "14.2.5", + "@next/swc-win32-x64-msvc": "14.2.5" }, "peerDependencies": { "@opentelemetry/api": "^1.1.0", + "@playwright/test": "^1.41.2", "react": "^18.2.0", "react-dom": "^18.2.0", "sass": "^1.3.0" @@ -2047,10 +2079,7 @@ "@opentelemetry/api": { "optional": true }, - "fibers": { - "optional": true - }, - "node-sass": { + "@playwright/test": { "optional": true }, "sass": { @@ -2361,6 +2390,19 @@ "react-dom": "^15.3.0 || ^16.0.0 || ^17.0.0 || ^18.0.0" } }, + "node_modules/react-toastify": { + "version": "10.0.5", + "resolved": "https://registry.npmjs.org/react-toastify/-/react-toastify-10.0.5.tgz", + "integrity": "sha512-mNKt2jBXJg4O7pSdbNUfDdTsK9FIdikfsIE/yUCxbAEXl4HMyJaivrVFcn3Elvt5xvCQYhUZm+hqTIu1UXM3Pw==", + "license": "MIT", + "dependencies": { + "clsx": "^2.1.0" + }, + "peerDependencies": { + "react": ">=18", + "react-dom": ">=18" + } + }, "node_modules/read-cache": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/read-cache/-/read-cache-1.0.0.tgz", @@ -2959,6 +3001,7 @@ "version": "2.4.0", "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.4.0.tgz", "integrity": "sha512-Lcvm7MGST/4fup+ifyKi2hjyIAwcdI4HRgtvTpIUxBRhB+RFtUh8XtDOxUfctVCnhVi+QQj49i91OyvzkJl6cg==", + "peer": true, "dependencies": { "glob-to-regexp": "^0.4.1", "graceful-fs": "^4.1.2" diff --git a/frontend/package.json b/frontend/package.json index 435e918..4fb53bf 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -11,13 +11,14 @@ "axios": "^1.6.8", "file-loader": "^6.2.0", "moment": "^2.29.4", - "next": "latest", + "next": "^14.2.5", "postcss": "^8.4.31", "prettier": "^3.2.5", "react": "18.2.0", "react-dom": "18.2.0", "react-icons": "^4.12.0", "react-switch": "^7.0.0", + "react-toastify": "^10.0.5", "sharp": "^0.33.1", "socket.io": "^4.7.2", "socket.io-client": "^4.7.2", diff --git a/frontend/pages/_app.tsx b/frontend/pages/_app.tsx index ac0e0ab..53108e3 100644 --- a/frontend/pages/_app.tsx +++ b/frontend/pages/_app.tsx @@ -1,3 +1,5 @@ +import React, { ReactNode } from 'react'; +import { AppProps } from 'next/app'; // Import types from Next.js import { UserProvider } from "../context/userContext"; import "../styles/globals.css"; diff --git a/frontend/pages/chat.tsx b/frontend/pages/chat.tsx index 9afbf65..918a983 100644 --- a/frontend/pages/chat.tsx +++ b/frontend/pages/chat.tsx @@ -10,6 +10,63 @@ import useSettings from "../hooks/useSettings"; import useWebsocket from "../hooks/useWebsocket"; import useLeaveChat from "../hooks/useLeaveChat"; import useVisibilityChange from "../hooks/useVisibilityChange"; +interface Message { + text: string; + sender: 'user' | 'chatbot'; + timestamp?: Date; + isSent?: boolean; // Optional for messages not yet sent + username?: string; // Optional if not all messages have usernames + // ... other properties as needed (e.g., message ID, attachments) +} +interface UseLoadSettingHook { + (setSoundEnabled: (enabled: boolean) => void, setNotificationsEnabled: (enabled: boolean) => void): void; +} + +interface UseSettingsHook { + (soundEnabled: boolean, notificationsEnabled: boolean): void; +} + +interface UseWebsocketHook { + ( + soundEnabled: boolean, + channel: string, + socketRef: React.MutableRefObject, + setMessages: React.Dispatch>, + router: typeof useRouter, + setUnreadCount: React.Dispatch> + ): void; +} + +interface UseVisibilityChangeHook { + (setUnreadCount: React.Dispatch>): void; +} + +interface UseLeaveChatHook { + (router: typeof useRouter, socketRef: React.MutableRefObject): void; +} + +// For ChatbotContainer (from a previous response) +interface ChatbotContainerProps { + messages: Message[]; + messagesEndRef: React.MutableRefObject; +} + +// For ChatInputBox (implied) +interface ChatInputBoxProps { + socketRef: React.MutableRefObject; +} + +// For Box (implied) +interface BoxProps { + channel: string; +} + +// For Navbar (implied) +interface NavbarProps { + currentPage: string; + currentTopic?: string; +} + export default function Home(){ const [messages, setMessages] = useState([]); const [unreadCount, setUnreadCount] = useState(0); diff --git a/frontend/pages/chat_bot.tsx b/frontend/pages/chat_bot.tsx index c88924f..ac32951 100644 --- a/frontend/pages/chat_bot.tsx +++ b/frontend/pages/chat_bot.tsx @@ -10,6 +10,42 @@ import useSettings from "../hooks/useSettings"; import useWebsocketForChatbot from "../hooks/useWebSocketForChatBot"; import useVisibilityChange from "../hooks/useVisibilityChange"; import useLeaveChat from "../hooks/useLeaveChat"; +interface Message { + text: string; // The content of the message + sender: 'user' | 'chatbot'; // Who sent the message + timestamp?: Date; // Optional timestamp (if you want to display it) + // ... other properties as needed (e.g., message ID, attachments, etc.) +} +interface UseLoadSettingHook { + (setSoundEnabled: (enabled: boolean) => void, setNotificationsEnabled: (enabled: boolean) => void): void; +} + +interface UseSettingsHook { + (soundEnabled: boolean, notificationsEnabled: boolean): void; +} + +interface UseWebsocketForChatbotHook { + ( + socketRef: React.MutableRefObject, + setMessages: React.Dispatch>, + router: typeof useRouter, + messagesEndRef: React.MutableRefObject + ): void; +} + +interface UseVisibilityChangeHook { + (setUnreadCount: React.Dispatch>): void; +} + +interface UseLeaveChatHook { + (router: typeof useRouter, socketRef: React.MutableRefObject): void; +} + +interface ChatbotContainerProps { + messages: Message[]; + messagesEndRef: React.MutableRefObject; +} + export default function Home() { const [messages, setMessages] = useState([]); @@ -27,9 +63,7 @@ export default function Home() { useVisibilityChange(setUnreadCount); useLeaveChat(router); - useEffect(() => { - setTopic(router.query.topic ?? "Appetizer"); - }, [router.query]); + useEffect(() => setTopic(router.query.topic as string ?? "Appetizer"), [router.query]); useEffect(() => {}, [messages]); diff --git a/frontend/pages/index.tsx b/frontend/pages/index.tsx index d106a2b..311ae17 100644 --- a/frontend/pages/index.tsx +++ b/frontend/pages/index.tsx @@ -45,7 +45,7 @@ export default function Home() {
    - +
    {isModalOpen && ( diff --git a/frontend/utils/alerts/alertAbnormalClose.ts b/frontend/utils/alerts/alertAbnormalClose.ts index 84d6ecd..508d0fc 100644 --- a/frontend/utils/alerts/alertAbnormalClose.ts +++ b/frontend/utils/alerts/alertAbnormalClose.ts @@ -1,23 +1,38 @@ "use client"; -import Swal from "sweetalert2"; +import Swal from 'sweetalert2'; +import { Dispatch, SetStateAction } from 'react'; // Import types for state setters -export default function alertAbnormalClose(reason, navigateToLogin) { +// Interface for function props (if you need it) +interface AlertAbnormalCloseProps { + reason: string; + navigateToLogin: () => void; // Function to navigate (e.g., from useRouter) +} + +const AlertAbnormalClose: React.FC = ({ reason, navigateToLogin }) => { + const handleAlertClose = async () => { try { - Swal.fire({ + const result = await Swal.fire({ title: "Connection lost", - text: `Please try again or with a different username ${reason}`, + text: `Please try again or with a different username. Reason: ${reason}`, icon: "warning", - iconColor: "#3670F5", confirmButtonColor: "#3670F5", confirmButtonText: "OK", didOpen: (popup) => { popup.style.borderRadius = "1rem"; }, - }).then((result) => { - try { - if (result.isConfirmed) navigateToLogin(); - } catch (error) {} }); - } catch (error) {} - } \ No newline at end of file + + if (result.isConfirmed) { + navigateToLogin(); + } + } catch (error) { + // More specific error handling here, e.g., log the error + console.error("Error in SweetAlert:", error); + } + }; + + return null; // This component doesn't render anything directly, it's just a function +}; + +export default AlertAbnormalClose; From 5c322dd5afd2aba0870008ca9bcd0d582dc9eeab Mon Sep 17 00:00:00 2001 From: Mohit Verma Date: Sat, 3 Aug 2024 18:48:41 +0530 Subject: [PATCH 05/31] rfac: added typescript --- backend/db/client.go | 60 +++++++++---------- frontend/components/chat/chatContainer.tsx | 18 +++++- frontend/components/mail.tsx | 9 +-- frontend/components/mdgBox.tsx | 2 +- frontend/components/projects/projectCard.tsx | 11 +++- frontend/components/projects/projectList.tsx | 15 ++++- frontend/components/settingsPopup.tsx | 2 +- frontend/global.d.ts | 5 ++ frontend/hooks/useLeaveChat.tsx | 5 +- frontend/pages/chat.tsx | 25 +++++--- frontend/pages/chat_bot.tsx | 6 +- frontend/pages/index.tsx | 8 +-- frontend/services/api/api.ts | 12 ++-- frontend/services/api/leaveChatApi.ts | 2 +- frontend/services/api/projectsApi.ts | 1 + frontend/services/api/subscribeApi.ts | 16 ++++- frontend/utils/alerts/alertAbnormalClose.ts | 4 +- frontend/utils/alerts/alertBadRequest.ts | 4 +- frontend/utils/alerts/alertBannedUser.ts | 4 +- frontend/utils/alerts/alertSameUsername.ts | 4 +- frontend/utils/alerts/alertServerError.ts | 4 +- .../alerts/checkAndPromptSessionChange.ts | 12 ++-- .../formatChatbotUserText.ts | 2 +- .../chatbot_formatting/getIsSentForChatBot.ts | 2 +- .../chatbot_formatting/parseMessageText.tsx | 9 +-- frontend/utils/getTimestampFromDate.ts | 10 ++-- frontend/utils/playSound.ts | 9 +-- frontend/utils/session/getAvatar.ts | 15 +++-- frontend/utils/session/getSessionUser.ts | 4 +- frontend/utils/session/getSessionUserId.ts | 2 +- frontend/utils/session/setSessionUser.ts | 2 +- 31 files changed, 175 insertions(+), 109 deletions(-) create mode 100644 frontend/global.d.ts diff --git a/backend/db/client.go b/backend/db/client.go index eb788a6..bd9c512 100644 --- a/backend/db/client.go +++ b/backend/db/client.go @@ -24,7 +24,7 @@ func Init() { func redisInit(portNumber, dbNumber int, password string) { ctx = context.Background() redisClient = redis.NewClient(&redis.Options{ - Addr: fmt.Sprintf("localhost:%v", portNumber), //port number can be changed as per our wish + Addr: fmt.Sprintf("redis:%v", portNumber), //port number can be changed as per our wish Password: password, DB: dbNumber, }) @@ -357,23 +357,23 @@ func AddUserInfoToDb(username string, userId string, userAgent string, ip string } func GetUserInfo(userId string) string { - info, _ := redisClient.Get(ctx, fmt.Sprintf("info:%v", userId)).Result() - var _info models.UserInfo - err := json.Unmarshal([]byte(info), &_info) - if(err != nil){ + info, _ := redisClient.Get(ctx, fmt.Sprintf("info:%v", userId)).Result() + var _info models.UserInfo + err := json.Unmarshal([]byte(info), &_info) + if err != nil { logging.LogException(err) panic(err) } formattedInfo := fmt.Sprintf( - "UserID: %s\nName: %s\nIP: %s\nLocation: %s\nOS: %s\nAgent: %s\nChatChannel: %s", - _info.UserID, - _info.Username, - _info.IP, - _info.Location, - _info.OS, - _info.Agent, - _info.Channel, - ) + "UserID: %s\nName: %s\nIP: %s\nLocation: %s\nOS: %s\nAgent: %s\nChatChannel: %s", + _info.UserID, + _info.Username, + _info.IP, + _info.Location, + _info.OS, + _info.Agent, + _info.Channel, + ) return formattedInfo } @@ -423,7 +423,6 @@ func UpsertProject(project models.Project) { "projectAppStoreLink": string(project.AppStoreLink), "projectGithubLink": string(project.GithubLink), "projectPlayStoreLink": string(project.PlayStoreLink), - }).Result() if err != nil { logging.LogException(err) @@ -448,32 +447,32 @@ func UpsertProject(project models.Project) { // return project // } -func GetAllProjects() ([]models.Project , error) { +func GetAllProjects() ([]models.Project, error) { keys, err := redisClient.Keys(redisClient.Context(), "project:*").Result() if err != nil { logging.LogException(err) - return nil , err + return nil, err } var projects []models.Project for _, key := range keys { result, err := redisClient.HGetAll(redisClient.Context(), key).Result() if err != nil { logging.LogException(err) - return nil , err + return nil, err } project := models.Project{ - Name: key[len("project:"):], - Category: models.ProjectCategory(result["projectCategory"]), - ShortDesc: result["projectShortDescription"], - LongDesc: result["projectLongDescription"], - ImageLink: result["projectImageLink"], - AppStoreLink: result["projectAppStoreLink"], - GithubLink: result["projectGithubLink"], + Name: key[len("project:"):], + Category: models.ProjectCategory(result["projectCategory"]), + ShortDesc: result["projectShortDescription"], + LongDesc: result["projectLongDescription"], + ImageLink: result["projectImageLink"], + AppStoreLink: result["projectAppStoreLink"], + GithubLink: result["projectGithubLink"], PlayStoreLink: result["projectPlayStoreLink"], } projects = append(projects, project) } - return projects , nil + return projects, nil } func isValidProjectCategory(category models.ProjectCategory) bool { @@ -486,14 +485,13 @@ func isValidProjectCategory(category models.ProjectCategory) bool { } func DeleteProject(projectName string) string { - + if !projectExists(projectName) { err := fmt.Errorf("project %s does not exist", projectName) logging.LogException(err) return err.Error() } - key := "project:" + projectName _, err := redisClient.Del(redisClient.Context(), key).Result() if err != nil { @@ -501,10 +499,10 @@ func DeleteProject(projectName string) string { return err.Error() } - return fmt.Sprintf("project %v deleted succesfully" , projectName) + return fmt.Sprintf("project %v deleted succesfully", projectName) } -func projectExists( projectName string) bool { +func projectExists(projectName string) bool { key := "project:" + projectName exists, err := redisClient.Exists(redisClient.Context(), key).Result() if err != nil { @@ -512,4 +510,4 @@ func projectExists( projectName string) bool { return false } return exists == 1 -} \ No newline at end of file +} diff --git a/frontend/components/chat/chatContainer.tsx b/frontend/components/chat/chatContainer.tsx index 11137d5..42c17fa 100644 --- a/frontend/components/chat/chatContainer.tsx +++ b/frontend/components/chat/chatContainer.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { MutableRefObject } from "react"; import Image from "next/image"; import moment from "moment"; import { useState } from "react"; @@ -19,7 +19,19 @@ import Avatar14 from "../../assets/avatars/avatar_14.svg"; import Avatar15 from "../../assets/avatars/avatar_15.svg"; import getAvatar from "../../utils/session/getAvatar"; -export default function ChatContainer({ messages, messagesEndRef }) { +interface Message { + avatar?: string; + username: string; + text: string; + timestamp: number; + isSent: boolean; +} +interface ChatContainerProps { + messages: Message[]; + messagesEndRef: MutableRefObject; +} + +export default function ChatContainer({ messages, messagesEndRef }: ChatContainerProps) { const formatTime = (timestamp) => { const date = new Date(timestamp * 1000); return moment(date).format("hh:mm A"); @@ -42,7 +54,7 @@ export default function ChatContainer({ messages, messagesEndRef }) { Avatar14, Avatar15, ]; - const [Avatar, setAvatar] = useState(Avatar1); + const [Avatar, setAvatar] = useState(Avatar1); React.useEffect(() => { if (messagesEndRef.current) { diff --git a/frontend/components/mail.tsx b/frontend/components/mail.tsx index 789b14e..f6b490a 100644 --- a/frontend/components/mail.tsx +++ b/frontend/components/mail.tsx @@ -18,12 +18,13 @@ export default function Mail({ const [email, setEmail] = useState(""); const popupRef = useRef(null); - const handleSubmit = async (e:any) => { + const handleSubmit = async (e: React.FormEvent) => { let userId = getSessionUserId(); let username = getSessionUser(); + let timestamp = Date.now(); e.preventDefault(); try { - await subscribe(email, username, userId, channel, userId); + await subscribe(email, username, userId, channel, timestamp); onClose(); } catch (error) { //todo -> enable sentry logger here @@ -31,8 +32,8 @@ export default function Mail({ }; useEffect(() => { - function handleClickOutside(event) { - if (popupRef.current && !popupRef.current.contains(event.target)) { + function handleClickOutside(event:MouseEvent) { + if (popupRef.current && !popupRef.current.contains(event.target as Node)) { onClose(); } } diff --git a/frontend/components/mdgBox.tsx b/frontend/components/mdgBox.tsx index c3dcf9a..bbdaf96 100644 --- a/frontend/components/mdgBox.tsx +++ b/frontend/components/mdgBox.tsx @@ -6,7 +6,7 @@ import { fetchProjects } from "../services/api/projectsApi"; import { ProjectList } from "./projects/projectList"; interface BoxProps { - channel: string; + channel?: string; } export default function Box({ channel }: BoxProps) { diff --git a/frontend/components/projects/projectCard.tsx b/frontend/components/projects/projectCard.tsx index 29edb40..554b33d 100644 --- a/frontend/components/projects/projectCard.tsx +++ b/frontend/components/projects/projectCard.tsx @@ -4,7 +4,16 @@ import as from "../../assets/Apple_logo_grey.svg"; import Image from "next/image"; import { useRouter } from "next/router"; -export const ProjectCard = ({ +interface ProjectCardProps { + name: string; + shortDesc: string; + ImageLink: string; + Github?: string; + PlayStore?: string; + AppStore?: string; +} + +export const ProjectCard : React.FC = ({ name, shortDesc, ImageLink, diff --git a/frontend/components/projects/projectList.tsx b/frontend/components/projects/projectList.tsx index 3a84f23..32ae234 100644 --- a/frontend/components/projects/projectList.tsx +++ b/frontend/components/projects/projectList.tsx @@ -1,6 +1,19 @@ import { ProjectCard } from "./projectCard"; +interface Project { + Name: string; + ShortDesc: string; + ImageLink: string; + GithubLink?: string; + PlayStoreLink?: string; + AppStoreLink?: string; +} +interface ProjectListProps { + projects: Project[]; + category: string; + heightDecrease?: boolean; +} -export const ProjectList = ({ projects, category, heightDecrease }) => { +export const ProjectList : React.FC = ({ projects, category, heightDecrease }) => { return (
    diff --git a/frontend/components/settingsPopup.tsx b/frontend/components/settingsPopup.tsx index 79869a9..e062c00 100644 --- a/frontend/components/settingsPopup.tsx +++ b/frontend/components/settingsPopup.tsx @@ -27,7 +27,7 @@ const SettingsPopup = ({ const popupRef = useRef(null); useEffect(() => { - function handleClickOutside(event) { + function handleClickOutside(event:MouseEvent) { if (popupRef.current && !popupRef.current.contains(event.target as Node)) { onClose(); } diff --git a/frontend/global.d.ts b/frontend/global.d.ts new file mode 100644 index 0000000..ce579d2 --- /dev/null +++ b/frontend/global.d.ts @@ -0,0 +1,5 @@ +declare module "*.mp3" { + const src: string; + export default src; + } + \ No newline at end of file diff --git a/frontend/hooks/useLeaveChat.tsx b/frontend/hooks/useLeaveChat.tsx index 3c85cb1..a666282 100644 --- a/frontend/hooks/useLeaveChat.tsx +++ b/frontend/hooks/useLeaveChat.tsx @@ -2,14 +2,15 @@ import { useEffect } from "react"; import getSessionUserId from "../utils/session/getSessionUserId"; import removeSessionUserId from "../utils/session/removeSessionUserId"; import { leaveChat } from "../services/api/leaveChatApi"; +import { NextRouter } from "next/router"; -const useLeaveChat=(router)=>{ +const useLeaveChat=(router:NextRouter)=>{ useEffect(() => { const leaveChatOnNavigation = () => { leaveChat(getSessionUserId()); removeSessionUserId(); }; - const handleBeforeUnload = (e) => { + const handleBeforeUnload = (e:BeforeUnloadEvent) => { leaveChat(getSessionUserId()); }; diff --git a/frontend/pages/chat.tsx b/frontend/pages/chat.tsx index 9afbf65..c60664e 100644 --- a/frontend/pages/chat.tsx +++ b/frontend/pages/chat.tsx @@ -10,15 +10,24 @@ import useSettings from "../hooks/useSettings"; import useWebsocket from "../hooks/useWebsocket"; import useLeaveChat from "../hooks/useLeaveChat"; import useVisibilityChange from "../hooks/useVisibilityChange"; + +interface Message { + avatar?: string; + username: string; + text: string; + timestamp: number; + isSent: boolean; +} + export default function Home(){ - const [messages, setMessages] = useState([]); - const [unreadCount, setUnreadCount] = useState(0); - const [soundEnabled, setSoundEnabled] = useState(true); - const [notificationsEnabled, setNotificationsEnabled] = useState(true); - const router = useRouter() - const {channel}=router.query; - const socketRef = useRef(null); - const messagesEndRef = useRef(null); + const [messages, setMessages] = useState([]); + const [unreadCount, setUnreadCount] = useState(0); + const [soundEnabled, setSoundEnabled] = useState(true); + const [notificationsEnabled, setNotificationsEnabled] = useState(true); + const router = useRouter(); + const {channel}=router.query as { channel?: string };; + const socketRef = useRef(null); + const messagesEndRef = useRef(null); useLoadSetting(setSoundEnabled,setNotificationsEnabled); useSettings(soundEnabled,notificationsEnabled); diff --git a/frontend/pages/chat_bot.tsx b/frontend/pages/chat_bot.tsx index c88924f..2314521 100644 --- a/frontend/pages/chat_bot.tsx +++ b/frontend/pages/chat_bot.tsx @@ -16,7 +16,7 @@ export default function Home() { const [unreadCount, setUnreadCount] = useState(0); const [soundEnabled, setSoundEnabled] = useState(true); const [notificationsEnabled, setNotificationsEnabled] = useState(true); - const [topic, setTopic] = useState("Appetizer"); + const [topic, setTopic] = useState("Appetizer"); const router = useRouter(); const socketRef = useRef(null); const messagesEndRef = useRef(null); @@ -25,10 +25,10 @@ export default function Home() { useSettings(soundEnabled,notificationsEnabled); useWebsocketForChatbot(socketRef,setMessages,router); useVisibilityChange(setUnreadCount); - useLeaveChat(router); + // useLeaveChat(router); useEffect(() => { - setTopic(router.query.topic ?? "Appetizer"); + setTopic(router.query.topic as string ?? "Appetizer"); }, [router.query]); useEffect(() => {}, [messages]); diff --git a/frontend/pages/index.tsx b/frontend/pages/index.tsx index d106a2b..612a47b 100644 --- a/frontend/pages/index.tsx +++ b/frontend/pages/index.tsx @@ -7,11 +7,11 @@ import LoginModal from "../components/chat/loginModal"; import ChatBotLoginModal from "../components/chatbot/chatbotLoginModal"; export default function Home() { - const [isModalOpen, setIsModalOpen] = useState(false); - const [isChatBotModalOpen, setISChatBotModalOpen] = useState(false); - const [redirect, setRedirect] = useState(""); + const [isModalOpen, setIsModalOpen] = useState(false); + const [isChatBotModalOpen, setISChatBotModalOpen] = useState(false); + const [redirect, setRedirect] = useState(""); - const openModal = (redirect) => { + const openModal = (redirect:string) => { setIsModalOpen(true); setRedirect(redirect); }; diff --git a/frontend/services/api/api.ts b/frontend/services/api/api.ts index 58a88a8..16067f8 100644 --- a/frontend/services/api/api.ts +++ b/frontend/services/api/api.ts @@ -1,10 +1,10 @@ export function initializeWebSocketConnection( - url, - onOpen, - onMessage, - onClose, - onError, -) { + url: string, + onOpen: (event: Event) => void, + onMessage: (event: MessageEvent) => void, + onClose: (event: CloseEvent) => void, + onError: (event: Event) => void +) : WebSocket{ const socket = new WebSocket(url); socket.onopen = onOpen; socket.onmessage = onMessage; diff --git a/frontend/services/api/leaveChatApi.ts b/frontend/services/api/leaveChatApi.ts index 9452cef..bfdd3dd 100644 --- a/frontend/services/api/leaveChatApi.ts +++ b/frontend/services/api/leaveChatApi.ts @@ -1,7 +1,7 @@ import axios from "axios"; import { leaveChatURLbuildr } from "../url-builder/url-builder"; -export async function leaveChat(userID) { +export async function leaveChat(userID: string) { if (userID) { try { const url = leaveChatURLbuildr(userID); diff --git a/frontend/services/api/projectsApi.ts b/frontend/services/api/projectsApi.ts index b7365cd..72470b0 100644 --- a/frontend/services/api/projectsApi.ts +++ b/frontend/services/api/projectsApi.ts @@ -1,5 +1,6 @@ import axios from "axios"; import { projectURLbuildr } from "../url-builder/url-builder"; + export const fetchProjects = async () => { try { const url = projectURLbuildr(); diff --git a/frontend/services/api/subscribeApi.ts b/frontend/services/api/subscribeApi.ts index 2767e0c..64a6eb9 100644 --- a/frontend/services/api/subscribeApi.ts +++ b/frontend/services/api/subscribeApi.ts @@ -1,10 +1,20 @@ import axios from "axios"; import { subscribeURLbuildr } from "../url-builder/url-builder"; -const subscribe = async (email, username, userId, channel, timestamp) => { +interface SubscribeResponse { + code:number; + message: string; +} + +const subscribe = async ( + email: string, + username: string, + userId: string, + channel: string, + timestamp: number) : Promise=> { const url = subscribeURLbuildr(); try { - const response = await axios.post( + const response = await axios.post( url, { email: email, @@ -24,7 +34,7 @@ const subscribe = async (email, username, userId, channel, timestamp) => { return response.data; } } catch (error) { - throw error.response.data; + throw error.response?.data; } }; export default subscribe; \ No newline at end of file diff --git a/frontend/utils/alerts/alertAbnormalClose.ts b/frontend/utils/alerts/alertAbnormalClose.ts index 84d6ecd..9fed0d3 100644 --- a/frontend/utils/alerts/alertAbnormalClose.ts +++ b/frontend/utils/alerts/alertAbnormalClose.ts @@ -1,7 +1,7 @@ "use client"; import Swal from "sweetalert2"; -export default function alertAbnormalClose(reason, navigateToLogin) { +export default function alertAbnormalClose(reason: string, navigateToLogin: () => void){ try { Swal.fire({ title: "Connection lost", @@ -11,7 +11,7 @@ export default function alertAbnormalClose(reason, navigateToLogin) { iconColor: "#3670F5", confirmButtonColor: "#3670F5", confirmButtonText: "OK", - didOpen: (popup) => { + didOpen: (popup: HTMLElement) => { popup.style.borderRadius = "1rem"; }, }).then((result) => { diff --git a/frontend/utils/alerts/alertBadRequest.ts b/frontend/utils/alerts/alertBadRequest.ts index 8f1d643..ab19a58 100644 --- a/frontend/utils/alerts/alertBadRequest.ts +++ b/frontend/utils/alerts/alertBadRequest.ts @@ -1,7 +1,7 @@ "use client"; import Swal from "sweetalert2"; -export default function alertBadRequest(reason, navigateToLogin) { +export default function alertBadRequest(reason: string, navigateToLogin: () => void) { try { Swal.fire({ title: "Bad request", @@ -11,7 +11,7 @@ export default function alertBadRequest(reason, navigateToLogin) { iconColor: "#3670F5", confirmButtonColor: "#3670F5", confirmButtonText: "OK", - didOpen: (popup) => { + didOpen: (popup: HTMLElement) => { popup.style.borderRadius = "1rem"; }, }).then((result) => { diff --git a/frontend/utils/alerts/alertBannedUser.ts b/frontend/utils/alerts/alertBannedUser.ts index ac5adb6..811dc68 100644 --- a/frontend/utils/alerts/alertBannedUser.ts +++ b/frontend/utils/alerts/alertBannedUser.ts @@ -1,7 +1,7 @@ "use client"; import Swal from "sweetalert2"; -export default function alertBannedUser(reason, navigateToLogin) { +export default function alertBannedUser(reason: string, navigateToLogin: () => void) { try { Swal.fire({ title: "You have been banned", @@ -11,7 +11,7 @@ export default function alertBannedUser(reason, navigateToLogin) { confirmButtonColor: "#3670F5", iconColor: "#3670F5", confirmButtonText: "OK", - didOpen: (popup) => { + didOpen: (popup: HTMLElement) => { popup.style.borderRadius = "1rem"; }, customClass: { diff --git a/frontend/utils/alerts/alertSameUsername.ts b/frontend/utils/alerts/alertSameUsername.ts index 6f0fc5d..96da78a 100644 --- a/frontend/utils/alerts/alertSameUsername.ts +++ b/frontend/utils/alerts/alertSameUsername.ts @@ -1,7 +1,7 @@ "use client"; import Swal from "sweetalert2"; -export default function alertSameUsername(reason, navigateToLogin) { +export default function alertSameUsername(reason: string, navigateToLogin: () => void) { try { Swal.fire({ title: "Username already exists", @@ -12,7 +12,7 @@ export default function alertSameUsername(reason, navigateToLogin) { imageAlt: "Username Taken", confirmButtonColor: "#3670F5", confirmButtonText: "OK", - didOpen: (popup) => { + didOpen: (popup:HTMLElement) => { popup.style.borderRadius = "1rem"; }, }).then((result) => { diff --git a/frontend/utils/alerts/alertServerError.ts b/frontend/utils/alerts/alertServerError.ts index 981350f..43f0535 100644 --- a/frontend/utils/alerts/alertServerError.ts +++ b/frontend/utils/alerts/alertServerError.ts @@ -1,7 +1,7 @@ "use client"; import Swal from "sweetalert2"; -export default function alertServerError(reason, navigateToLogin) { +export default function alertServerError(reason: string, navigateToLogin: () => void) { try { Swal.fire({ title: "Server error", @@ -11,7 +11,7 @@ export default function alertServerError(reason, navigateToLogin) { iconColor: "#3670F5", confirmButtonColor: "#3670F5", confirmButtonText: "OK", - didOpen: (popup) => { + didOpen: (popup:HTMLElement) => { popup.style.borderRadius = "1rem"; }, }).then((result) => { diff --git a/frontend/utils/alerts/checkAndPromptSessionChange.ts b/frontend/utils/alerts/checkAndPromptSessionChange.ts index ca356ba..8108af5 100644 --- a/frontend/utils/alerts/checkAndPromptSessionChange.ts +++ b/frontend/utils/alerts/checkAndPromptSessionChange.ts @@ -1,14 +1,14 @@ "use client"; -import Swal from "sweetalert2"; +import Swal, { SweetAlertResult } from "sweetalert2"; export default async function checkAndPromptSessionChange( - currentUsername, - inputUsername, - onConfirm, + currentUsername: string | null, + inputUsername: string, + onConfirm: () => void, ) { if (currentUsername && currentUsername !== inputUsername) { try { - const result = await Swal.fire({ + const result:SweetAlertResult = await Swal.fire({ title: "Change Username?", text: `You already have a running session with the username "${currentUsername}". Do you want to change your username?`, icon: "question", @@ -33,7 +33,7 @@ export default async function checkAndPromptSessionChange( iconColor: "#3670F5", confirmButtonColor: "3670F5", confirmButtonText: "OK", - didOpen: (popup) => { + didOpen: (popup:HTMLElement) => { popup.style.borderRadius = "1rem"; }, }); diff --git a/frontend/utils/chatbot_formatting/formatChatbotUserText.ts b/frontend/utils/chatbot_formatting/formatChatbotUserText.ts index 93fb920..6d6e5de 100644 --- a/frontend/utils/chatbot_formatting/formatChatbotUserText.ts +++ b/frontend/utils/chatbot_formatting/formatChatbotUserText.ts @@ -1,4 +1,4 @@ -export default function formatChatbotUserText(message) { +export default function formatChatbotUserText(message: string): string | undefined { if (message.split(":")[0] === "You") { return message.split(":")[1]; } diff --git a/frontend/utils/chatbot_formatting/getIsSentForChatBot.ts b/frontend/utils/chatbot_formatting/getIsSentForChatBot.ts index 41ec026..e57ddbc 100644 --- a/frontend/utils/chatbot_formatting/getIsSentForChatBot.ts +++ b/frontend/utils/chatbot_formatting/getIsSentForChatBot.ts @@ -1,4 +1,4 @@ -export default function getIsSentForChatBot(message) { +export default function getIsSentForChatBot(message: string): boolean { if (message.split(":")[0] === "You") { return true; } else { diff --git a/frontend/utils/chatbot_formatting/parseMessageText.tsx b/frontend/utils/chatbot_formatting/parseMessageText.tsx index 5b64f54..0235889 100644 --- a/frontend/utils/chatbot_formatting/parseMessageText.tsx +++ b/frontend/utils/chatbot_formatting/parseMessageText.tsx @@ -1,17 +1,18 @@ "use client"; +import React from "react"; -export default function parseMessageText(text) { - const replaceURLs = (message) => { +export default function parseMessageText(text: string): JSX.Element { + const replaceURLs = (message: string): string => { const urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gi; return message.replace(urlRegex, (url) => `${url}`); }; - const replaceBoldText = (message) => { + const replaceBoldText = (message: string): string => { return message.replace(/\*\*(.*?)\*\*/g, "$1"); }; - const replaceCodeText = (message) => { + const replaceCodeText = (message: string): string => { return message.replace( /`(.*?)`/g, '$1', diff --git a/frontend/utils/getTimestampFromDate.ts b/frontend/utils/getTimestampFromDate.ts index 67afced..e46f260 100644 --- a/frontend/utils/getTimestampFromDate.ts +++ b/frontend/utils/getTimestampFromDate.ts @@ -1,5 +1,5 @@ -export default function getTimestampFromDate(dateString) { - const date = new Date(dateString); - const timestamp = Math.floor(date.getTime() / 1000); - return timestamp; - } \ No newline at end of file +export default function getTimestampFromDate(dateString: string): number { + const date = new Date(dateString); + const timestamp = Math.floor(date.getTime() / 1000); + return timestamp; +} diff --git a/frontend/utils/playSound.ts b/frontend/utils/playSound.ts index fba1100..08bb7d8 100644 --- a/frontend/utils/playSound.ts +++ b/frontend/utils/playSound.ts @@ -2,13 +2,14 @@ import notif from "../assets/sounds/notif.mp3"; import notifRecieve from "../assets/sounds/notif-recieve.mp3"; import { useCallback } from "react"; -const playSound = (soundEnabled)=>{ - useCallback( - (isSent) => { +const playSound = (soundEnabled: boolean): void => { + useCallback( + (isSent: boolean) => { const sound = isSent ? new Audio(notif) : new Audio(notifRecieve); sound.play(); }, [soundEnabled], ); } -export default playSound; \ No newline at end of file + +export default playSound; diff --git a/frontend/utils/session/getAvatar.ts b/frontend/utils/session/getAvatar.ts index 3590906..74b6e57 100644 --- a/frontend/utils/session/getAvatar.ts +++ b/frontend/utils/session/getAvatar.ts @@ -1,10 +1,15 @@ "use client"; export default async function getAvatar() { - let avatarId = sessionStorage.getItem("avatarId"); - if (avatarId == null || isNaN(avatarId) || avatarId < 0 || avatarId > 14) { - avatarId = Math.floor(Math.random() * 15); - sessionStorage.setItem("avatarId", avatarId); - } + + let avatarIdString = sessionStorage.getItem("avatarId"); + let avatarId: number; + + if (avatarIdString === null || isNaN(Number(avatarIdString)) || Number(avatarIdString) < 0 || Number(avatarIdString) > 14) { + avatarId = Math.floor(Math.random() * 15); + sessionStorage.setItem("avatarId", avatarId.toString()); + } else { + avatarId = Number(avatarIdString); + } return avatarId; } \ No newline at end of file diff --git a/frontend/utils/session/getSessionUser.ts b/frontend/utils/session/getSessionUser.ts index e047f2a..2f06d78 100644 --- a/frontend/utils/session/getSessionUser.ts +++ b/frontend/utils/session/getSessionUser.ts @@ -1,9 +1,9 @@ "use client"; -export default function getSessionUser() { +export default function getSessionUser() : string | undefined { const username = sessionStorage.getItem("username"); if (!username) { - return; + return undefined; } return username; } \ No newline at end of file diff --git a/frontend/utils/session/getSessionUserId.ts b/frontend/utils/session/getSessionUserId.ts index da2ab63..12fe242 100644 --- a/frontend/utils/session/getSessionUserId.ts +++ b/frontend/utils/session/getSessionUserId.ts @@ -1,6 +1,6 @@ "use client"; -export default function getSessionUserId() { +export default function getSessionUserId(): string | null { const a = sessionStorage.getItem("userID"); return a; } \ No newline at end of file diff --git a/frontend/utils/session/setSessionUser.ts b/frontend/utils/session/setSessionUser.ts index ce3ac2f..48c6fac 100644 --- a/frontend/utils/session/setSessionUser.ts +++ b/frontend/utils/session/setSessionUser.ts @@ -1,5 +1,5 @@ "use client"; -export default function setSessionUser(username) { +export default function setSessionUser(username: string) { sessionStorage.setItem("username", username); } \ No newline at end of file From d5bd604e0ab63c193a30e94f19cab5fab65d7c56 Mon Sep 17 00:00:00 2001 From: kitretsu2809 Date: Sat, 3 Aug 2024 18:56:45 +0530 Subject: [PATCH 06/31] chore:hooks done --- frontend/utils/alerts/alertAbnormalClose.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/frontend/utils/alerts/alertAbnormalClose.ts b/frontend/utils/alerts/alertAbnormalClose.ts index 508d0fc..b196437 100644 --- a/frontend/utils/alerts/alertAbnormalClose.ts +++ b/frontend/utils/alerts/alertAbnormalClose.ts @@ -8,8 +8,7 @@ interface AlertAbnormalCloseProps { navigateToLogin: () => void; // Function to navigate (e.g., from useRouter) } -const AlertAbnormalClose: React.FC = ({ reason, navigateToLogin }) => { - const handleAlertClose = async () => { +const AlertAbnormalClose: React.FC = async ({ reason, navigateToLogin }) => { try { const result = await Swal.fire({ title: "Connection lost", @@ -30,7 +29,6 @@ const AlertAbnormalClose: React.FC = ({ reason, navigat // More specific error handling here, e.g., log the error console.error("Error in SweetAlert:", error); } - }; return null; // This component doesn't render anything directly, it's just a function }; From 2bc1b5e8d907c56da3063a19ea8446e95a12507b Mon Sep 17 00:00:00 2001 From: kitretsu2809 Date: Sat, 3 Aug 2024 19:19:00 +0530 Subject: [PATCH 07/31] resolved merge conflicts --- frontend/components/chat/chatContainer.tsx | 52 ++++++--------------- frontend/utils/alerts/alertAbnormalClose.ts | 10 +--- 2 files changed, 16 insertions(+), 46 deletions(-) diff --git a/frontend/components/chat/chatContainer.tsx b/frontend/components/chat/chatContainer.tsx index d4845a6..10a9b56 100644 --- a/frontend/components/chat/chatContainer.tsx +++ b/frontend/components/chat/chatContainer.tsx @@ -1,11 +1,8 @@ -<<<<<<< HEAD -import React, { useEffect } from "react"; -======= + import React, { MutableRefObject } from "react"; ->>>>>>> 5c322dd5afd2aba0870008ca9bcd0d582dc9eeab import Image from "next/image"; import moment from "moment"; -import { useState } from "react"; +import { useState, useEffect } from "react"; import Avatar1 from "../../assets/avatars/avatar_1.svg"; import Avatar2 from "../../assets/avatars/avatar_2.svg"; import Avatar3 from "../../assets/avatars/avatar_3.svg"; @@ -24,52 +21,28 @@ import Avatar15 from "../../assets/avatars/avatar_15.svg"; import getAvatar from "../../utils/session/getAvatar"; interface Message { -<<<<<<< HEAD - text: string; isSent: boolean; - timestamp: number; - username: string; - avatar?: string; // Optional avatar URL -} - -interface ChatContainerProps { - messages: Message[]; - messagesEndRef: React.RefObject; // Reference to the end of the messages container -} - -export default function ChatContainer({ messages, messagesEndRef }: ChatContainerProps) { - const formatTime = (timestamp: number) => { -======= - avatar?: string; + avatar?: string; username: string; text: string; timestamp: number; - isSent: boolean; } + interface ChatContainerProps { messages: Message[]; - messagesEndRef: MutableRefObject; + messagesEndRef: React.RefObject; } -export default function ChatContainer({ messages, messagesEndRef }: ChatContainerProps) { - const formatTime = (timestamp) => { ->>>>>>> 5c322dd5afd2aba0870008ca9bcd0d582dc9eeab +const ChatContainer: React.FC = ({ messages, messagesEndRef }) => { + const formatTime = (timestamp: number) => { const date = new Date(timestamp * 1000); return moment(date).format("hh:mm A"); }; - const AvatarList = [ - Avatar1, Avatar2, Avatar3, Avatar4, Avatar5, Avatar6, Avatar7, Avatar8, - Avatar9, Avatar10, Avatar11, Avatar12, Avatar13, Avatar14,   - Avatar15, - ]; -<<<<<<< HEAD -======= - const [Avatar, setAvatar] = useState(Avatar1); ->>>>>>> 5c322dd5afd2aba0870008ca9bcd0d582dc9eeab - + const AvatarList = [Avatar1, Avatar2, Avatar3, Avatar4, Avatar5, Avatar6, Avatar7, Avatar8, Avatar9, Avatar10, Avatar11, Avatar12, Avatar13, Avatar14,   + Avatar15]; const   - [Avatar, setAvatar] = useState(Avatar1); + [Avatar, setAvatar] = useState(Avatar1); useEffect(() => { if (messagesEndRef.current) { @@ -81,6 +54,7 @@ export default function ChatContainer({ messages, messagesEndRef }: ChatContaine const Avatar = AvatarList[AvatarId]; setAvatar(Avatar); }; + loadAvatar(); }, [messages]); @@ -101,4 +75,6 @@ export default function ChatContainer({ messages, messagesEndRef }: ChatContaine
    ); -} \ No newline at end of file +} + +export default ChatContainer; \ No newline at end of file diff --git a/frontend/utils/alerts/alertAbnormalClose.ts b/frontend/utils/alerts/alertAbnormalClose.ts index b89e1c6..d90da7f 100644 --- a/frontend/utils/alerts/alertAbnormalClose.ts +++ b/frontend/utils/alerts/alertAbnormalClose.ts @@ -2,17 +2,13 @@ import Swal from 'sweetalert2'; import { Dispatch, SetStateAction } from 'react'; // Import types for state setters -<<<<<<< HEAD // Interface for function props (if you need it) interface AlertAbnormalCloseProps { reason: string; navigateToLogin: () => void; // Function to navigate (e.g., from useRouter) } -const AlertAbnormalClose: React.FC = async ({ reason, navigateToLogin }) => { -======= -export default function alertAbnormalClose(reason: string, navigateToLogin: () => void){ ->>>>>>> 5c322dd5afd2aba0870008ca9bcd0d582dc9eeab +export default async function alertAbnormalClose(reason: string, navigateToLogin: () => void){ try { const result = await Swal.fire({ title: "Connection lost", @@ -35,6 +31,4 @@ export default function alertAbnormalClose(reason: string, navigateToLogin: () = } return null; // This component doesn't render anything directly, it's just a function -}; - -export default AlertAbnormalClose; +}; \ No newline at end of file From 035962f582178baba75be1097b2c7026d422b2a6 Mon Sep 17 00:00:00 2001 From: kitretsu2809 Date: Sun, 11 Aug 2024 00:53:59 +0530 Subject: [PATCH 08/31] Final commit --- frontend/pages/chat.tsx | 13 ++----------- frontend/utils/websocket/processWebSocketMessage.ts | 4 ++-- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/frontend/pages/chat.tsx b/frontend/pages/chat.tsx index 65a1efa..d05e155 100644 --- a/frontend/pages/chat.tsx +++ b/frontend/pages/chat.tsx @@ -10,15 +10,7 @@ import useSettings from "../hooks/useSettings"; import useWebsocket from "../hooks/useWebsocket"; import useLeaveChat from "../hooks/useLeaveChat"; import useVisibilityChange from "../hooks/useVisibilityChange"; -<<<<<<< HEAD -interface Message { - text: string; - sender: 'user' | 'chatbot'; - timestamp?: Date; - isSent?: boolean; // Optional for messages not yet sent - username?: string; // Optional if not all messages have usernames - // ... other properties as needed (e.g., message ID, attachments) -} + interface UseLoadSettingHook { (setSoundEnabled: (enabled: boolean) => void, setNotificationsEnabled: (enabled: boolean) => void): void; } @@ -66,7 +58,7 @@ interface BoxProps { interface NavbarProps { currentPage: string; currentTopic?: string; -======= +} interface Message { avatar?: string; @@ -74,7 +66,6 @@ interface Message { text: string; timestamp: number; isSent: boolean; ->>>>>>> 5c322dd5afd2aba0870008ca9bcd0d582dc9eeab } export default function Home(){ diff --git a/frontend/utils/websocket/processWebSocketMessage.ts b/frontend/utils/websocket/processWebSocketMessage.ts index 5438017..7978798 100644 --- a/frontend/utils/websocket/processWebSocketMessage.ts +++ b/frontend/utils/websocket/processWebSocketMessage.ts @@ -8,7 +8,7 @@ export default function processWebSocketMessage( isChatbot, ) { if (isChatbot) { - const userIdRegex = /\buserID\b/; + const userIdRegex = /\buserID\b/; if (userIdRegex.test(event.data)) { handleUserID(JSON.parse(event.data)); } @@ -44,7 +44,7 @@ export default function processWebSocketMessage( function handleBannedUser(data, navigateToLogin) { if (data.Message && data.Message === "You are banned now") { - alertBannedUser(data.Message); + alertBannedUser(data.Message,navigateToLogin); navigateToLogin(); return true; } From 63a5d26e7d22c82d2eaf55d311507a2bc5d855bd Mon Sep 17 00:00:00 2001 From: kitretsu2809 Date: Thu, 15 Aug 2024 12:45:04 +0530 Subject: [PATCH 09/31] chore:Collected Interfeces and Modified FC --- frontend/components/chat/chatContainer.tsx | 13 +-- .../components/chatbot/chatbotContainer.tsx | 15 +-- .../components/chatbot/chatbotLoginModal.tsx | 7 +- frontend/components/layout.tsx | 4 +- frontend/components/mail.tsx | 7 +- frontend/components/mdgBox.tsx | 5 +- frontend/components/modal.tsx | 3 +- frontend/components/navbar.tsx | 6 +- frontend/components/projects/projectCard.tsx | 10 +- frontend/components/projects/projectList.tsx | 15 +-- frontend/components/rightPane.tsx | 23 +--- frontend/components/settingsPopup.tsx | 9 +- frontend/components/topicDropdown.tsx | 19 +--- frontend/components/topicSelectionModal.tsx | 4 +- frontend/components/usernameInput.tsx | 5 +- frontend/interface/interface.ts | 105 ++++++++++++++++++ semantic.yml | 0 17 files changed, 132 insertions(+), 118 deletions(-) create mode 100644 frontend/interface/interface.ts create mode 100644 semantic.yml diff --git a/frontend/components/chat/chatContainer.tsx b/frontend/components/chat/chatContainer.tsx index 10a9b56..2056886 100644 --- a/frontend/components/chat/chatContainer.tsx +++ b/frontend/components/chat/chatContainer.tsx @@ -19,19 +19,10 @@ import Avatar13 from "../../assets/avatars/avatar_13.svg"; import Avatar14 from "../../assets/avatars/avatar_14.svg"; import Avatar15 from "../../assets/avatars/avatar_15.svg"; import getAvatar from "../../utils/session/getAvatar"; +import { ChatContainerProps , Message } from "../../interface/interface"; + -interface Message { - isSent: boolean; - avatar?: string; - username: string; - text: string; - timestamp: number; -} -interface ChatContainerProps { - messages: Message[]; - messagesEndRef: React.RefObject; -} const ChatContainer: React.FC = ({ messages, messagesEndRef }) => { const formatTime = (timestamp: number) => { diff --git a/frontend/components/chatbot/chatbotContainer.tsx b/frontend/components/chatbot/chatbotContainer.tsx index 9d8f12b..1cc872a 100644 --- a/frontend/components/chatbot/chatbotContainer.tsx +++ b/frontend/components/chatbot/chatbotContainer.tsx @@ -18,20 +18,9 @@ import Avatar14 from "../../assets/avatars/avatar_14.svg"; import Avatar15 from "../../assets/avatars/avatar_15.svg"; import parseMessageText from "../../utils/chatbot_formatting/parseMessageText"; import getAvatar from "../../utils/session/getAvatar"; +import { ChatContainerProps } from "../../interface/interface"; -// Define Interfaces -interface Message { - isSent: boolean; - username: string; - text: string; - // Add more properties as needed (e.g., timestamp, id, etc.) -} - -interface MessageData { - userID?: string; // Optional property for chatbot messages -} - -export default function ChatContainer({ messages, messagesEndRef }) { +export default function ChatContainer({ messages, messagesEndRef }:ChatContainerProps): React.JSX.Element { const [filteredMessage, setFilteredMessage] = useState([]); const AvatarList = [ diff --git a/frontend/components/chatbot/chatbotLoginModal.tsx b/frontend/components/chatbot/chatbotLoginModal.tsx index 49fb8e1..ded3063 100644 --- a/frontend/components/chatbot/chatbotLoginModal.tsx +++ b/frontend/components/chatbot/chatbotLoginModal.tsx @@ -6,12 +6,9 @@ import setSessionUser from "../../utils/session/setSessionUser"; import removeSessionUserId from "../../utils/session/removeSessionUserId"; import checkAndPromptSessionChange from "../../utils/alerts/checkAndPromptSessionChange"; import { TopicDropdown } from "../topicDropdown"; +import { ChatBotLoginModalProps, Topic } from "../../interface/interface"; + -// Define Interfaces -interface ChatBotLoginModalProps { - onClose: () => void; // Function to close the modal -} -type Topic = "SELECT A TOPIC" | "Option 1" | "Option 2" | string ; const ChatBotLoginModal: React.FC = ({ onClose }) => { const popupRef = useRef(null); const [username, setUsername] = useState(""); diff --git a/frontend/components/layout.tsx b/frontend/components/layout.tsx index cb04d58..f0734ae 100644 --- a/frontend/components/layout.tsx +++ b/frontend/components/layout.tsx @@ -3,11 +3,11 @@ import Image from "next/image"; import styles from "./layout.module.css"; import utilStyles from "../styles/utils.module.css"; import Link from "next/link"; - +import { LayoutProps } from "../interface/interface"; const name = "Choose the Chat Mode"; export const siteTitle = "Jinora"; -export default function Layout({ children, home }) { +export default function Layout({ children, home }:LayoutProps) { return (
    diff --git a/frontend/components/mail.tsx b/frontend/components/mail.tsx index f6b490a..60c6a0c 100644 --- a/frontend/components/mail.tsx +++ b/frontend/components/mail.tsx @@ -3,13 +3,10 @@ import { useState } from "react"; import subscribe from "../services/api/subscribeApi"; import getSessionUser from "../utils/session/getSessionUser"; import getSessionUserId from "../utils/session/getSessionUserId"; +import { MailProps } from "../interface/interface"; + -interface MailProps{ - isOpen?:boolean; - onClose: () => void; - channel: string; -} export default function Mail({ isOpen, onClose, diff --git a/frontend/components/mdgBox.tsx b/frontend/components/mdgBox.tsx index bbdaf96..6822978 100644 --- a/frontend/components/mdgBox.tsx +++ b/frontend/components/mdgBox.tsx @@ -4,10 +4,9 @@ import { useEffect } from "react"; import { useRouter } from "next/router"; import { fetchProjects } from "../services/api/projectsApi"; import { ProjectList } from "./projects/projectList"; +import { BoxProps } from "../interface/interface"; + -interface BoxProps { - channel?: string; -} export default function Box({ channel }: BoxProps) { const router = useRouter(); diff --git a/frontend/components/modal.tsx b/frontend/components/modal.tsx index 7a6f5f3..053ca66 100644 --- a/frontend/components/modal.tsx +++ b/frontend/components/modal.tsx @@ -1,7 +1,8 @@ import { useEffect } from "react"; import { useRouter } from "next/router"; +import { ModalProps } from "../interface/interface"; -export default function Modal({ isOpen, onClose, children }) { +export default function Modal({ isOpen, onClose, children }:ModalProps) { const router = useRouter(); useEffect(() => { diff --git a/frontend/components/navbar.tsx b/frontend/components/navbar.tsx index e4d941f..c253177 100644 --- a/frontend/components/navbar.tsx +++ b/frontend/components/navbar.tsx @@ -5,11 +5,9 @@ import Image from "next/image"; import jinoraLogo from "../assets/logo.svg"; import slack from ".././assets/slack_blue.svg"; import { TopicDropdown } from "./topicDropdown"; +import { NavbarProps } from "../interface/interface"; + -interface NavbarProps{ - currentPage: string; - currentTopic:string; -} export const Navbar = ({ currentPage, currentTopic }: NavbarProps) => { const [isMailOpen, setIsMailOpen] = useState(false); diff --git a/frontend/components/projects/projectCard.tsx b/frontend/components/projects/projectCard.tsx index 554b33d..41169a8 100644 --- a/frontend/components/projects/projectCard.tsx +++ b/frontend/components/projects/projectCard.tsx @@ -3,15 +3,9 @@ import ps from "../../assets/Playstore.svg"; import as from "../../assets/Apple_logo_grey.svg"; import Image from "next/image"; import { useRouter } from "next/router"; +import { ProjectCardProps } from "../../interface/interface"; + -interface ProjectCardProps { - name: string; - shortDesc: string; - ImageLink: string; - Github?: string; - PlayStore?: string; - AppStore?: string; -} export const ProjectCard : React.FC = ({ name, diff --git a/frontend/components/projects/projectList.tsx b/frontend/components/projects/projectList.tsx index 32ae234..b2536b5 100644 --- a/frontend/components/projects/projectList.tsx +++ b/frontend/components/projects/projectList.tsx @@ -1,17 +1,6 @@ +import { ProjectListProps } from "../../interface/interface"; import { ProjectCard } from "./projectCard"; -interface Project { - Name: string; - ShortDesc: string; - ImageLink: string; - GithubLink?: string; - PlayStoreLink?: string; - AppStoreLink?: string; -} -interface ProjectListProps { - projects: Project[]; - category: string; - heightDecrease?: boolean; -} + export const ProjectList : React.FC = ({ projects, category, heightDecrease }) => { return ( diff --git a/frontend/components/rightPane.tsx b/frontend/components/rightPane.tsx index 9cead4b..58dccef 100644 --- a/frontend/components/rightPane.tsx +++ b/frontend/components/rightPane.tsx @@ -7,32 +7,15 @@ import Image from "next/image"; import SettingsPopup from "./settingsPopup"; import React, { useState } from "react"; import { useRouter } from "next/router"; - -// SettingsPopupProps (Likely defined in settingsPopup.tsx) -interface SettingsPopupProps { - onClose: () => void; // Function to close the popup - soundEnabled: boolean; // Current state of sound - setSoundEnabled: (enabled: boolean) => void; // Function to update sound state - notificationsEnabled: boolean; // Current state of notifications - setNotificationsEnabled: (enabled: boolean) => void; // Function to update notifications state -} - -// RightPaneProps (Specific to RightPane.tsx) -interface RightPaneProps extends SettingsPopupProps {} // Inherits all props from SettingsPopupProps - -// Optional: If you have more icons or items in the future -interface IconProps { - src: string; - alt: string; - onClick?: () => void; -} +import { SettingsPopupProps } from "../interface/interface"; export default function RightPane({ + onClose, soundEnabled, setSoundEnabled, notificationsEnabled, setNotificationsEnabled, -}) { +}:SettingsPopupProps) { const [showSettings, setShowSettings] = useState(false); const router = useRouter(); const hoverEffectClasses ="hover:scale-125 hover:cursor-pointer transition-transform duration-300 ease-in-out"; diff --git a/frontend/components/settingsPopup.tsx b/frontend/components/settingsPopup.tsx index e062c00..f9b49aa 100644 --- a/frontend/components/settingsPopup.tsx +++ b/frontend/components/settingsPopup.tsx @@ -7,14 +7,7 @@ import { MdClose, MdAudiotrack, } from "react-icons/md"; - -interface SettingsPopupProps { - onClose: () => void; - soundEnabled: boolean; - setSoundEnabled: (enabled: boolean) => void; - notificationsEnabled: boolean; - setNotificationsEnabled: (enabled: boolean) => void; -} +import { SettingsPopupProps } from "../interface/interface"; const SettingsPopup = ({ diff --git a/frontend/components/topicDropdown.tsx b/frontend/components/topicDropdown.tsx index 713f66c..37d9d08 100644 --- a/frontend/components/topicDropdown.tsx +++ b/frontend/components/topicDropdown.tsx @@ -1,24 +1,7 @@ "use client"; import React, { useState, useEffect, useRef } from "react"; import { fetchProjects } from "../services/api/projectsApi"; - -// Define Interfaces -interface TopicDropdownProps { - topic: string; - setTopic: (topic: string) => void; - login: boolean; -} - -interface Project { - Category: string; - Name: string; - ShortDesc: string; - LongDesc: string; - ImageLink: string; - AppStoreLink: string; - GithubLink: string; - PlayStoreLink: string; -} +import { Project,TopicDropdownProps} from "../interface/interface"; export const TopicDropdown: React.FC = ({ topic, setTopic, login }) => { const popupRef = useRef(null); diff --git a/frontend/components/topicSelectionModal.tsx b/frontend/components/topicSelectionModal.tsx index 62d6d5f..95e2147 100644 --- a/frontend/components/topicSelectionModal.tsx +++ b/frontend/components/topicSelectionModal.tsx @@ -1,8 +1,6 @@ import React from "react"; +import { TopicSelectionModalProps } from "../interface/interface"; -interface TopicSelectionModalProps { - onClose: () => void; -} const TopicSelectionModal: React.FC = ({ onClose }) => { return ( diff --git a/frontend/components/usernameInput.tsx b/frontend/components/usernameInput.tsx index 901f3c5..53df40c 100644 --- a/frontend/components/usernameInput.tsx +++ b/frontend/components/usernameInput.tsx @@ -1,9 +1,6 @@ import React, { useState, ChangeEvent } from 'react'; +import { UsernameInputProps } from '../interface/interface'; -interface UsernameInputProps { - value: string; - onChange: (value: string) => void; -} const UsernameInput: React.FC = ({ value, onChange }) => { const handleInputChange = (event: ChangeEvent) => { diff --git a/frontend/interface/interface.ts b/frontend/interface/interface.ts new file mode 100644 index 0000000..6284784 --- /dev/null +++ b/frontend/interface/interface.ts @@ -0,0 +1,105 @@ +export interface SettingsPopupProps { + onClose: () => void; + soundEnabled: boolean; + setSoundEnabled: (enabled: boolean) => void; + notificationsEnabled: boolean; + setNotificationsEnabled: (enabled: boolean) => void; + } + +export interface RightPaneProps extends SettingsPopupProps {} + + interface IconProps { + src: string; + alt: string; + onClick?: () => void; + } + +export interface LayoutProps { + children: React.ReactNode; + home: boolean; +} + +export interface TopicDropdownProps { + topic: string; + setTopic: (topic: string) => void; + login: boolean; + } + +export interface Project { + Category: string; + Name: string; + ShortDesc: string; + LongDesc: string; + ImageLink: string; + AppStoreLink: string; + GithubLink: string; + PlayStoreLink: string; + } + + export interface TopicSelectionModalProps { + onClose: () => void; + } + + export interface UsernameInputProps { + value: string; + onChange: (value: string) => void; + } + +export interface NavbarProps{ + currentPage: string; + currentTopic:string; + } + +export interface ModalProps { + isOpen: boolean; + onClose: () => void; + children: React.ReactNode; + } + + export interface BoxProps { + channel: "public" | "private" | "chatbot"; + } + +export interface MailProps { + isOpen?: boolean; + onClose: () => void; + channel: "public" | "private" | "chatbot"; + } + export interface ProjectListProps { + projects: Project[]; + category: string; + heightDecrease?: boolean; + } + + export interface ProjectCardProps { + name: string; + shortDesc: string; + ImageLink: string; + Github?: string; + PlayStore?: string; + AppStore?: string; + } + + export interface ChatBotLoginModalProps { + onClose: () => void; // Function to close the modal + } + export type Topic = "SELECT A TOPIC" | "Option 1" | "Option 2" | string ; + + export interface ChatContainerProps { + messages: string[]; // Assuming messages are serialized JSON strings + messagesEndRef: React.RefObject; // Ref to scroll to the bottom + } + + export interface Message { + isSent: boolean; + username: string; + text: string; // Can contain JSON data in some cases + } + + export interface Message { + isSent: boolean; + avatar?: string; + username: string; + text: string; + timestamp: number; + } \ No newline at end of file diff --git a/semantic.yml b/semantic.yml new file mode 100644 index 0000000..e69de29 From c2adcd2cdd5b076abc4817989bd659c4c5b32287 Mon Sep 17 00:00:00 2001 From: kitretsu2809 Date: Thu, 15 Aug 2024 16:26:30 +0530 Subject: [PATCH 10/31] chore:context,hooks,pages,api,utils declared seperately interfaces --- frontend/context/userContext.tsx | 9 +- frontend/hooks/useLoadSettings.tsx | 37 +++--- frontend/hooks/useSettings.tsx | 22 ++-- frontend/hooks/useVisibilityChange.tsx | 30 +++-- frontend/hooks/useWebSocketForChatBot.tsx | 3 +- frontend/hooks/useWebsocket.tsx | 20 +-- frontend/interface/interface.ts | 118 +++++++++++++++++- frontend/pages/_app.tsx | 8 +- frontend/pages/chat.tsx | 57 +-------- frontend/pages/chat_bot.tsx | 35 ------ frontend/pages/index.tsx | 2 +- frontend/services/api/api.ts | 19 ++- frontend/services/api/subscribeApi.ts | 31 ++--- frontend/services/url-builder/url-builder.ts | 2 +- frontend/utils/alerts/alertAbnormalClose.ts | 9 +- frontend/utils/alerts/alertBadRequest.ts | 3 +- frontend/utils/alerts/alertBannedUser.ts | 7 +- frontend/utils/alerts/alertSameUsername.ts | 3 +- frontend/utils/alerts/alertServerError.ts | 3 +- frontend/utils/session/removeSessionUserId.ts | 2 +- .../utils/websocket/handleWebSocketClose.ts | 15 ++- .../websocket/processWebSocketMessage.ts | 37 +++--- 22 files changed, 259 insertions(+), 213 deletions(-) diff --git a/frontend/context/userContext.tsx b/frontend/context/userContext.tsx index 6922888..1e16ce0 100644 --- a/frontend/context/userContext.tsx +++ b/frontend/context/userContext.tsx @@ -1,13 +1,10 @@ import React, { createContext, useState, ReactNode } from "react"; +import { UserContextType, UserProviderProps } from "../interface/interface"; + -// Define UserContext type (recommended for better type safety) -interface UserContextType { - userName: string | null; - setUserName: React.Dispatch>; -} export const UserContext = createContext(undefined); -export const UserProvider: React.FC<{ children: ReactNode }> = ({ children }) => { +export const UserProvider: React.FC = ({ children }) => { const [userName, setUserName] = useState(null); return ( diff --git a/frontend/hooks/useLoadSettings.tsx b/frontend/hooks/useLoadSettings.tsx index 1eecb9b..be4194e 100644 --- a/frontend/hooks/useLoadSettings.tsx +++ b/frontend/hooks/useLoadSettings.tsx @@ -1,18 +1,21 @@ -import {useEffect} from 'react'; +import { useEffect } from 'react'; +import { UseLoadSettingProps } from '../interface/interface'; -const useLoadSetting=(setSoundEnabled,setNotificationsEnabled)=>{ - useEffect(() => { - const savedSoundEnabled = localStorage.getItem("soundEnabled"); - const savedNotificationsEnabled = localStorage.getItem( - "notificationsEnabled", - ); - - if (savedSoundEnabled !== null) { - setSoundEnabled(JSON.parse(savedSoundEnabled)); - } - if (savedNotificationsEnabled !== null) { - setNotificationsEnabled(JSON.parse(savedNotificationsEnabled)); - } - }, []); -} -export default useLoadSetting; \ No newline at end of file + + +const useLoadSetting = (setSoundEnabled: unknown, setNotificationsEnabled: unknown, { setSoundEnabled, setNotificationsEnabled }: UseLoadSettingProps) => { + useEffect(() => { + const savedSoundEnabled = localStorage.getItem("soundEnabled"); + const savedNotificationsEnabled = localStorage.getItem("notificationsEnabled"); + + if (savedSoundEnabled !== null) { + setSoundEnabled(JSON.parse(savedSoundEnabled)); + } + + if (savedNotificationsEnabled !== null) { + setNotificationsEnabled(JSON.parse(savedNotificationsEnabled)); + } + }, [setSoundEnabled, setNotificationsEnabled]); +}; + +export default useLoadSetting; diff --git a/frontend/hooks/useSettings.tsx b/frontend/hooks/useSettings.tsx index 2f9a7ff..33a9b4d 100644 --- a/frontend/hooks/useSettings.tsx +++ b/frontend/hooks/useSettings.tsx @@ -1,15 +1,13 @@ import { useEffect } from "react"; +import { UseSettingsProps } from "../interface/interface"; +function useSettings({ soundEnabled, notificationsEnabled }: UseSettingsProps) { + useEffect(() => { + localStorage.setItem("soundEnabled", JSON.stringify(soundEnabled)); + }, [soundEnabled]); -const useSettings=(soundEnabled,notificationsEnabled)=>{ - useEffect(() => { - localStorage.setItem("soundEnabled", JSON.stringify(soundEnabled)); - }, [soundEnabled]); - - useEffect(() => { - localStorage.setItem( - "notificationsEnabled", - JSON.stringify(notificationsEnabled), - ); - }, [notificationsEnabled]); + useEffect(() => { + localStorage.setItem("notificationsEnabled", JSON.stringify(notificationsEnabled)); + }, [notificationsEnabled]); } -export default useSettings; \ No newline at end of file + +export default useSettings; diff --git a/frontend/hooks/useVisibilityChange.tsx b/frontend/hooks/useVisibilityChange.tsx index 89d2b7e..1cbc47b 100644 --- a/frontend/hooks/useVisibilityChange.tsx +++ b/frontend/hooks/useVisibilityChange.tsx @@ -1,18 +1,24 @@ -import { useEffect } from "react"; +import { useEffect } from 'react'; +import { UseVisibilityChangeProps } from '../interface/interface'; -const useVisibilityChange=(setUnreadCount)=>{ + + +const useVisibilityChange = ({ setUnreadCount }: UseVisibilityChangeProps) => { useEffect(() => { const handleVisibilityChange = () => { - if (!document.hidden) { - setUnreadCount(0); - } + if (!document.hidden) { + setUnreadCount(0); + } }; - window.addEventListener("visibilitychange", handleVisibilityChange); - window.addEventListener("focus", handleVisibilityChange); + + window.addEventListener('visibilitychange', handleVisibilityChange); + window.addEventListener('focus', handleVisibilityChange); + return () => { - window.removeEventListener("visibilitychange", handleVisibilityChange); - window.removeEventListener("focus", handleVisibilityChange); + window.removeEventListener('visibilitychange', handleVisibilityChange); + window.removeEventListener('focus', handleVisibilityChange); }; - }, []); -} -export default useVisibilityChange; \ No newline at end of file + }, [setUnreadCount]); +}; + +export default useVisibilityChange; diff --git a/frontend/hooks/useWebSocketForChatBot.tsx b/frontend/hooks/useWebSocketForChatBot.tsx index 6349eac..c7db80f 100644 --- a/frontend/hooks/useWebSocketForChatBot.tsx +++ b/frontend/hooks/useWebSocketForChatBot.tsx @@ -8,8 +8,9 @@ import { handleWebSocketError } from "../utils/websocket/handleWebSocketError"; import processWebSocketMessage from "../utils/websocket/processWebSocketMessage"; import { buildWebSocketURL } from "../services/url-builder/url-builder"; import { initializeWebSocketConnection } from "../services/api/api"; +import { useWebsocketForChatbotProps } from "../interface/interface"; -const useWebsocketForChatbot=(socketRef,setMessages,router)=>{ +const useWebsocketForChatbot=({socketRef,setMessages,router}:useWebsocketForChatbotProps)=>{ useEffect(() => { const username = getSessionUser(); if (!username || username === "null" || username === "undefined") { diff --git a/frontend/hooks/useWebsocket.tsx b/frontend/hooks/useWebsocket.tsx index dcae442..983c352 100644 --- a/frontend/hooks/useWebsocket.tsx +++ b/frontend/hooks/useWebsocket.tsx @@ -7,8 +7,14 @@ import processWebSocketMessage from "../utils/websocket/processWebSocketMessage" import { buildWebSocketURL } from "../services/url-builder/url-builder"; import { initializeWebSocketConnection } from "../services/api/api"; import playSound from "../utils/playSound"; +import { UseWebsocketProps, Message } from "../interface/interface"; -const useWebsocket=(soundEnabled,channel,socketRef,setMessages,router,setUnreadCount)=>{ +interface MessageData { + [timestamp: string]: string; +} + + +const useWebsocket=({soundEnabled,channel,socketRef,setMessages,router,setUnreadCount}:UseWebsocketProps)=>{ useEffect(() => { const username = getSessionUser(); if (!username || username === "null" || username === "undefined") { @@ -73,16 +79,16 @@ const useWebsocket=(soundEnabled,channel,socketRef,setMessages,router,setUnreadC allMessages.sort((a, b) => a.timestamp - b.timestamp); setMessages(allMessages); } else { - if (data.text && data.sender && data.timestamp) { - let isSent = data.sender === username; + if (event.data.text && event.data.sender && event.data.timestamp) { + let isSent = event.data.sender === username; setMessages((prevMessages) => [ ...prevMessages, { - text: data.text, + text: event.data.text, isSent: isSent, - username: data.sender, - timestamp: parseFloat(data.timestamp), - avatar: data.url, + username: event.data.sender, + timestamp: parseFloat(event.data.timestamp), + avatar: event.data.url, }, ]); if (soundEnabled) playSound(isSent); diff --git a/frontend/interface/interface.ts b/frontend/interface/interface.ts index 6284784..63a695e 100644 --- a/frontend/interface/interface.ts +++ b/frontend/interface/interface.ts @@ -1,3 +1,7 @@ +import React, { Dispatch, MutableRefObject, ReactNode, SetStateAction, useEffect } from "react"; +import { useRouter } from 'next/navigation'; +import alertServerError from "../utils/alerts/alertServerError"; + export interface SettingsPopupProps { onClose: () => void; soundEnabled: boolean; @@ -102,4 +106,116 @@ export interface MailProps { username: string; text: string; timestamp: number; - } \ No newline at end of file + } + + export interface UserContextType { + userName: string | null; + setUserName: React.Dispatch>; + } + + export interface UserProviderProps { + children: React.ReactNode; + } + + export interface UseLoadSettingProps { + setSoundEnabled: (value: boolean) => void; + setNotificationsEnabled: (value: boolean) => void; + } + + export interface UseSettingsProps { + soundEnabled: boolean; + notificationsEnabled: boolean; + } + + export interface UseVisibilityChangeProps { + setUnreadCount: (count: number) => void; +} + +export interface UseWebsocketProps { + soundEnabled: boolean; + channel: string; + socketRef: React.MutableRefObject; + setMessages: React.Dispatch>; + router: typeof(useRouter); + setUnreadCount: React.Dispatch>; +} + +export interface useWebsocketForChatbotProps { + socketRef: MutableRefObject; + setMessages: Dispatch>; + router: typeof(useRouter); +} + +interface UseLoadSettingHook { + (setSoundEnabled: (enabled: boolean) => void, setNotificationsEnabled: (enabled: boolean) => void): void; +} + +interface UseSettingsHook { + (soundEnabled: boolean, notificationsEnabled: boolean): void; +} + +interface UseWebsocketForChatbotHook { + ( + socketRef: React.MutableRefObject, + setMessages: React.Dispatch>, + router: typeof useRouter, + messagesEndRef: React.MutableRefObject + ): void; +} + +interface UseVisibilityChangeHook { + (setUnreadCount: React.Dispatch>): void; +} + +interface UseLeaveChatHook { + (router: typeof useRouter, socketRef: React.MutableRefObject): void; +} + +interface ChatbotContainerProps { + messages: Message[]; + messagesEndRef: React.MutableRefObject; +} + +export interface ProcessWebSocketMessageProps { + event: MessageEvent; + setMessages: React.Dispatch>; + navigateToLogin: () => void; + isChatbot: boolean; +} + +export interface DataFromServer { + userID?: string; + Message?: string; + Delete?: string; +} + +export interface AlertAbnormalCloseProps { + reason: string; + navigateToLogin: () => void; // Function to navigate (e.g., from useRouter) +} + +export interface AlertBadRequestProps { + reason: string; + navigateToLogin: () => void; // Function to navigate (e.g., from useRouter) +} + +export interface WebSocketHandlers { + onOpen: (event: Event) => void; + onMessage: (event: MessageEvent) => void; + onClose: (event: CloseEvent) => void; + onError: (event: Event) => void; +} + +export interface AlertBannedUserProps { + reason: string; + navigateToLogin: () => void; +} +export interface AlertSameUserProps { + reason: string; + navigateToLogin: () => void; +} + +export interface AlertServerErrorProps { + reason: string; + navigateToLogin: () => void; +} \ No newline at end of file diff --git a/frontend/pages/_app.tsx b/frontend/pages/_app.tsx index 53108e3..ac4f267 100644 --- a/frontend/pages/_app.tsx +++ b/frontend/pages/_app.tsx @@ -1,12 +1,14 @@ -import React, { ReactNode } from 'react'; -import { AppProps } from 'next/app'; // Import types from Next.js +import React from 'react'; +import { AppProps } from 'next/app'; import { UserProvider } from "../context/userContext"; import "../styles/globals.css"; -export default function App({ Component, pageProps }) { +function App({ Component, pageProps }: AppProps) { return ( ); } + +export default App; diff --git a/frontend/pages/chat.tsx b/frontend/pages/chat.tsx index d05e155..e55f8e7 100644 --- a/frontend/pages/chat.tsx +++ b/frontend/pages/chat.tsx @@ -10,63 +10,8 @@ import useSettings from "../hooks/useSettings"; import useWebsocket from "../hooks/useWebsocket"; import useLeaveChat from "../hooks/useLeaveChat"; import useVisibilityChange from "../hooks/useVisibilityChange"; +import { Message } from "../interface/interface"; -interface UseLoadSettingHook { - (setSoundEnabled: (enabled: boolean) => void, setNotificationsEnabled: (enabled: boolean) => void): void; -} - -interface UseSettingsHook { - (soundEnabled: boolean, notificationsEnabled: boolean): void; -} - -interface UseWebsocketHook { - ( - soundEnabled: boolean, - channel: string, - socketRef: React.MutableRefObject, - setMessages: React.Dispatch>, - router: typeof useRouter, - setUnreadCount: React.Dispatch> - ): void; -} - -interface UseVisibilityChangeHook { - (setUnreadCount: React.Dispatch>): void; -} - -interface UseLeaveChatHook { - (router: typeof useRouter, socketRef: React.MutableRefObject): void; -} - -// For ChatbotContainer (from a previous response) -interface ChatbotContainerProps { - messages: Message[]; - messagesEndRef: React.MutableRefObject; -} - -// For ChatInputBox (implied) -interface ChatInputBoxProps { - socketRef: React.MutableRefObject; -} - -// For Box (implied) -interface BoxProps { - channel: string; -} - -// For Navbar (implied) -interface NavbarProps { - currentPage: string; - currentTopic?: string; -} - -interface Message { - avatar?: string; - username: string; - text: string; - timestamp: number; - isSent: boolean; -} export default function Home(){ const [messages, setMessages] = useState([]); diff --git a/frontend/pages/chat_bot.tsx b/frontend/pages/chat_bot.tsx index 69a3be8..c1a5f41 100644 --- a/frontend/pages/chat_bot.tsx +++ b/frontend/pages/chat_bot.tsx @@ -10,41 +10,6 @@ import useSettings from "../hooks/useSettings"; import useWebsocketForChatbot from "../hooks/useWebSocketForChatBot"; import useVisibilityChange from "../hooks/useVisibilityChange"; import useLeaveChat from "../hooks/useLeaveChat"; -interface Message { - text: string; // The content of the message - sender: 'user' | 'chatbot'; // Who sent the message - timestamp?: Date; // Optional timestamp (if you want to display it) - // ... other properties as needed (e.g., message ID, attachments, etc.) -} -interface UseLoadSettingHook { - (setSoundEnabled: (enabled: boolean) => void, setNotificationsEnabled: (enabled: boolean) => void): void; -} - -interface UseSettingsHook { - (soundEnabled: boolean, notificationsEnabled: boolean): void; -} - -interface UseWebsocketForChatbotHook { - ( - socketRef: React.MutableRefObject, - setMessages: React.Dispatch>, - router: typeof useRouter, - messagesEndRef: React.MutableRefObject - ): void; -} - -interface UseVisibilityChangeHook { - (setUnreadCount: React.Dispatch>): void; -} - -interface UseLeaveChatHook { - (router: typeof useRouter, socketRef: React.MutableRefObject): void; -} - -interface ChatbotContainerProps { - messages: Message[]; - messagesEndRef: React.MutableRefObject; -} export default function Home() { diff --git a/frontend/pages/index.tsx b/frontend/pages/index.tsx index b0af0e9..4d0b540 100644 --- a/frontend/pages/index.tsx +++ b/frontend/pages/index.tsx @@ -45,7 +45,7 @@ export default function Home() {
    - +
    {isModalOpen && ( diff --git a/frontend/services/api/api.ts b/frontend/services/api/api.ts index 16067f8..9c5f0cd 100644 --- a/frontend/services/api/api.ts +++ b/frontend/services/api/api.ts @@ -1,14 +1,13 @@ +import { WebSocketHandlers } from "../../interface/interface"; + export function initializeWebSocketConnection( url: string, - onOpen: (event: Event) => void, - onMessage: (event: MessageEvent) => void, - onClose: (event: CloseEvent) => void, - onError: (event: Event) => void -) : WebSocket{ + handlers: WebSocketHandlers +): WebSocket { const socket = new WebSocket(url); - socket.onopen = onOpen; - socket.onmessage = onMessage; - socket.onclose = onClose; - socket.onerror = onError; + socket.onopen = handlers.onOpen; + socket.onmessage = handlers.onMessage; + socket.onclose = handlers.onClose; + socket.onerror = handlers.onError; return socket; -} \ No newline at end of file +} diff --git a/frontend/services/api/subscribeApi.ts b/frontend/services/api/subscribeApi.ts index 64a6eb9..50ad27e 100644 --- a/frontend/services/api/subscribeApi.ts +++ b/frontend/services/api/subscribeApi.ts @@ -2,32 +2,32 @@ import axios from "axios"; import { subscribeURLbuildr } from "../url-builder/url-builder"; interface SubscribeResponse { - code:number; + code: number; message: string; } +interface SubscribeRequestData { + email: string; + username: string; + userId: string; + channel: string; + timestamp: number; +} + const subscribe = async ( - email: string, - username: string, - userId: string, - channel: string, - timestamp: number) : Promise=> { + requestData: SubscribeRequestData +): Promise => { const url = subscribeURLbuildr(); + try { const response = await axios.post( url, - { - email: email, - username: username, - userId: userId, - channel: channel, - timestamp: timestamp, - }, + requestData, // Pass the requestData object directly { headers: { "Content-Type": "multipart/form-data", }, - }, + } ); if (response.status === 200) { @@ -37,4 +37,5 @@ const subscribe = async ( throw error.response?.data; } }; -export default subscribe; \ No newline at end of file + +export default subscribe; diff --git a/frontend/services/url-builder/url-builder.ts b/frontend/services/url-builder/url-builder.ts index 991266f..49a3fde 100644 --- a/frontend/services/url-builder/url-builder.ts +++ b/frontend/services/url-builder/url-builder.ts @@ -1,4 +1,4 @@ -export function buildWebSocketURL(userId, username, channel, topic) { +export function buildWebSocketURL(userId, username, channel, topic?) { const host = process.env.NEXT_PUBLIC_BACKEND_HOST; const port = process.env.NEXT_PUBLIC_BACKEND_PORT; const protocol = diff --git a/frontend/utils/alerts/alertAbnormalClose.ts b/frontend/utils/alerts/alertAbnormalClose.ts index d90da7f..489a3df 100644 --- a/frontend/utils/alerts/alertAbnormalClose.ts +++ b/frontend/utils/alerts/alertAbnormalClose.ts @@ -1,14 +1,11 @@ "use client"; import Swal from 'sweetalert2'; import { Dispatch, SetStateAction } from 'react'; // Import types for state setters +import { AlertAbnormalCloseProps } from '../../interface/interface'; -// Interface for function props (if you need it) -interface AlertAbnormalCloseProps { - reason: string; - navigateToLogin: () => void; // Function to navigate (e.g., from useRouter) -} -export default async function alertAbnormalClose(reason: string, navigateToLogin: () => void){ + +export default async function alertAbnormalClose({reason, navigateToLogin}:AlertAbnormalCloseProps){ try { const result = await Swal.fire({ title: "Connection lost", diff --git a/frontend/utils/alerts/alertBadRequest.ts b/frontend/utils/alerts/alertBadRequest.ts index ab19a58..9f2c631 100644 --- a/frontend/utils/alerts/alertBadRequest.ts +++ b/frontend/utils/alerts/alertBadRequest.ts @@ -1,7 +1,8 @@ "use client"; import Swal from "sweetalert2"; +import { AlertAbnormalCloseProps, AlertBadRequestProps } from "../../interface/interface"; -export default function alertBadRequest(reason: string, navigateToLogin: () => void) { +export default function alertBadRequest({reason, navigateToLogin}:AlertBadRequestProps) { try { Swal.fire({ title: "Bad request", diff --git a/frontend/utils/alerts/alertBannedUser.ts b/frontend/utils/alerts/alertBannedUser.ts index 811dc68..79f5104 100644 --- a/frontend/utils/alerts/alertBannedUser.ts +++ b/frontend/utils/alerts/alertBannedUser.ts @@ -1,7 +1,8 @@ "use client"; import Swal from "sweetalert2"; +import { AlertBannedUserProps } from "../../interface/interface"; -export default function alertBannedUser(reason: string, navigateToLogin: () => void) { +const alertBannedUser = async function alertBannedUser({reason,navigateToLogin}:AlertBannedUserProps) { try { Swal.fire({ title: "You have been banned", @@ -23,4 +24,6 @@ export default function alertBannedUser(reason: string, navigateToLogin: () => v } catch (error) {} }); } catch (error) {} - } \ No newline at end of file + } + +export default alertBannedUser; \ No newline at end of file diff --git a/frontend/utils/alerts/alertSameUsername.ts b/frontend/utils/alerts/alertSameUsername.ts index 96da78a..4183938 100644 --- a/frontend/utils/alerts/alertSameUsername.ts +++ b/frontend/utils/alerts/alertSameUsername.ts @@ -1,7 +1,8 @@ "use client"; import Swal from "sweetalert2"; +import { AlertSameUserProps } from "../../interface/interface"; -export default function alertSameUsername(reason: string, navigateToLogin: () => void) { +export default function alertSameUsername({ reason, navigateToLogin }: AlertSameUserProps) { try { Swal.fire({ title: "Username already exists", diff --git a/frontend/utils/alerts/alertServerError.ts b/frontend/utils/alerts/alertServerError.ts index 43f0535..34a80ec 100644 --- a/frontend/utils/alerts/alertServerError.ts +++ b/frontend/utils/alerts/alertServerError.ts @@ -1,7 +1,8 @@ "use client"; import Swal from "sweetalert2"; +import { AlertServerErrorProps } from "../../interface/interface"; -export default function alertServerError(reason: string, navigateToLogin: () => void) { +export default function alertServerError({reason, navigateToLogin}:AlertServerErrorProps) { try { Swal.fire({ title: "Server error", diff --git a/frontend/utils/session/removeSessionUserId.ts b/frontend/utils/session/removeSessionUserId.ts index 24c9730..517de64 100644 --- a/frontend/utils/session/removeSessionUserId.ts +++ b/frontend/utils/session/removeSessionUserId.ts @@ -1,5 +1,5 @@ "use client"; -export default function removeSessionUserId() { +export default function removeSessionUserId():void { sessionStorage.removeItem("userID"); } \ No newline at end of file diff --git a/frontend/utils/websocket/handleWebSocketClose.ts b/frontend/utils/websocket/handleWebSocketClose.ts index 2880c73..206ffe3 100644 --- a/frontend/utils/websocket/handleWebSocketClose.ts +++ b/frontend/utils/websocket/handleWebSocketClose.ts @@ -14,18 +14,23 @@ import alertAbnormalClose from "../alerts/alertAbnormalClose"; export default function handleWebSocketClose(event, navigateToLogin) { if (isUserBanned(event.code)) { - alertBannedUser(event.reason, navigateToLogin); + alertBannedUser(event.reason); + navigateToLogin(); } if (isSameUsername(event.code)) { - alertSameUsername(event.reason, navigateToLogin); + alertSameUsername(event.reason); + navigateToLogin(); } if (isBadRequest(event.code)) { - alertBadRequest(event.reason, navigateToLogin); + alertBadRequest(event.reason); + navigateToLogin(); } if (isServerError(event.code)) { - alertServerError(event.reason, navigateToLogin); + alertServerError(event.reason); + navigateToLogin(); } if (isAbnormalClose(event.code)) { - alertAbnormalClose(event.reason, navigateToLogin); + alertAbnormalClose(event.reason); + navigateToLogin(); } } \ No newline at end of file diff --git a/frontend/utils/websocket/processWebSocketMessage.ts b/frontend/utils/websocket/processWebSocketMessage.ts index 7978798..c133f08 100644 --- a/frontend/utils/websocket/processWebSocketMessage.ts +++ b/frontend/utils/websocket/processWebSocketMessage.ts @@ -1,11 +1,12 @@ "use client"; +import { DataFromServer, Message, ProcessWebSocketMessageProps } from "../../interface/interface"; import alertBannedUser from "../alerts/alertBannedUser"; export default function processWebSocketMessage( - event, + {event, setMessages, navigateToLogin, - isChatbot, + isChatbot,}:ProcessWebSocketMessageProps ) { if (isChatbot) { const userIdRegex = /\buserID\b/; @@ -36,25 +37,23 @@ export default function processWebSocketMessage( console.error("Error parsing or handling the message:", error); } - function handleUserID(data) { + function handleUserID(data: DataFromServer) { if (data.userID) { - sessionStorage.setItem("userID", data.userID); + sessionStorage.setItem("userID", data.userID); } - } - - function handleBannedUser(data, navigateToLogin) { + } + + function handleBannedUser(data: DataFromServer, navigateToLogin: () => void) { if (data.Message && data.Message === "You are banned now") { - alertBannedUser(data.Message,navigateToLogin); - navigateToLogin(); - return true; + alertBannedUser(data.Message?); + navigateToLogin(); + return true; } return false; - } - - function handleDeleteMessage(data, setMessages) { - const deleteTimestamp = parseFloat(data.Delete); - setMessages((prevMessages) => - prevMessages.filter((message) => message.timestamp !== deleteTimestamp), - ); - } - } \ No newline at end of file + } + + function handleDeleteMessage(data: DataFromServer, setMessages: React.Dispatch>) { + const deleteTimestamp = parseFloat(data.Delete!); + setMessages((prevMessages) => prevMessages.filter((message) => message.timestamp !== deleteTimestamp)); + } +} \ No newline at end of file From d18c520aba4f8699cce88e2e2b0293f56fa562b1 Mon Sep 17 00:00:00 2001 From: kitretsu2809 Date: Thu, 15 Aug 2024 17:03:08 +0530 Subject: [PATCH 11/31] fix:chat_bot and websocket --- frontend/hooks/useLoadSettings.tsx | 3 +-- frontend/hooks/useSettings.tsx | 2 +- frontend/interface/interface.ts | 12 ++++++------ frontend/pages/chat_bot.tsx | 4 ++-- frontend/utils/websocket/processWebSocketMessage.ts | 6 +----- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/frontend/hooks/useLoadSettings.tsx b/frontend/hooks/useLoadSettings.tsx index be4194e..df613cc 100644 --- a/frontend/hooks/useLoadSettings.tsx +++ b/frontend/hooks/useLoadSettings.tsx @@ -2,8 +2,7 @@ import { useEffect } from 'react'; import { UseLoadSettingProps } from '../interface/interface'; - -const useLoadSetting = (setSoundEnabled: unknown, setNotificationsEnabled: unknown, { setSoundEnabled, setNotificationsEnabled }: UseLoadSettingProps) => { +const useLoadSetting = (setSoundEnabled, setNotificationsEnabled) => { useEffect(() => { const savedSoundEnabled = localStorage.getItem("soundEnabled"); const savedNotificationsEnabled = localStorage.getItem("notificationsEnabled"); diff --git a/frontend/hooks/useSettings.tsx b/frontend/hooks/useSettings.tsx index 33a9b4d..b61f94d 100644 --- a/frontend/hooks/useSettings.tsx +++ b/frontend/hooks/useSettings.tsx @@ -1,6 +1,6 @@ import { useEffect } from "react"; import { UseSettingsProps } from "../interface/interface"; -function useSettings({ soundEnabled, notificationsEnabled }: UseSettingsProps) { +function useSettings(soundEnabled, notificationsEnabled) { useEffect(() => { localStorage.setItem("soundEnabled", JSON.stringify(soundEnabled)); }, [soundEnabled]); diff --git a/frontend/interface/interface.ts b/frontend/interface/interface.ts index 63a695e..41de6a0 100644 --- a/frontend/interface/interface.ts +++ b/frontend/interface/interface.ts @@ -1,4 +1,4 @@ -import React, { Dispatch, MutableRefObject, ReactNode, SetStateAction, useEffect } from "react"; +import React, { Dispatch, MutableRefObject, ReactNode, SetStateAction, useEffect, useState } from "react"; import { useRouter } from 'next/navigation'; import alertServerError from "../utils/alerts/alertServerError"; @@ -118,8 +118,8 @@ export interface MailProps { } export interface UseLoadSettingProps { - setSoundEnabled: (value: boolean) => void; - setNotificationsEnabled: (value: boolean) => void; + setSoundEnabled: typeof useState; + setNotificationsEnabled: typeof useState; } export interface UseSettingsProps { @@ -128,7 +128,7 @@ export interface MailProps { } export interface UseVisibilityChangeProps { - setUnreadCount: (count: number) => void; + setUnreadCount: Dispatch> } export interface UseWebsocketProps { @@ -136,14 +136,14 @@ export interface UseWebsocketProps { channel: string; socketRef: React.MutableRefObject; setMessages: React.Dispatch>; - router: typeof(useRouter); + router: any; setUnreadCount: React.Dispatch>; } export interface useWebsocketForChatbotProps { socketRef: MutableRefObject; setMessages: Dispatch>; - router: typeof(useRouter); + router: any; } interface UseLoadSettingHook { diff --git a/frontend/pages/chat_bot.tsx b/frontend/pages/chat_bot.tsx index c1a5f41..36a2476 100644 --- a/frontend/pages/chat_bot.tsx +++ b/frontend/pages/chat_bot.tsx @@ -24,8 +24,8 @@ export default function Home() { useLoadSetting(setSoundEnabled,setNotificationsEnabled); useSettings(soundEnabled,notificationsEnabled); - useWebsocketForChatbot(socketRef,setMessages,router); - useVisibilityChange(setUnreadCount); + useWebsocketForChatbot({socketRef,setMessages,router}); + useVisibilityChange({setUnreadCount}); // useLeaveChat(router); useEffect(() => setTopic(router.query.topic as string ?? "Appetizer"), [router.query]); diff --git a/frontend/utils/websocket/processWebSocketMessage.ts b/frontend/utils/websocket/processWebSocketMessage.ts index c133f08..1573db5 100644 --- a/frontend/utils/websocket/processWebSocketMessage.ts +++ b/frontend/utils/websocket/processWebSocketMessage.ts @@ -3,11 +3,7 @@ import { DataFromServer, Message, ProcessWebSocketMessageProps } from "../../int import alertBannedUser from "../alerts/alertBannedUser"; export default function processWebSocketMessage( - {event, - setMessages, - navigateToLogin, - isChatbot,}:ProcessWebSocketMessageProps - ) { +{ event, setMessages, navigateToLogin, isChatbot }: ProcessWebSocketMessageProps, p1: boolean ) { if (isChatbot) { const userIdRegex = /\buserID\b/; if (userIdRegex.test(event.data)) { From f7761c3b6c760cd31d23b78a8f3c72f7b969f3ee Mon Sep 17 00:00:00 2001 From: kitretsu2809 Date: Thu, 15 Aug 2024 19:14:36 +0530 Subject: [PATCH 12/31] fix:websocket --- frontend/hooks/useWebsocket.tsx | 175 ++++++++---------- .../websocket/processWebSocketMessage.ts | 2 +- 2 files changed, 82 insertions(+), 95 deletions(-) diff --git a/frontend/hooks/useWebsocket.tsx b/frontend/hooks/useWebsocket.tsx index 983c352..0198377 100644 --- a/frontend/hooks/useWebsocket.tsx +++ b/frontend/hooks/useWebsocket.tsx @@ -1,4 +1,7 @@ -import { useEffect} from "react"; +import { useEffect, useRef, MutableRefObject, Dispatch, SetStateAction } from "react"; +import { useRouter } from "next/router"; +import formatChatbotUserText from "../utils/chatbot_formatting/formatChatbotUserText"; +import getIsSentForChatBot from "../utils/chatbot_formatting/getIsSentForChatBot"; import getSessionUser from "../utils/session/getSessionUser"; import getSessionUserId from "../utils/session/getSessionUserId"; import handleWebSocketClose from "../utils/websocket/handleWebSocketClose"; @@ -6,102 +9,86 @@ import { handleWebSocketError } from "../utils/websocket/handleWebSocketError"; import processWebSocketMessage from "../utils/websocket/processWebSocketMessage"; import { buildWebSocketURL } from "../services/url-builder/url-builder"; import { initializeWebSocketConnection } from "../services/api/api"; -import playSound from "../utils/playSound"; -import { UseWebsocketProps, Message } from "../interface/interface"; -interface MessageData { - [timestamp: string]: string; +// Define the shape of your message object +interface Message { + text: string; + isSent: boolean; + username?: string; // Make username optional as it might not always be present } +interface UseWebsocketForChatbotProps { + socketRef: MutableRefObject; + setMessages: Dispatch>; + router: typeof useRouter; +} + +const useWebsocketForChatbot = ({ socketRef, setMessages, router }: UseWebsocketForChatbotProps) => { + useEffect(() => { + const username = getSessionUser(); + if (!username || username === "null" || username === "undefined") { + router.push("/"); + return; // Important to return here to prevent further execution if the user is not logged in + } + const userId = getSessionUserId(); + + const channel = "chatbot"; + + const topic = router.query; + const url = buildWebSocketURL( + userId, + username, + channel, + // Type assertion here since `router.query` can potentially be `undefined` + (topic as { topic?: string }).topic ?? "Appetizer" + ); + + const handleOpen = () => { + // todo-> toast connected to server + }; + + const handleMessage = (event: MessageEvent) => + processWebSocketMessage(event, setMessages, () => router.push("/"), true); + + const handleClose = (event: CloseEvent) => + handleWebSocketClose(event, () => router.push("/")); + + const handleError = handleWebSocketError; -const useWebsocket=({soundEnabled,channel,socketRef,setMessages,router,setUnreadCount}:UseWebsocketProps)=>{ - useEffect(() => { + const socket = initializeWebSocketConnection( + url, + {handleOpen, + handleMessage, + handleClose, + handleError} + ); + socketRef.current = socket; + + socket.addEventListener("message", (event) => { + try { const username = getSessionUser(); - if (!username || username === "null" || username === "undefined") { - router.push("/"); - } - const userId = getSessionUserId(); - const url = buildWebSocketURL(userId, username, channel); - const handleOpen = () => { - //todo-> toast connected to server - }; - const handleMessage = (event) => - processWebSocketMessage( - event, - setMessages, - () => router.push("/"), - false, - ); - const handleClose = (event) => - handleWebSocketClose(event, () => router.push("/")); - const handleError = handleWebSocketError; - const socket = initializeWebSocketConnection( - url, - handleOpen, - handleMessage, - handleClose, - handleError, - ); - socketRef.current = socket; - - socket.addEventListener("message", (event) => { - try { - let data = ""; - if ( - event.data != "Message send successful" && - event.data != "Welcome to MDG Chat!" - ) { - data = JSON.parse(event.data); - } - const allMessages = []; - const addMessages = (messageData, isSent) => { - for (const timestamp in messageData) { - const messageObj = JSON.parse(messageData[timestamp]); - allMessages.push({ - text: messageObj.text, - isSent: isSent, - username: messageObj.sender, - timestamp: parseFloat(timestamp), - avatar: messageObj.url, - }); - } - }; - let hasBulkMessages = false; - if (data["Sent by others"]) { - addMessages(data["Sent by others"], false); - hasBulkMessages = true; - } - if (data["Sent by you"]) { - addMessages(data["Sent by you"], true); - hasBulkMessages = true; - } - if (hasBulkMessages) { - allMessages.sort((a, b) => a.timestamp - b.timestamp); - setMessages(allMessages); - } else { - if (event.data.text && event.data.sender && event.data.timestamp) { - let isSent = event.data.sender === username; - setMessages((prevMessages) => [ - ...prevMessages, - { - text: event.data.text, - isSent: isSent, - username: event.data.sender, - timestamp: parseFloat(event.data.timestamp), - avatar: event.data.url, - }, - ]); - if (soundEnabled) playSound(isSent); - if (document.hidden) setUnreadCount((prevCount) => prevCount + 1); - } - } - } catch (error) { - //todo-> enable sentry logger here - } - }); - return () => { - socket.close(); + let data = event.data; + const isSent = getIsSentForChatBot(event.data); + + const newMessage: Message = { + text: isSent ? formatChatbotUserText(data) : data, + isSent: isSent, + username: isSent ? username : "Echofy", }; - }, [initializeWebSocketConnection, soundEnabled]); -} -export default useWebsocket; \ No newline at end of file + + setMessages((prevMessages) => [...prevMessages, newMessage]); + } catch (error) { + // todo-> enable sentry logger here + console.error("Error in WebSocket message handler:", error); + } + }); + + return () => { + if (socketRef.current) { // Check if socketRef.current is not null before closing + socketRef.current.close(); + } + }; + }, [initializeWebSocketConnection, router.query, setMessages]); // Include router.query in the dependency array +}; + +export default useWebsocketForChatbot; diff --git a/frontend/utils/websocket/processWebSocketMessage.ts b/frontend/utils/websocket/processWebSocketMessage.ts index 1573db5..97f5aab 100644 --- a/frontend/utils/websocket/processWebSocketMessage.ts +++ b/frontend/utils/websocket/processWebSocketMessage.ts @@ -3,7 +3,7 @@ import { DataFromServer, Message, ProcessWebSocketMessageProps } from "../../int import alertBannedUser from "../alerts/alertBannedUser"; export default function processWebSocketMessage( -{ event, setMessages, navigateToLogin, isChatbot }: ProcessWebSocketMessageProps, p1: boolean ) { +{ event, setMessages, navigateToLogin, isChatbot }: ProcessWebSocketMessageProps) { if (isChatbot) { const userIdRegex = /\buserID\b/; if (userIdRegex.test(event.data)) { From 3ad70ff16b8c430a59d00c0a6e2e38a9c5ba9f54 Mon Sep 17 00:00:00 2001 From: kitretsu2809 Date: Fri, 16 Aug 2024 19:00:30 +0530 Subject: [PATCH 13/31] Fix:errors fixed --- backend/db/client.go | 2 +- frontend/components/chat/chatContainer.tsx | 1 - .../components/chatbot/chatbotContainer.tsx | 2 +- .../components/chatbot/chatbotLoginModal.tsx | 22 ++++----- frontend/hooks/useWebSocketForChatBot.tsx | 2 +- frontend/hooks/useWebsocket.tsx | 46 ++++++++++++------- frontend/interface/interface.ts | 34 +++++--------- frontend/pages/chat.tsx | 4 +- frontend/services/api/api.ts | 19 ++++---- frontend/services/api/subscribeApi.ts | 34 ++++++-------- frontend/utils/alerts/alertAbnormalClose.ts | 4 +- frontend/utils/alerts/alertBadRequest.ts | 5 +- frontend/utils/alerts/alertBannedUser.ts | 4 +- frontend/utils/alerts/alertSameUsername.ts | 5 +- frontend/utils/alerts/alertServerError.ts | 5 +- .../utils/websocket/handleWebSocketClose.ts | 16 ++----- .../websocket/processWebSocketMessage.ts | 4 +- 17 files changed, 98 insertions(+), 111 deletions(-) diff --git a/backend/db/client.go b/backend/db/client.go index bd9c512..8131869 100644 --- a/backend/db/client.go +++ b/backend/db/client.go @@ -24,7 +24,7 @@ func Init() { func redisInit(portNumber, dbNumber int, password string) { ctx = context.Background() redisClient = redis.NewClient(&redis.Options{ - Addr: fmt.Sprintf("redis:%v", portNumber), //port number can be changed as per our wish + Addr: fmt.Sprintf("localhost", portNumber), //port number can be changed as per our wish Password: password, DB: dbNumber, }) diff --git a/frontend/components/chat/chatContainer.tsx b/frontend/components/chat/chatContainer.tsx index 2056886..6dd2585 100644 --- a/frontend/components/chat/chatContainer.tsx +++ b/frontend/components/chat/chatContainer.tsx @@ -1,4 +1,3 @@ - import React, { MutableRefObject } from "react"; import Image from "next/image"; import moment from "moment"; diff --git a/frontend/components/chatbot/chatbotContainer.tsx b/frontend/components/chatbot/chatbotContainer.tsx index 1cc872a..1911001 100644 --- a/frontend/components/chatbot/chatbotContainer.tsx +++ b/frontend/components/chatbot/chatbotContainer.tsx @@ -59,7 +59,7 @@ export default function ChatContainer({ messages, messagesEndRef }:ChatContainer const filterMessages = () => { const newMessages = messages.filter((message) => { try { - message = JSON.parse(message); + // message = JSON.parse(message); const messageData = JSON.parse(message.text); return !( messageData.userID && messageData.userID.startsWith("chatbot") diff --git a/frontend/components/chatbot/chatbotLoginModal.tsx b/frontend/components/chatbot/chatbotLoginModal.tsx index ded3063..c52ad8e 100644 --- a/frontend/components/chatbot/chatbotLoginModal.tsx +++ b/frontend/components/chatbot/chatbotLoginModal.tsx @@ -6,15 +6,15 @@ import setSessionUser from "../../utils/session/setSessionUser"; import removeSessionUserId from "../../utils/session/removeSessionUserId"; import checkAndPromptSessionChange from "../../utils/alerts/checkAndPromptSessionChange"; import { TopicDropdown } from "../topicDropdown"; -import { ChatBotLoginModalProps, Topic } from "../../interface/interface"; - - +interface ChatBotLoginModalProps { + onClose: () => void; +} +type Topic = "SELECT A TOPIC" | "Option 1" | "Option 2" | string ; const ChatBotLoginModal: React.FC = ({ onClose }) => { const popupRef = useRef(null); - const [username, setUsername] = useState(""); - const [topic, setTopic] = useState("SELECT A TOPIC"); + const [username, setUsername] = useState(""); + const [topic, setTopic] = useState("SELECT A TOPIC"); const router = useRouter(); - useEffect(() => { const handleClickOutside = (event: MouseEvent) => { if (popupRef.current && !popupRef.current.contains(event.target as Node)) { @@ -22,25 +22,21 @@ const ChatBotLoginModal: React.FC = ({ onClose }) => { } }; document.addEventListener("mousedown", handleClickOutside); - return () => document.removeEventListener("mousedown",   + return () => document.removeEventListener("mousedown", handleClickOutside); - }, [popupRef,   + }, [popupRef, onClose]); - const handleUsernameChange = (event: React.ChangeEvent) => { setUsername(event.target.value); }; - const handleEnterClick = (event: React.KeyboardEvent) => { if (event.key === "Enter") { handleChatWithUsClick(); } }; - const handleChatWithUsClick = async () => { const currentUser = getSessionUser(); const currentUserId = getSessionUserId(); - if (currentUser && currentUserId) { if (currentUser === username) { router.push(`/chat_bot?topic=${encodeURIComponent(topic)}`); @@ -53,7 +49,6 @@ const ChatBotLoginModal: React.FC = ({ onClose }) => { setSessionUser(username); } ); - if (hasChanged) { router.push(`/chat_bot?topic=${encodeURIComponent(topic)}`); } @@ -73,7 +68,6 @@ const ChatBotLoginModal: React.FC = ({ onClose }) => {
    Pick your username and login
    -
    toast connected to server }; const handleMessage = (event) => - processWebSocketMessage(event, setMessages, () => router.push("/"), true); + processWebSocketMessage({event, setMessages, navigateToLogin:() => router.push("/"), isChatbot:true}); const handleClose = (event) => handleWebSocketClose(event, () => router.push("/")); const handleError = handleWebSocketError; diff --git a/frontend/hooks/useWebsocket.tsx b/frontend/hooks/useWebsocket.tsx index 983c352..a22160b 100644 --- a/frontend/hooks/useWebsocket.tsx +++ b/frontend/hooks/useWebsocket.tsx @@ -1,4 +1,4 @@ -import { useEffect} from "react"; +import { MutableRefObject, useEffect} from "react"; import getSessionUser from "../utils/session/getSessionUser"; import getSessionUserId from "../utils/session/getSessionUserId"; import handleWebSocketClose from "../utils/websocket/handleWebSocketClose"; @@ -7,14 +7,26 @@ import processWebSocketMessage from "../utils/websocket/processWebSocketMessage" import { buildWebSocketURL } from "../services/url-builder/url-builder"; import { initializeWebSocketConnection } from "../services/api/api"; import playSound from "../utils/playSound"; -import { UseWebsocketProps, Message } from "../interface/interface"; +import { Message } from "../interface/interface" +import { NextRouter } from "next/router"; -interface MessageData { - [timestamp: string]: string; +interface UseWebSocketProps { + soundEnabled: boolean, + channel: string, + socketRef: MutableRefObject, + setMessages: React.Dispatch>, + router: NextRouter, + setUnreadCount: React.Dispatch> } - -const useWebsocket=({soundEnabled,channel,socketRef,setMessages,router,setUnreadCount}:UseWebsocketProps)=>{ +const useWebsocket=({ + soundEnabled, + channel, + socketRef, + setMessages, + router, + setUnreadCount, +}: UseWebSocketProps)=>{ useEffect(() => { const username = getSessionUser(); if (!username || username === "null" || username === "undefined") { @@ -27,11 +39,11 @@ const useWebsocket=({soundEnabled,channel,socketRef,setMessages,router,setUnread }; const handleMessage = (event) => processWebSocketMessage( - event, + { event, setMessages, - () => router.push("/"), - false, - ); + navigateToLogin:() => router.push("/"), + isChatbot:false, + }); const handleClose = (event) => handleWebSocketClose(event, () => router.push("/")); const handleError = handleWebSocketError; @@ -46,7 +58,7 @@ const useWebsocket=({soundEnabled,channel,socketRef,setMessages,router,setUnread socket.addEventListener("message", (event) => { try { - let data = ""; + let data:any = ""; if ( event.data != "Message send successful" && event.data != "Welcome to MDG Chat!" @@ -79,16 +91,16 @@ const useWebsocket=({soundEnabled,channel,socketRef,setMessages,router,setUnread allMessages.sort((a, b) => a.timestamp - b.timestamp); setMessages(allMessages); } else { - if (event.data.text && event.data.sender && event.data.timestamp) { - let isSent = event.data.sender === username; + if (data.text && data.sender && data.timestamp) { + let isSent = data.sender === username; setMessages((prevMessages) => [ ...prevMessages, { - text: event.data.text, + text: data.text, isSent: isSent, - username: event.data.sender, - timestamp: parseFloat(event.data.timestamp), - avatar: event.data.url, + username: data.sender, + timestamp: parseFloat(data.timestamp), + avatar: data.url, }, ]); if (soundEnabled) playSound(isSent); diff --git a/frontend/interface/interface.ts b/frontend/interface/interface.ts index 41de6a0..852afd6 100644 --- a/frontend/interface/interface.ts +++ b/frontend/interface/interface.ts @@ -88,17 +88,6 @@ export interface MailProps { onClose: () => void; // Function to close the modal } export type Topic = "SELECT A TOPIC" | "Option 1" | "Option 2" | string ; - - export interface ChatContainerProps { - messages: string[]; // Assuming messages are serialized JSON strings - messagesEndRef: React.RefObject; // Ref to scroll to the bottom - } - - export interface Message { - isSent: boolean; - username: string; - text: string; // Can contain JSON data in some cases - } export interface Message { isSent: boolean; @@ -107,6 +96,14 @@ export interface MailProps { text: string; timestamp: number; } + export interface ChatContainerProps { + messages: Message[]; // Assuming messages are serialized JSON strings + messagesEndRef: React.RefObject; // Ref to scroll to the bottom + } + + + + export interface UserContextType { userName: string | null; @@ -189,15 +186,9 @@ export interface DataFromServer { Delete?: string; } -export interface AlertAbnormalCloseProps { - reason: string; - navigateToLogin: () => void; // Function to navigate (e.g., from useRouter) -} -export interface AlertBadRequestProps { - reason: string; - navigateToLogin: () => void; // Function to navigate (e.g., from useRouter) -} + + export interface WebSocketHandlers { onOpen: (event: Event) => void; @@ -206,10 +197,7 @@ export interface WebSocketHandlers { onError: (event: Event) => void; } -export interface AlertBannedUserProps { - reason: string; - navigateToLogin: () => void; -} + export interface AlertSameUserProps { reason: string; navigateToLogin: () => void; diff --git a/frontend/pages/chat.tsx b/frontend/pages/chat.tsx index e55f8e7..c5bf305 100644 --- a/frontend/pages/chat.tsx +++ b/frontend/pages/chat.tsx @@ -25,9 +25,9 @@ export default function Home(){ useLoadSetting(setSoundEnabled,setNotificationsEnabled); useSettings(soundEnabled,notificationsEnabled); - useWebsocket(soundEnabled,channel,socketRef,setMessages,router,setUnreadCount) + useWebsocket({soundEnabled,channel,socketRef,setMessages,router,setUnreadCount}) useLeaveChat(router); - useVisibilityChange(setUnreadCount); + useVisibilityChange({setUnreadCount}); useEffect(() => {}, [messages]); diff --git a/frontend/services/api/api.ts b/frontend/services/api/api.ts index 9c5f0cd..16067f8 100644 --- a/frontend/services/api/api.ts +++ b/frontend/services/api/api.ts @@ -1,13 +1,14 @@ -import { WebSocketHandlers } from "../../interface/interface"; - export function initializeWebSocketConnection( url: string, - handlers: WebSocketHandlers -): WebSocket { + onOpen: (event: Event) => void, + onMessage: (event: MessageEvent) => void, + onClose: (event: CloseEvent) => void, + onError: (event: Event) => void +) : WebSocket{ const socket = new WebSocket(url); - socket.onopen = handlers.onOpen; - socket.onmessage = handlers.onMessage; - socket.onclose = handlers.onClose; - socket.onerror = handlers.onError; + socket.onopen = onOpen; + socket.onmessage = onMessage; + socket.onclose = onClose; + socket.onerror = onError; return socket; -} +} \ No newline at end of file diff --git a/frontend/services/api/subscribeApi.ts b/frontend/services/api/subscribeApi.ts index 50ad27e..3525d47 100644 --- a/frontend/services/api/subscribeApi.ts +++ b/frontend/services/api/subscribeApi.ts @@ -1,35 +1,32 @@ import axios from "axios"; import { subscribeURLbuildr } from "../url-builder/url-builder"; - interface SubscribeResponse { - code: number; + code:number; message: string; } - -interface SubscribeRequestData { - email: string; - username: string; - userId: string; - channel: string; - timestamp: number; -} - const subscribe = async ( - requestData: SubscribeRequestData -): Promise => { + email: string, + username: string, + userId: string, + channel: string, + timestamp: number) : Promise=> { const url = subscribeURLbuildr(); - try { const response = await axios.post( url, - requestData, // Pass the requestData object directly + { + email: email, + username: username, + userId: userId, + channel: channel, + timestamp: timestamp, + }, { headers: { "Content-Type": "multipart/form-data", }, - } + }, ); - if (response.status === 200) { return response.data; } @@ -37,5 +34,4 @@ const subscribe = async ( throw error.response?.data; } }; - -export default subscribe; +export default subscribe; \ No newline at end of file diff --git a/frontend/utils/alerts/alertAbnormalClose.ts b/frontend/utils/alerts/alertAbnormalClose.ts index 489a3df..be896f2 100644 --- a/frontend/utils/alerts/alertAbnormalClose.ts +++ b/frontend/utils/alerts/alertAbnormalClose.ts @@ -1,11 +1,11 @@ "use client"; import Swal from 'sweetalert2'; import { Dispatch, SetStateAction } from 'react'; // Import types for state setters -import { AlertAbnormalCloseProps } from '../../interface/interface'; -export default async function alertAbnormalClose({reason, navigateToLogin}:AlertAbnormalCloseProps){ +export default async function alertAbnormalClose(reason: string, + navigateToLogin: () => void){ try { const result = await Swal.fire({ title: "Connection lost", diff --git a/frontend/utils/alerts/alertBadRequest.ts b/frontend/utils/alerts/alertBadRequest.ts index 9f2c631..596b470 100644 --- a/frontend/utils/alerts/alertBadRequest.ts +++ b/frontend/utils/alerts/alertBadRequest.ts @@ -1,8 +1,9 @@ "use client"; import Swal from "sweetalert2"; -import { AlertAbnormalCloseProps, AlertBadRequestProps } from "../../interface/interface"; -export default function alertBadRequest({reason, navigateToLogin}:AlertBadRequestProps) { + +export default function alertBadRequest(reason: string, + navigateToLogin: () => void) { try { Swal.fire({ title: "Bad request", diff --git a/frontend/utils/alerts/alertBannedUser.ts b/frontend/utils/alerts/alertBannedUser.ts index 79f5104..217eb56 100644 --- a/frontend/utils/alerts/alertBannedUser.ts +++ b/frontend/utils/alerts/alertBannedUser.ts @@ -1,8 +1,8 @@ "use client"; import Swal from "sweetalert2"; -import { AlertBannedUserProps } from "../../interface/interface"; -const alertBannedUser = async function alertBannedUser({reason,navigateToLogin}:AlertBannedUserProps) { +const alertBannedUser = async (reason: string, + navigateToLogin: () => void)=> { try { Swal.fire({ title: "You have been banned", diff --git a/frontend/utils/alerts/alertSameUsername.ts b/frontend/utils/alerts/alertSameUsername.ts index 4183938..543fe3d 100644 --- a/frontend/utils/alerts/alertSameUsername.ts +++ b/frontend/utils/alerts/alertSameUsername.ts @@ -1,8 +1,9 @@ "use client"; import Swal from "sweetalert2"; -import { AlertSameUserProps } from "../../interface/interface"; -export default function alertSameUsername({ reason, navigateToLogin }: AlertSameUserProps) { + +export default function alertSameUsername( reason: string, + navigateToLogin: () => void ) { try { Swal.fire({ title: "Username already exists", diff --git a/frontend/utils/alerts/alertServerError.ts b/frontend/utils/alerts/alertServerError.ts index 34a80ec..11ec45d 100644 --- a/frontend/utils/alerts/alertServerError.ts +++ b/frontend/utils/alerts/alertServerError.ts @@ -1,8 +1,9 @@ "use client"; import Swal from "sweetalert2"; -import { AlertServerErrorProps } from "../../interface/interface"; -export default function alertServerError({reason, navigateToLogin}:AlertServerErrorProps) { + +export default function alertServerError(reason: string, + navigateToLogin: () => void) { try { Swal.fire({ title: "Server error", diff --git a/frontend/utils/websocket/handleWebSocketClose.ts b/frontend/utils/websocket/handleWebSocketClose.ts index 206ffe3..15cc69c 100644 --- a/frontend/utils/websocket/handleWebSocketClose.ts +++ b/frontend/utils/websocket/handleWebSocketClose.ts @@ -11,26 +11,20 @@ import alertSameUsername from "../alerts/alertSameUsername"; import alertBadRequest from "../alerts/alertBadRequest"; import alertServerError from "../alerts/alertServerError"; import alertAbnormalClose from "../alerts/alertAbnormalClose"; - export default function handleWebSocketClose(event, navigateToLogin) { if (isUserBanned(event.code)) { - alertBannedUser(event.reason); - navigateToLogin(); + alertBannedUser(event.reason, navigateToLogin); } if (isSameUsername(event.code)) { - alertSameUsername(event.reason); - navigateToLogin(); + alertSameUsername(event.reason, navigateToLogin); } if (isBadRequest(event.code)) { - alertBadRequest(event.reason); - navigateToLogin(); + alertBadRequest(event.reason, navigateToLogin); } if (isServerError(event.code)) { - alertServerError(event.reason); - navigateToLogin(); + alertServerError(event.reason, navigateToLogin); } if (isAbnormalClose(event.code)) { - alertAbnormalClose(event.reason); - navigateToLogin(); + alertAbnormalClose(event.reason, navigateToLogin); } } \ No newline at end of file diff --git a/frontend/utils/websocket/processWebSocketMessage.ts b/frontend/utils/websocket/processWebSocketMessage.ts index 1573db5..5938093 100644 --- a/frontend/utils/websocket/processWebSocketMessage.ts +++ b/frontend/utils/websocket/processWebSocketMessage.ts @@ -3,7 +3,7 @@ import { DataFromServer, Message, ProcessWebSocketMessageProps } from "../../int import alertBannedUser from "../alerts/alertBannedUser"; export default function processWebSocketMessage( -{ event, setMessages, navigateToLogin, isChatbot }: ProcessWebSocketMessageProps, p1: boolean ) { +{ event, setMessages, navigateToLogin, isChatbot }: ProcessWebSocketMessageProps) { if (isChatbot) { const userIdRegex = /\buserID\b/; if (userIdRegex.test(event.data)) { @@ -41,7 +41,7 @@ export default function processWebSocketMessage( function handleBannedUser(data: DataFromServer, navigateToLogin: () => void) { if (data.Message && data.Message === "You are banned now") { - alertBannedUser(data.Message?); + alertBannedUser(data.Message,navigateToLogin); navigateToLogin(); return true; } From fa9ee50d2e3f13a5c7af35206fb582859812edfb Mon Sep 17 00:00:00 2001 From: kitretsu2809 Date: Mon, 19 Aug 2024 02:40:25 +0530 Subject: [PATCH 14/31] fix:WebSocket Issue --- frontend/hooks/useWebsocket.tsx | 8 ++++---- frontend/interface/interface.ts | 19 ++++++++++++++++++- frontend/services/api/api.ts | 15 ++++++++------- frontend/services/url-builder/url-builder.ts | 6 +++--- frontend/utils/session/getSessionUser.ts | 4 ++-- frontend/utils/session/getSessionUserId.ts | 2 +- frontend/utils/session/setSessionUser.ts | 2 +- 7 files changed, 37 insertions(+), 19 deletions(-) diff --git a/frontend/hooks/useWebsocket.tsx b/frontend/hooks/useWebsocket.tsx index a22160b..f52ddf8 100644 --- a/frontend/hooks/useWebsocket.tsx +++ b/frontend/hooks/useWebsocket.tsx @@ -38,12 +38,12 @@ const useWebsocket=({ //todo-> toast connected to server }; const handleMessage = (event) => - processWebSocketMessage( - { event, + processWebSocketMessage({ + event, setMessages, navigateToLogin:() => router.push("/"), - isChatbot:false, - }); + isChatbot:false,} + ); const handleClose = (event) => handleWebSocketClose(event, () => router.push("/")); const handleError = handleWebSocketError; diff --git a/frontend/interface/interface.ts b/frontend/interface/interface.ts index 852afd6..8bfeef1 100644 --- a/frontend/interface/interface.ts +++ b/frontend/interface/interface.ts @@ -206,4 +206,21 @@ export interface AlertSameUserProps { export interface AlertServerErrorProps { reason: string; navigateToLogin: () => void; -} \ No newline at end of file +} + +export interface WebSocketURLParams { + userId: string; + username: string; + channel: string; + topic?: string; +} + +export interface URLBuilderParams { + host: string; + port: string; + protocol: string; +} + +export interface LeaveChatURLParams { + userID: string; +} diff --git a/frontend/services/api/api.ts b/frontend/services/api/api.ts index 16067f8..2e661f4 100644 --- a/frontend/services/api/api.ts +++ b/frontend/services/api/api.ts @@ -1,11 +1,12 @@ export function initializeWebSocketConnection( - url: string, - onOpen: (event: Event) => void, - onMessage: (event: MessageEvent) => void, - onClose: (event: CloseEvent) => void, - onError: (event: Event) => void -) : WebSocket{ - const socket = new WebSocket(url); + url, + onOpen, + onMessage, + onClose, + onError, +) { + console.log("WebSocket URL:", url); + const socket = new WebSocket(url); socket.onopen = onOpen; socket.onmessage = onMessage; socket.onclose = onClose; diff --git a/frontend/services/url-builder/url-builder.ts b/frontend/services/url-builder/url-builder.ts index 49a3fde..b9e2ae3 100644 --- a/frontend/services/url-builder/url-builder.ts +++ b/frontend/services/url-builder/url-builder.ts @@ -1,6 +1,6 @@ -export function buildWebSocketURL(userId, username, channel, topic?) { - const host = process.env.NEXT_PUBLIC_BACKEND_HOST; - const port = process.env.NEXT_PUBLIC_BACKEND_PORT; +export function buildWebSocketURL(userId:string, username:string, channel:string, topic?:string) { + const host: string = process.env.NEXT_PUBLIC_BACKEND_HOST || 'localhost'; + const port: string = process.env.NEXT_PUBLIC_BACKEND_PORT || '443'; const protocol = process.env.NEXT_PUBLIC_BACKEND_ENVIRONMENT === "development" ? "ws" diff --git a/frontend/utils/session/getSessionUser.ts b/frontend/utils/session/getSessionUser.ts index 2f06d78..e047f2a 100644 --- a/frontend/utils/session/getSessionUser.ts +++ b/frontend/utils/session/getSessionUser.ts @@ -1,9 +1,9 @@ "use client"; -export default function getSessionUser() : string | undefined { +export default function getSessionUser() { const username = sessionStorage.getItem("username"); if (!username) { - return undefined; + return; } return username; } \ No newline at end of file diff --git a/frontend/utils/session/getSessionUserId.ts b/frontend/utils/session/getSessionUserId.ts index 12fe242..da2ab63 100644 --- a/frontend/utils/session/getSessionUserId.ts +++ b/frontend/utils/session/getSessionUserId.ts @@ -1,6 +1,6 @@ "use client"; -export default function getSessionUserId(): string | null { +export default function getSessionUserId() { const a = sessionStorage.getItem("userID"); return a; } \ No newline at end of file diff --git a/frontend/utils/session/setSessionUser.ts b/frontend/utils/session/setSessionUser.ts index 48c6fac..ce3ac2f 100644 --- a/frontend/utils/session/setSessionUser.ts +++ b/frontend/utils/session/setSessionUser.ts @@ -1,5 +1,5 @@ "use client"; -export default function setSessionUser(username: string) { +export default function setSessionUser(username) { sessionStorage.setItem("username", username); } \ No newline at end of file From 2d30b9e3eaa903f39f039693b5bab3235464127e Mon Sep 17 00:00:00 2001 From: kitretsu2809 Date: Mon, 19 Aug 2024 02:45:23 +0530 Subject: [PATCH 15/31] fix:db localhost was changed --- backend/db/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/db/client.go b/backend/db/client.go index 8131869..bd9c512 100644 --- a/backend/db/client.go +++ b/backend/db/client.go @@ -24,7 +24,7 @@ func Init() { func redisInit(portNumber, dbNumber int, password string) { ctx = context.Background() redisClient = redis.NewClient(&redis.Options{ - Addr: fmt.Sprintf("localhost", portNumber), //port number can be changed as per our wish + Addr: fmt.Sprintf("redis:%v", portNumber), //port number can be changed as per our wish Password: password, DB: dbNumber, }) From 22f6503eb5ab2d9b1059b9b7029026430bcc6dd9 Mon Sep 17 00:00:00 2001 From: kitretsu2809 Date: Tue, 20 Aug 2024 17:47:31 +0530 Subject: [PATCH 16/31] fix: url-builder updated: --- backend/db/client.go | 2 +- .../components/chatbot/chatbotLoginModal.tsx | 56 +++++++++++-------- frontend/components/topicSelectionModal.tsx | 2 +- frontend/services/url-builder/url-builder.ts | 2 +- 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/backend/db/client.go b/backend/db/client.go index bd9c512..8131869 100644 --- a/backend/db/client.go +++ b/backend/db/client.go @@ -24,7 +24,7 @@ func Init() { func redisInit(portNumber, dbNumber int, password string) { ctx = context.Background() redisClient = redis.NewClient(&redis.Options{ - Addr: fmt.Sprintf("redis:%v", portNumber), //port number can be changed as per our wish + Addr: fmt.Sprintf("localhost", portNumber), //port number can be changed as per our wish Password: password, DB: dbNumber, }) diff --git a/frontend/components/chatbot/chatbotLoginModal.tsx b/frontend/components/chatbot/chatbotLoginModal.tsx index c52ad8e..ebcb0c4 100644 --- a/frontend/components/chatbot/chatbotLoginModal.tsx +++ b/frontend/components/chatbot/chatbotLoginModal.tsx @@ -5,41 +5,47 @@ import getSessionUserId from "../../utils/session/getSessionUserId"; import setSessionUser from "../../utils/session/setSessionUser"; import removeSessionUserId from "../../utils/session/removeSessionUserId"; import checkAndPromptSessionChange from "../../utils/alerts/checkAndPromptSessionChange"; -import { TopicDropdown } from "../topicDropdown"; -interface ChatBotLoginModalProps { + +interface LoginModalProps { onClose: () => void; + redirect: string; } -type Topic = "SELECT A TOPIC" | "Option 1" | "Option 2" | string ; -const ChatBotLoginModal: React.FC = ({ onClose }) => { - const popupRef = useRef(null); + +const LoginModal: React.FC = ({ onClose, redirect }) => { + const popupRef = useRef(null); const [username, setUsername] = useState(""); - const [topic, setTopic] = useState("SELECT A TOPIC"); const router = useRouter(); - useEffect(() => { - const handleClickOutside = (event: MouseEvent) => { - if (popupRef.current && !popupRef.current.contains(event.target as Node)) { - onClose(); - } - }; - document.addEventListener("mousedown", handleClickOutside); - return () => document.removeEventListener("mousedown", - handleClickOutside); - }, [popupRef, - onClose]); + const handleUsernameChange = (event: React.ChangeEvent) => { setUsername(event.target.value); }; + const handleEnterClick = (event: React.KeyboardEvent) => { if (event.key === "Enter") { handleChatWithUsClick(); } }; + + useEffect(() => { + const handleClickOutside = (event: MouseEvent) => { + if (popupRef.current && !popupRef.current.contains(event.target as Node)) { + onClose(); + } + }; + + document.addEventListener("mousedown", handleClickOutside); + return () => document.removeEventListener("mousedown", handleClickOutside); + }, [onClose]); + const handleChatWithUsClick = async () => { + const chatType = redirect; const currentUser = getSessionUser(); const currentUserId = getSessionUserId(); + const query = { channel: chatType }; + if (currentUser && currentUserId) { if (currentUser === username) { - router.push(`/chat_bot?topic=${encodeURIComponent(topic)}`); + router.push(`/chat?${new URLSearchParams(query).toString()}`); } else { const hasChanged = await checkAndPromptSessionChange( currentUser, @@ -47,17 +53,19 @@ const ChatBotLoginModal: React.FC = ({ onClose }) => { () => { removeSessionUserId(); setSessionUser(username); - } + }, ); if (hasChanged) { - router.push(`/chat_bot?topic=${encodeURIComponent(topic)}`); + router.push(`/chat?${new URLSearchParams(query).toString()}`); } } } else { setSessionUser(username); - router.push(`/chat_bot?topic=${encodeURIComponent(topic)}`); + router.push(`/chat?${new URLSearchParams(query).toString()}`); } }; + + return (
    = ({ onClose }) => { onKeyDown={handleEnterClick} />
    -
    - START ASKING + CHAT WITH US
    ); }; -export default ChatBotLoginModal; \ No newline at end of file + +export default LoginModal; diff --git a/frontend/components/topicSelectionModal.tsx b/frontend/components/topicSelectionModal.tsx index 95e2147..1921a4c 100644 --- a/frontend/components/topicSelectionModal.tsx +++ b/frontend/components/topicSelectionModal.tsx @@ -13,7 +13,7 @@ const TopicSelectionModal: React.FC = ({ onClose }) => > Close -
    +
    ); }; diff --git a/frontend/services/url-builder/url-builder.ts b/frontend/services/url-builder/url-builder.ts index b9e2ae3..ac79aeb 100644 --- a/frontend/services/url-builder/url-builder.ts +++ b/frontend/services/url-builder/url-builder.ts @@ -1,6 +1,6 @@ export function buildWebSocketURL(userId:string, username:string, channel:string, topic?:string) { const host: string = process.env.NEXT_PUBLIC_BACKEND_HOST || 'localhost'; - const port: string = process.env.NEXT_PUBLIC_BACKEND_PORT || '443'; + const port: string = process.env.NEXT_PUBLIC_BACKEND_PORT || '1323'; const protocol = process.env.NEXT_PUBLIC_BACKEND_ENVIRONMENT === "development" ? "ws" From 870ddd038ea62387284f38a903d4a04ef8411195 Mon Sep 17 00:00:00 2001 From: kitretsu2809 Date: Sun, 1 Sep 2024 20:56:41 +0530 Subject: [PATCH 17/31] Fix:more fixes --- backend/db/client.go | 2 +- frontend/components/chat/chatContainer.tsx | 41 +++++++++++++++++++- frontend/services/api/api.ts | 15 ++++--- frontend/services/url-builder/url-builder.ts | 16 ++++---- 4 files changed, 55 insertions(+), 19 deletions(-) diff --git a/backend/db/client.go b/backend/db/client.go index 8131869..bd9c512 100644 --- a/backend/db/client.go +++ b/backend/db/client.go @@ -24,7 +24,7 @@ func Init() { func redisInit(portNumber, dbNumber int, password string) { ctx = context.Background() redisClient = redis.NewClient(&redis.Options{ - Addr: fmt.Sprintf("localhost", portNumber), //port number can be changed as per our wish + Addr: fmt.Sprintf("redis:%v", portNumber), //port number can be changed as per our wish Password: password, DB: dbNumber, }) diff --git a/frontend/components/chat/chatContainer.tsx b/frontend/components/chat/chatContainer.tsx index 6dd2585..75a1a1b 100644 --- a/frontend/components/chat/chatContainer.tsx +++ b/frontend/components/chat/chatContainer.tsx @@ -5,7 +5,7 @@ import { useState, useEffect } from "react"; import Avatar1 from "../../assets/avatars/avatar_1.svg"; import Avatar2 from "../../assets/avatars/avatar_2.svg"; import Avatar3 from "../../assets/avatars/avatar_3.svg"; -import Avatar4 from "../../assets/avatars/avatar_4.svg"; +import Avatar4 from "../../assets/avatars/avatar_4.svg";`` import Avatar5 from "../../assets/avatars/avatar_5.svg"; import Avatar6 from "../../assets/avatars/avatar_6.svg"; import Avatar7 from "../../assets/avatars/avatar_7.svg"; @@ -58,7 +58,44 @@ const ChatContainer: React.FC = ({ messages, messagesEndRef message.isSent ? "justify-end" : "justify-start" } mb-4 mx-6`} > - {/* ... (rest of the message rendering code is the same as before) */} +
    +
    +
    +
    + +
    +
    + {message.username} +
    +
    +
    +
    +
    {message.text}
    +
    +
    + {formatTime(message.timestamp)} +
    +
    +
    +
    ))}
diff --git a/frontend/services/api/api.ts b/frontend/services/api/api.ts index 2e661f4..16067f8 100644 --- a/frontend/services/api/api.ts +++ b/frontend/services/api/api.ts @@ -1,12 +1,11 @@ export function initializeWebSocketConnection( - url, - onOpen, - onMessage, - onClose, - onError, -) { - console.log("WebSocket URL:", url); - const socket = new WebSocket(url); + url: string, + onOpen: (event: Event) => void, + onMessage: (event: MessageEvent) => void, + onClose: (event: CloseEvent) => void, + onError: (event: Event) => void +) : WebSocket{ + const socket = new WebSocket(url); socket.onopen = onOpen; socket.onmessage = onMessage; socket.onclose = onClose; diff --git a/frontend/services/url-builder/url-builder.ts b/frontend/services/url-builder/url-builder.ts index ac79aeb..7b3b579 100644 --- a/frontend/services/url-builder/url-builder.ts +++ b/frontend/services/url-builder/url-builder.ts @@ -1,6 +1,6 @@ -export function buildWebSocketURL(userId:string, username:string, channel:string, topic?:string) { - const host: string = process.env.NEXT_PUBLIC_BACKEND_HOST || 'localhost'; - const port: string = process.env.NEXT_PUBLIC_BACKEND_PORT || '1323'; +export function buildWebSocketURL(userId: string | null, username: string, channel?: string, topic?: string): string { + const host = process.env.NEXT_PUBLIC_BACKEND_HOST || "localhost"; + const port = process.env.NEXT_PUBLIC_BACKEND_PORT || 1323; const protocol = process.env.NEXT_PUBLIC_BACKEND_ENVIRONMENT === "development" ? "ws" @@ -10,12 +10,12 @@ export function buildWebSocketURL(userId:string, username:string, channel:string channel: channel || "public", name: username, userID: userId || "0", - topic: topic || null, + topic: topic || '', }); return `${baseUrl}?${params.toString()}`; } -export function projectURLbuildr() { +export function projectURLbuildr(): string { const host = process.env.NEXT_PUBLIC_BACKEND_HOST; const port = process.env.NEXT_PUBLIC_BACKEND_PORT; const protocol = @@ -26,7 +26,7 @@ export function projectURLbuildr() { return baseUrl; } -export function leaveChatURLbuildr(userID) { +export function leaveChatURLbuildr(userID: string): string { const host = process.env.NEXT_PUBLIC_BACKEND_HOST; const port = process.env.NEXT_PUBLIC_BACKEND_PORT; const protocol = @@ -41,7 +41,7 @@ export function leaveChatURLbuildr(userID) { return `${baseUrl}?${params.toString()}`; } -export function subscribeURLbuildr() { +export function subscribeURLbuildr(): string { const host = process.env.NEXT_PUBLIC_BACKEND_HOST; const port = process.env.NEXT_PUBLIC_BACKEND_PORT; const protocol = @@ -50,4 +50,4 @@ export function subscribeURLbuildr() { : "https"; const baseUrl = `${protocol}://${host}:${port}/subscribe`; return baseUrl; -} \ No newline at end of file +} From e0964e7a1c7028098e2e97d3ce1983c2ca5ecdb5 Mon Sep 17 00:00:00 2001 From: kitretsu2809 Date: Tue, 24 Sep 2024 17:05:44 +0530 Subject: [PATCH 18/31] Fix:more fixes --- frontend/components/chat/chatContainer.tsx | 87 +++++++++++++++++----- frontend/components/chat/chatInputBox.tsx | 4 +- frontend/components/chat/loginModal.tsx | 5 +- frontend/interface/interface.ts | 18 +++++ 4 files changed, 87 insertions(+), 27 deletions(-) diff --git a/frontend/components/chat/chatContainer.tsx b/frontend/components/chat/chatContainer.tsx index 6dd2585..56ea59f 100644 --- a/frontend/components/chat/chatContainer.tsx +++ b/frontend/components/chat/chatContainer.tsx @@ -1,7 +1,6 @@ -import React, { MutableRefObject } from "react"; +import React, { useEffect, useState } from "react"; import Image from "next/image"; import moment from "moment"; -import { useState, useEffect } from "react"; import Avatar1 from "../../assets/avatars/avatar_1.svg"; import Avatar2 from "../../assets/avatars/avatar_2.svg"; import Avatar3 from "../../assets/avatars/avatar_3.svg"; @@ -18,53 +17,101 @@ import Avatar13 from "../../assets/avatars/avatar_13.svg"; import Avatar14 from "../../assets/avatars/avatar_14.svg"; import Avatar15 from "../../assets/avatars/avatar_15.svg"; import getAvatar from "../../utils/session/getAvatar"; -import { ChatContainerProps , Message } from "../../interface/interface"; - +import {Message ,ChatContainerProps } from "../../interface/interface" +const AvatarList = [ + Avatar1, + Avatar2, + Avatar3, + Avatar4, + Avatar5, + Avatar6, + Avatar7, + Avatar8, + Avatar9, + Avatar10, + Avatar11, + Avatar12, + Avatar13, + Avatar14, + Avatar15, +]; const ChatContainer: React.FC = ({ messages, messagesEndRef }) => { + const [Avatar, setAvatar] = useState(Avatar1); + const formatTime = (timestamp: number) => { const date = new Date(timestamp * 1000); return moment(date).format("hh:mm A"); }; - const AvatarList = [Avatar1, Avatar2, Avatar3, Avatar4, Avatar5, Avatar6, Avatar7, Avatar8, Avatar9, Avatar10, Avatar11, Avatar12, Avatar13, Avatar14,   - Avatar15]; - const   - [Avatar, setAvatar] = useState(Avatar1); - useEffect(() => { if (messagesEndRef.current) { messagesEndRef.current.scrollIntoView({ behavior: "smooth" }); } - const loadAvatar = async () => { + async function loadAvatar() { const AvatarId = await getAvatar(); - const Avatar = AvatarList[AvatarId]; - setAvatar(Avatar); - }; + const selectedAvatar = AvatarList[AvatarId]; + setAvatar(selectedAvatar); + } loadAvatar(); - }, [messages]); + }, [messages]); return (
    - {messages.map((message, index) => ( + {messages?.map((message: Message, index: number) => (
  • - {/* ... (rest of the message rendering code is the same as before) */} +
    +
    +
    +
    + +
    +
    + {message.username} +
    +
    +
    +
    +
    {message.text}
    +
    +
    + {formatTime(message.timestamp)} +
    +
    +
    +
  • ))}
); -} +}; export default ChatContainer; \ No newline at end of file diff --git a/frontend/components/chat/chatInputBox.tsx b/frontend/components/chat/chatInputBox.tsx index 95070db..bb0c3b6 100644 --- a/frontend/components/chat/chatInputBox.tsx +++ b/frontend/components/chat/chatInputBox.tsx @@ -1,10 +1,8 @@ import React, { useState, useRef } from "react"; import sendLogo from "../../assets/send.svg"; import Image from "next/image"; +import { ChatInputBoxProps } from "../../interface/interface"; -interface ChatInputBoxProps { - socketRef: React.MutableRefObject; -} const ChatInputBox: React.FC = ({ socketRef }) => { const [newMessage, setNewMessage] = useState(""); diff --git a/frontend/components/chat/loginModal.tsx b/frontend/components/chat/loginModal.tsx index 3a283e4..adc051f 100644 --- a/frontend/components/chat/loginModal.tsx +++ b/frontend/components/chat/loginModal.tsx @@ -6,10 +6,7 @@ import setSessionUser from "../../utils/session/setSessionUser"; import removeSessionUserId from "../../utils/session/removeSessionUserId"; import checkAndPromptSessionChange from "../../utils/alerts/checkAndPromptSessionChange"; import { toast } from "react-toastify"; // Assuming you're using react-toastify -interface LoginModalProps { - onClose: () => void; - redirect: string; -} +import {LoginModalProps} from "../../interface/interface" const LoginModal: React.FC = ({ onClose, redirect }) => { const popupRef = useRef(null); diff --git a/frontend/interface/interface.ts b/frontend/interface/interface.ts index 8bfeef1..9266b11 100644 --- a/frontend/interface/interface.ts +++ b/frontend/interface/interface.ts @@ -224,3 +224,21 @@ export interface URLBuilderParams { export interface LeaveChatURLParams { userID: string; } + +export interface ChatContainerProps { + messages: Message[]; // An array of message objects + messagesEndRef: React.RefObject; // A ref for auto-scrolling to the bottom of the chat +} + +export interface AvatarListProps { + AvatarList: string[]; // List of avatar image paths/URLs +} + +export interface ChatInputBoxProps { + socketRef: React.MutableRefObject; +} + +export interface LoginModalProps { + onClose: () => void; + redirect: string; +} \ No newline at end of file From 0e79cd3ef71edc525a0488970cbbc806b521d074 Mon Sep 17 00:00:00 2001 From: kitretsu2809 Date: Tue, 24 Sep 2024 18:04:37 +0530 Subject: [PATCH 19/31] Fix:more fixes --- frontend/components/chat/chatContainer.tsx | 143 +++++++++--------- frontend/components/chat/loginModal.tsx | 13 +- .../components/chatbot/chatbotLoginModal.tsx | 11 +- frontend/hooks/useLeaveChat.tsx | 49 +++--- frontend/hooks/useLoadSettings.tsx | 4 +- frontend/hooks/useSettings.tsx | 5 +- frontend/interface/interface.ts | 14 +- frontend/package-lock.json | 19 ++- frontend/package.json | 3 +- .../alerts/checkAndPromptSessionChange.ts | 93 +++++++----- 10 files changed, 193 insertions(+), 161 deletions(-) diff --git a/frontend/components/chat/chatContainer.tsx b/frontend/components/chat/chatContainer.tsx index 56ea59f..89e6c0c 100644 --- a/frontend/components/chat/chatContainer.tsx +++ b/frontend/components/chat/chatContainer.tsx @@ -1,6 +1,6 @@ -import React, { useEffect, useState } from "react"; +import React, { useState, useEffect } from "react"; +import Echofy from "../../assets/logo.svg"; import Image from "next/image"; -import moment from "moment"; import Avatar1 from "../../assets/avatars/avatar_1.svg"; import Avatar2 from "../../assets/avatars/avatar_2.svg"; import Avatar3 from "../../assets/avatars/avatar_3.svg"; @@ -16,35 +16,31 @@ import Avatar12 from "../../assets/avatars/avatar_12.svg"; import Avatar13 from "../../assets/avatars/avatar_13.svg"; import Avatar14 from "../../assets/avatars/avatar_14.svg"; import Avatar15 from "../../assets/avatars/avatar_15.svg"; +import parseMessageText from "../../utils/chatbot_formatting/parseMessageText"; import getAvatar from "../../utils/session/getAvatar"; +import { ChatContainerProps, Message } from "../../interface/interface"; -import {Message ,ChatContainerProps } from "../../interface/interface" +export default function ChatContainer({ messages, messagesEndRef }: ChatContainerProps): React.JSX.Element { + const [filteredMessage, setFilteredMessage] = useState([]); -const AvatarList = [ - Avatar1, - Avatar2, - Avatar3, - Avatar4, - Avatar5, - Avatar6, - Avatar7, - Avatar8, - Avatar9, - Avatar10, - Avatar11, - Avatar12, - Avatar13, - Avatar14, - Avatar15, -]; - -const ChatContainer: React.FC = ({ messages, messagesEndRef }) => { - const [Avatar, setAvatar] = useState(Avatar1); - - const formatTime = (timestamp: number) => { - const date = new Date(timestamp * 1000); - return moment(date).format("hh:mm A"); - }; + const AvatarList = [ + Avatar1, + Avatar2, + Avatar3, + Avatar4, + Avatar5, + Avatar6, + Avatar7, + Avatar8, + Avatar9, + Avatar10, + Avatar11, + Avatar12, + Avatar13, + Avatar14, + Avatar15, + ]; + const [Avatar, setAvatar] = useState(Avatar1.src); useEffect(() => { if (messagesEndRef.current) { @@ -53,65 +49,66 @@ const ChatContainer: React.FC = ({ messages, messagesEndRef async function loadAvatar() { const AvatarId = await getAvatar(); - const selectedAvatar = AvatarList[AvatarId]; - setAvatar(selectedAvatar); + const Avatar = AvatarList[AvatarId]; + setAvatar(Avatar.src); } - loadAvatar(); }, [messages]); + useEffect(() => { + const filterMessages = () => { + const newMessages = messages.filter((message) => { + // message is already an object, no need to parse it + return !(message.userID && message.userID.startsWith("chatbot")); + }); + return newMessages; + }; + const newFilteredMessages = filterMessages(); + setFilteredMessage(newFilteredMessages as Message[]); + }, [messages]); + return (
    - {messages?.map((message: Message, index: number) => ( -
  • -
    { + return ( +
  • -
    -
    -
    - -
    -
    - {message.username} -
    -
    +
    -
    -
    {message.text}
    +
    +
    + +
    +
    {message.username}
    -
    - {formatTime(message.timestamp)} +
    +
    +
    + {message.isSent ? message.text : parseMessageText(message.text)} +
    +
    -
    -
  • - ))} + + ); + })}
); -}; - -export default ChatContainer; \ No newline at end of file +} diff --git a/frontend/components/chat/loginModal.tsx b/frontend/components/chat/loginModal.tsx index adc051f..e59269b 100644 --- a/frontend/components/chat/loginModal.tsx +++ b/frontend/components/chat/loginModal.tsx @@ -7,7 +7,6 @@ import removeSessionUserId from "../../utils/session/removeSessionUserId"; import checkAndPromptSessionChange from "../../utils/alerts/checkAndPromptSessionChange"; import { toast } from "react-toastify"; // Assuming you're using react-toastify import {LoginModalProps} from "../../interface/interface" - const LoginModal: React.FC = ({ onClose, redirect }) => { const popupRef = useRef(null); const [username, setUsername] = useState(""); @@ -58,14 +57,14 @@ const LoginModal: React.FC = ({ onClose, redirect }) => { if (currentUser === username) { router.push(`/chat?${queryParams.toString()}`); } else { - const hasChanged = await checkAndPromptSessionChange( - currentUser, - username, - () => { + const hasChanged = await checkAndPromptSessionChange({ + currentUsername: currentUser, + inputUsername: username, + onConfirm: () => { removeSessionUserId(); setSessionUser(username); - } - ); + }, + }); if (hasChanged) { router.push(`/chat?${queryParams.toString()}`); } diff --git a/frontend/components/chatbot/chatbotLoginModal.tsx b/frontend/components/chatbot/chatbotLoginModal.tsx index ebcb0c4..e9d7d61 100644 --- a/frontend/components/chatbot/chatbotLoginModal.tsx +++ b/frontend/components/chatbot/chatbotLoginModal.tsx @@ -47,14 +47,15 @@ const LoginModal: React.FC = ({ onClose, redirect }) => { if (currentUser === username) { router.push(`/chat?${new URLSearchParams(query).toString()}`); } else { - const hasChanged = await checkAndPromptSessionChange( - currentUser, - username, - () => { + const hasChanged = await checkAndPromptSessionChange({ + currentUsername: currentUser, + inputUsername: username, + onConfirm: () => { removeSessionUserId(); setSessionUser(username); }, - ); + }); + if (hasChanged) { router.push(`/chat?${new URLSearchParams(query).toString()}`); } diff --git a/frontend/hooks/useLeaveChat.tsx b/frontend/hooks/useLeaveChat.tsx index a666282..2b514ea 100644 --- a/frontend/hooks/useLeaveChat.tsx +++ b/frontend/hooks/useLeaveChat.tsx @@ -1,26 +1,35 @@ +// useLeaveChat.ts import { useEffect } from "react"; import getSessionUserId from "../utils/session/getSessionUserId"; import removeSessionUserId from "../utils/session/removeSessionUserId"; import { leaveChat } from "../services/api/leaveChatApi"; import { NextRouter } from "next/router"; -const useLeaveChat=(router:NextRouter)=>{ - useEffect(() => { - const leaveChatOnNavigation = () => { - leaveChat(getSessionUserId()); - removeSessionUserId(); - }; - const handleBeforeUnload = (e:BeforeUnloadEvent) => { - leaveChat(getSessionUserId()); - }; - - router.events.on("routeChangeStart", leaveChatOnNavigation); - window.addEventListener("beforeunload", handleBeforeUnload); - - return () => { - router.events.off("routeChangeStart", leaveChatOnNavigation); - window.removeEventListener("beforeunload", handleBeforeUnload); - }; - }, [router]); -} -export default useLeaveChat; \ No newline at end of file +const useLeaveChat = (router: NextRouter) => { + useEffect(() => { + const leaveChatOnNavigation = () => { + const userId = getSessionUserId(); + if (userId) { + leaveChat(userId); + removeSessionUserId(); + } + }; + + const handleBeforeUnload = (e: BeforeUnloadEvent) => { + const userId = getSessionUserId(); + if (userId) { + leaveChat(userId); + } + }; + + router.events.on("routeChangeStart", leaveChatOnNavigation); + window.addEventListener("beforeunload", handleBeforeUnload); + + return () => { + router.events.off("routeChangeStart", leaveChatOnNavigation); + window.removeEventListener("beforeunload", handleBeforeUnload); + }; + }, [router]); +}; + +export default useLeaveChat; diff --git a/frontend/hooks/useLoadSettings.tsx b/frontend/hooks/useLoadSettings.tsx index df613cc..990e8f7 100644 --- a/frontend/hooks/useLoadSettings.tsx +++ b/frontend/hooks/useLoadSettings.tsx @@ -1,8 +1,7 @@ import { useEffect } from 'react'; import { UseLoadSettingProps } from '../interface/interface'; - -const useLoadSetting = (setSoundEnabled, setNotificationsEnabled) => { +const useLoadSetting = ({ setSoundEnabled, setNotificationsEnabled }: UseLoadSettingProps) => { useEffect(() => { const savedSoundEnabled = localStorage.getItem("soundEnabled"); const savedNotificationsEnabled = localStorage.getItem("notificationsEnabled"); @@ -18,3 +17,4 @@ const useLoadSetting = (setSoundEnabled, setNotificationsEnabled) => { }; export default useLoadSetting; + diff --git a/frontend/hooks/useSettings.tsx b/frontend/hooks/useSettings.tsx index b61f94d..344eb49 100644 --- a/frontend/hooks/useSettings.tsx +++ b/frontend/hooks/useSettings.tsx @@ -1,6 +1,7 @@ import { useEffect } from "react"; import { UseSettingsProps } from "../interface/interface"; -function useSettings(soundEnabled, notificationsEnabled) { + +const useSettings = ({ soundEnabled, notificationsEnabled }: UseSettingsProps) => { useEffect(() => { localStorage.setItem("soundEnabled", JSON.stringify(soundEnabled)); }, [soundEnabled]); @@ -8,6 +9,6 @@ function useSettings(soundEnabled, notificationsEnabled) { useEffect(() => { localStorage.setItem("notificationsEnabled", JSON.stringify(notificationsEnabled)); }, [notificationsEnabled]); -} +}; export default useSettings; diff --git a/frontend/interface/interface.ts b/frontend/interface/interface.ts index 9266b11..5d5a5c7 100644 --- a/frontend/interface/interface.ts +++ b/frontend/interface/interface.ts @@ -95,6 +95,7 @@ export interface MailProps { username: string; text: string; timestamp: number; + userID: string; } export interface ChatContainerProps { messages: Message[]; // Assuming messages are serialized JSON strings @@ -241,4 +242,15 @@ export interface ChatInputBoxProps { export interface LoginModalProps { onClose: () => void; redirect: string; -} \ No newline at end of file +} + +export type CheckAndPromptSessionChange = ( + currentUser: string, + newUsername: string, + onSessionChange: () => void +) => Promise; + +export type GetSessionUser = () => string | null; +export type GetSessionUserId = () => string | null; +export type SetSessionUser = (username: string) => void; +export type RemoveSessionUserId = () => void; \ No newline at end of file diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 4511f5c..19bf341 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -25,7 +25,8 @@ "tailwindcss": "^3.3.3" }, "devDependencies": { - "@types/react": "18.3.3", + "@types/node": "^22.6.1", + "@types/react": "^18.3.3", "typescript": "5.5.4" } }, @@ -781,11 +782,12 @@ "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==" }, "node_modules/@types/node": { - "version": "20.8.9", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.9.tgz", - "integrity": "sha512-UzykFsT3FhHb1h7yD4CA4YhBHq545JC0YnEz41xkipN88eKQtL6rSgocL5tbAP6Ola9Izm/Aw4Ora8He4x0BHg==", + "version": "22.6.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.6.1.tgz", + "integrity": "sha512-V48tCfcKb/e6cVUigLAaJDAILdMP0fUW6BidkPK4GpGjXcfbnoHasCZDwz3N3yVt5we2RHm4XTQCpv0KJz9zqw==", + "license": "MIT", "dependencies": { - "undici-types": "~5.26.4" + "undici-types": "~6.19.2" } }, "node_modules/@types/prop-types": { @@ -2943,9 +2945,10 @@ } }, "node_modules/undici-types": { - "version": "5.26.5", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", - "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==" + "version": "6.19.8", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", + "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==", + "license": "MIT" }, "node_modules/update-browserslist-db": { "version": "1.0.13", diff --git a/frontend/package.json b/frontend/package.json index 4fb53bf..31c6f9c 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -27,7 +27,8 @@ "tailwindcss": "^3.3.3" }, "devDependencies": { - "@types/react": "18.3.3", + "@types/node": "^22.6.1", + "@types/react": "^18.3.3", "typescript": "5.5.4" } } diff --git a/frontend/utils/alerts/checkAndPromptSessionChange.ts b/frontend/utils/alerts/checkAndPromptSessionChange.ts index 8108af5..04a757c 100644 --- a/frontend/utils/alerts/checkAndPromptSessionChange.ts +++ b/frontend/utils/alerts/checkAndPromptSessionChange.ts @@ -1,49 +1,58 @@ "use client"; import Swal, { SweetAlertResult } from "sweetalert2"; -export default async function checkAndPromptSessionChange( - currentUsername: string | null, - inputUsername: string, - onConfirm: () => void, - ) { - if (currentUsername && currentUsername !== inputUsername) { - try { - const result:SweetAlertResult = await Swal.fire({ - title: "Change Username?", - text: `You already have a running session with the username "${currentUsername}". Do you want to change your username?`, - icon: "question", - iconColor: "#3670F5", - - showCancelButton: true, - confirmButtonColor: "3670F5", - cancelButtonColor: "#d33", - confirmButtonText: "Yes, change it!", - }); - - if (result.isConfirmed && inputUsername.length < 20) { - onConfirm(); - return true; - } else { - if (inputUsername.length > 20) { - Swal.fire({ - title: "Username too long", - text: `Please choose a username with less than 20 characters`, - icon: "warning", - - iconColor: "#3670F5", - confirmButtonColor: "3670F5", - confirmButtonText: "OK", - didOpen: (popup:HTMLElement) => { - popup.style.borderRadius = "1rem"; - }, - }); - } - return false; +// Interface for the function parameters +interface CheckAndPromptSessionChangeProps { + currentUsername: string | null; + inputUsername: string; + onConfirm: () => void; +} + +// Function to check and prompt session change using SweetAlert2 +export default async function checkAndPromptSessionChange({ + currentUsername, + inputUsername, + onConfirm, +}: CheckAndPromptSessionChangeProps): Promise { + // Check if the current username exists and differs from the input username + if (currentUsername && currentUsername !== inputUsername) { + try { + const result: SweetAlertResult = await Swal.fire({ + title: "Change Username?", + text: `You already have a running session with the username "${currentUsername}". Do you want to change your username?`, + icon: "question", + iconColor: "#3670F5", + showCancelButton: true, + confirmButtonColor: "#3670F5", + cancelButtonColor: "#d33", + confirmButtonText: "Yes, change it!", + }); + + // If the user confirms and the new username is less than 20 characters + if (result.isConfirmed && inputUsername.length < 20) { + onConfirm(); + return true; + } else { + // If the input username exceeds the length limit, display a warning + if (inputUsername.length > 20) { + Swal.fire({ + title: "Username too long", + text: `Please choose a username with less than 20 characters`, + icon: "warning", + iconColor: "#3670F5", + confirmButtonColor: "#3670F5", + confirmButtonText: "OK", + didOpen: (popup: HTMLElement) => { + popup.style.borderRadius = "1rem"; + }, + }); } - } catch (error) { - console.error("Error with SweetAlert2:", error); return false; } + } catch (error) { + console.error("Error with SweetAlert2:", error); + return false; } - return false; - } \ No newline at end of file + } + return false; +} From 5b97a78c06c82ea93ad0e72ea5bdb92dcfbbe1ce Mon Sep 17 00:00:00 2001 From: kitretsu2809 Date: Tue, 24 Sep 2024 18:44:31 +0530 Subject: [PATCH 20/31] Fix:more fixes --- frontend/hooks/useWebsocket.tsx | 3 + frontend/interface/interface.ts | 60 ++++++++++++-- frontend/pages/chat.tsx | 4 +- frontend/pages/chat_bot.tsx | 6 +- frontend/pages/index.tsx | 2 +- frontend/services/api/api.ts | 30 ++++--- frontend/services/api/leaveChatApi.ts | 12 ++- frontend/services/api/projectsApi.ts | 13 ++- frontend/services/api/subscribeApi.ts | 46 ++++++----- frontend/services/url-builder/url-builder.ts | 87 ++++++++++++-------- 10 files changed, 176 insertions(+), 87 deletions(-) diff --git a/frontend/hooks/useWebsocket.tsx b/frontend/hooks/useWebsocket.tsx index f52ddf8..fc852f8 100644 --- a/frontend/hooks/useWebsocket.tsx +++ b/frontend/hooks/useWebsocket.tsx @@ -49,10 +49,12 @@ const useWebsocket=({ const handleError = handleWebSocketError; const socket = initializeWebSocketConnection( url, + { handleOpen, handleMessage, handleClose, handleError, + } ); socketRef.current = socket; @@ -101,6 +103,7 @@ const useWebsocket=({ username: data.sender, timestamp: parseFloat(data.timestamp), avatar: data.url, + userID: data.userID, }, ]); if (soundEnabled) playSound(isSent); diff --git a/frontend/interface/interface.ts b/frontend/interface/interface.ts index 5d5a5c7..72d06cf 100644 --- a/frontend/interface/interface.ts +++ b/frontend/interface/interface.ts @@ -84,6 +84,11 @@ export interface MailProps { AppStore?: string; } + export interface LoginModalProps { + onClose: () => void; + redirect: string; + } + export interface ChatBotLoginModalProps { onClose: () => void; // Function to close the modal } @@ -116,9 +121,9 @@ export interface MailProps { } export interface UseLoadSettingProps { - setSoundEnabled: typeof useState; - setNotificationsEnabled: typeof useState; - } + setSoundEnabled: React.Dispatch>; + setNotificationsEnabled: React.Dispatch>; +} export interface UseSettingsProps { soundEnabled: boolean; @@ -239,10 +244,7 @@ export interface ChatInputBoxProps { socketRef: React.MutableRefObject; } -export interface LoginModalProps { - onClose: () => void; - redirect: string; -} + export type CheckAndPromptSessionChange = ( currentUser: string, @@ -253,4 +255,46 @@ export type CheckAndPromptSessionChange = ( export type GetSessionUser = () => string | null; export type GetSessionUserId = () => string | null; export type SetSessionUser = (username: string) => void; -export type RemoveSessionUserId = () => void; \ No newline at end of file +export type RemoveSessionUserId = () => void; + +export interface LeaveChatResponse { + // Define the expected properties of the response here + success: boolean; + message?: string; +} + +// Define the return type of the fetchProjects function +export type FetchProjectsResponse = Project[]; // Array of projects + +// Define the interface for a project +export interface Project { + id: string; // Adjust the type as per your actual API response + name: string; // Example property + description?: string; // Optional property + // Add more properties as needed based on your project data structure +} + +// Define the interface for the subscribe response +export interface SubscribeResponse { + code: number; + message: string; +} + +// Define the parameters for the subscribe function +export interface SubscribeParams { + email: string; + username: string; + userId: string; + channel: string; + timestamp: number; +} + +// Define an interface for the environment variables +export interface BackendEnvironment { + NEXT_PUBLIC_BACKEND_HOST: string; + NEXT_PUBLIC_BACKEND_PORT: string; + NEXT_PUBLIC_BACKEND_ENVIRONMENT: 'development' | 'production'; +} + +// Create a type for the optional topic parameter + \ No newline at end of file diff --git a/frontend/pages/chat.tsx b/frontend/pages/chat.tsx index c5bf305..7cb1552 100644 --- a/frontend/pages/chat.tsx +++ b/frontend/pages/chat.tsx @@ -23,8 +23,8 @@ export default function Home(){ const socketRef = useRef(null); const messagesEndRef = useRef(null); - useLoadSetting(setSoundEnabled,setNotificationsEnabled); - useSettings(soundEnabled,notificationsEnabled); + useLoadSetting({setSoundEnabled,setNotificationsEnabled}); + useSettings({soundEnabled,notificationsEnabled}); useWebsocket({soundEnabled,channel,socketRef,setMessages,router,setUnreadCount}) useLeaveChat(router); useVisibilityChange({setUnreadCount}); diff --git a/frontend/pages/chat_bot.tsx b/frontend/pages/chat_bot.tsx index 36a2476..f391ee9 100644 --- a/frontend/pages/chat_bot.tsx +++ b/frontend/pages/chat_bot.tsx @@ -1,4 +1,4 @@ -+"use client"; +"use client"; import ChatInputBox from "../components/chat/chatInputBox"; import Box from "../components/mdgBox"; import { useState, useEffect, useRef } from "react"; @@ -22,8 +22,8 @@ export default function Home() { const socketRef = useRef(null); const messagesEndRef = useRef(null); - useLoadSetting(setSoundEnabled,setNotificationsEnabled); - useSettings(soundEnabled,notificationsEnabled); + useLoadSetting({setSoundEnabled,setNotificationsEnabled}); + useSettings({soundEnabled,notificationsEnabled}); useWebsocketForChatbot({socketRef,setMessages,router}); useVisibilityChange({setUnreadCount}); // useLeaveChat(router); diff --git a/frontend/pages/index.tsx b/frontend/pages/index.tsx index 4d0b540..77ea60b 100644 --- a/frontend/pages/index.tsx +++ b/frontend/pages/index.tsx @@ -52,7 +52,7 @@ export default function Home() { )} {isChatBotModalOpen && ( - + )}
diff --git a/frontend/services/api/api.ts b/frontend/services/api/api.ts index 2e661f4..6d41fa2 100644 --- a/frontend/services/api/api.ts +++ b/frontend/services/api/api.ts @@ -1,15 +1,21 @@ +interface WebSocketHandlers { + handleOpen: (event: Event) => void; + handleMessage: (event: MessageEvent) => void; + handleClose: (event: CloseEvent) => void; + handleError: (event: Event) => void; +} + export function initializeWebSocketConnection( - url, - onOpen, - onMessage, - onClose, - onError, -) { + url: string, + handlers: WebSocketHandlers +): WebSocket { console.log("WebSocket URL:", url); - const socket = new WebSocket(url); - socket.onopen = onOpen; - socket.onmessage = onMessage; - socket.onclose = onClose; - socket.onerror = onError; + const socket = new WebSocket(url); + + socket.onopen = handlers.handleOpen; + socket.onmessage = handlers.handleMessage; + socket.onclose = handlers.handleClose; + socket.onerror = handlers.handleError; + return socket; -} \ No newline at end of file +} diff --git a/frontend/services/api/leaveChatApi.ts b/frontend/services/api/leaveChatApi.ts index bfdd3dd..2a4a120 100644 --- a/frontend/services/api/leaveChatApi.ts +++ b/frontend/services/api/leaveChatApi.ts @@ -1,13 +1,17 @@ import axios from "axios"; import { leaveChatURLbuildr } from "../url-builder/url-builder"; +import { LeaveChatResponse } from "../../interface/interface"; -export async function leaveChat(userID: string) { +export async function leaveChat(userID: string): Promise { if (userID) { try { const url = leaveChatURLbuildr(userID); - const response = await axios.post(url, {}); + const response = await axios.post(url, {}); + + return response.data; // Assuming the API returns a response with the properties defined in LeaveChatResponse } catch (error) { - // console.error("Error in leaving chat:", error) + console.error("Error in leaving chat:", error); + return undefined; // Or handle the error as needed } } -} \ No newline at end of file +} diff --git a/frontend/services/api/projectsApi.ts b/frontend/services/api/projectsApi.ts index 72470b0..fb8905e 100644 --- a/frontend/services/api/projectsApi.ts +++ b/frontend/services/api/projectsApi.ts @@ -1,12 +1,17 @@ import axios from "axios"; import { projectURLbuildr } from "../url-builder/url-builder"; -export const fetchProjects = async () => { +import { FetchProjectsResponse, Project } from "../../interface/interface"; + +export const fetchProjects = async (): Promise => { try { const url = projectURLbuildr(); - const res = await axios.get(url); + const res = await axios.get(url); return res.data; } catch (error) { - //todo -> enable sentry logger here + console.error("Error fetching projects:", error); + // todo -> enable sentry logger here + return undefined; // Handle error as needed } -}; \ No newline at end of file +}; + diff --git a/frontend/services/api/subscribeApi.ts b/frontend/services/api/subscribeApi.ts index 3525d47..e362411 100644 --- a/frontend/services/api/subscribeApi.ts +++ b/frontend/services/api/subscribeApi.ts @@ -1,37 +1,45 @@ import axios from "axios"; import { subscribeURLbuildr } from "../url-builder/url-builder"; -interface SubscribeResponse { - code:number; - message: string; -} -const subscribe = async ( - email: string, - username: string, - userId: string, - channel: string, - timestamp: number) : Promise=> { + +import { SubscribeResponse ,SubscribeParams } from "../../interface/interface"; + + +// Convert the subscribe function to TypeScript +const subscribe = async ({ + email, + username, + userId, + channel, + timestamp, +}: SubscribeParams): Promise => { const url = subscribeURLbuildr(); + try { const response = await axios.post( url, { - email: email, - username: username, - userId: userId, - channel: channel, - timestamp: timestamp, + email, + username, + userId, + channel, + timestamp, }, { headers: { "Content-Type": "multipart/form-data", }, - }, + } ); + if (response.status === 200) { return response.data; + } else { + throw new Error("Subscription failed"); } - } catch (error) { - throw error.response?.data; + } catch (error: any) { + // Here, we throw a new error with a message from the server if available + throw new Error(error.response?.data?.message || "An error occurred during subscription"); } }; -export default subscribe; \ No newline at end of file + +export default subscribe; diff --git a/frontend/services/url-builder/url-builder.ts b/frontend/services/url-builder/url-builder.ts index ac79aeb..7d79ff9 100644 --- a/frontend/services/url-builder/url-builder.ts +++ b/frontend/services/url-builder/url-builder.ts @@ -1,39 +1,55 @@ -export function buildWebSocketURL(userId:string, username:string, channel:string, topic?:string) { - const host: string = process.env.NEXT_PUBLIC_BACKEND_HOST || 'localhost'; - const port: string = process.env.NEXT_PUBLIC_BACKEND_PORT || '1323'; - const protocol = - process.env.NEXT_PUBLIC_BACKEND_ENVIRONMENT === "development" - ? "ws" - : "wss"; - const baseUrl = `${protocol}://${host}:${port}/chat`; +import { BackendEnvironment , Topic } from "../../interface/interface"; +// Function to build WebSocket URL +export function buildWebSocketURL( + userId: string, + username: string, + channel: string, + topic?: Topic +): string { + const env: BackendEnvironment = { + NEXT_PUBLIC_BACKEND_HOST: process.env.NEXT_PUBLIC_BACKEND_HOST || 'localhost', + NEXT_PUBLIC_BACKEND_PORT: process.env.NEXT_PUBLIC_BACKEND_PORT || '1323', + NEXT_PUBLIC_BACKEND_ENVIRONMENT: process.env.NEXT_PUBLIC_BACKEND_ENVIRONMENT as 'development' | 'production', + }; + + const protocol = env.NEXT_PUBLIC_BACKEND_ENVIRONMENT === "development" ? "ws" : "wss"; + const baseUrl = `${protocol}://${env.NEXT_PUBLIC_BACKEND_HOST}:${env.NEXT_PUBLIC_BACKEND_PORT}/chat`; + const params = new URLSearchParams({ channel: channel || "public", name: username, userID: userId || "0", - topic: topic || null, + topic: topic || '', }); + return `${baseUrl}?${params.toString()}`; } -export function projectURLbuildr() { - const host = process.env.NEXT_PUBLIC_BACKEND_HOST; - const port = process.env.NEXT_PUBLIC_BACKEND_PORT; - const protocol = - process.env.NEXT_PUBLIC_BACKEND_ENVIRONMENT === "development" - ? "http" - : "https"; - const baseUrl = `${protocol}://${host}:${port}/projects`; +// Function to build project URL +export function projectURLbuildr(): string { + const env: BackendEnvironment = { + NEXT_PUBLIC_BACKEND_HOST: process.env.NEXT_PUBLIC_BACKEND_HOST || 'localhost', + NEXT_PUBLIC_BACKEND_PORT: process.env.NEXT_PUBLIC_BACKEND_PORT || '1323', + NEXT_PUBLIC_BACKEND_ENVIRONMENT: process.env.NEXT_PUBLIC_BACKEND_ENVIRONMENT as 'development' | 'production', + }; + + const protocol = env.NEXT_PUBLIC_BACKEND_ENVIRONMENT === "development" ? "http" : "https"; + const baseUrl = `${protocol}://${env.NEXT_PUBLIC_BACKEND_HOST}:${env.NEXT_PUBLIC_BACKEND_PORT}/projects`; + return baseUrl; } -export function leaveChatURLbuildr(userID) { - const host = process.env.NEXT_PUBLIC_BACKEND_HOST; - const port = process.env.NEXT_PUBLIC_BACKEND_PORT; - const protocol = - process.env.NEXT_PUBLIC_BACKEND_ENVIRONMENT === "development" - ? "http" - : "https"; - const baseUrl = `${protocol}://${host}:${port}/chat/leave`; +// Function to build leave chat URL +export function leaveChatURLbuildr(userID: string): string { + const env: BackendEnvironment = { + NEXT_PUBLIC_BACKEND_HOST: process.env.NEXT_PUBLIC_BACKEND_HOST || 'localhost', + NEXT_PUBLIC_BACKEND_PORT: process.env.NEXT_PUBLIC_BACKEND_PORT || '1323', + NEXT_PUBLIC_BACKEND_ENVIRONMENT: process.env.NEXT_PUBLIC_BACKEND_ENVIRONMENT as 'development' | 'production', + }; + + const protocol = env.NEXT_PUBLIC_BACKEND_ENVIRONMENT === "development" ? "http" : "https"; + const baseUrl = `${protocol}://${env.NEXT_PUBLIC_BACKEND_HOST}:${env.NEXT_PUBLIC_BACKEND_PORT}/chat/leave`; + const params = new URLSearchParams({ userID: userID, }); @@ -41,13 +57,16 @@ export function leaveChatURLbuildr(userID) { return `${baseUrl}?${params.toString()}`; } -export function subscribeURLbuildr() { - const host = process.env.NEXT_PUBLIC_BACKEND_HOST; - const port = process.env.NEXT_PUBLIC_BACKEND_PORT; - const protocol = - process.env.NEXT_PUBLIC_BACKEND_ENVIRONMENT === "development" - ? "http" - : "https"; - const baseUrl = `${protocol}://${host}:${port}/subscribe`; +// Function to build subscribe URL +export function subscribeURLbuildr(): string { + const env: BackendEnvironment = { + NEXT_PUBLIC_BACKEND_HOST: process.env.NEXT_PUBLIC_BACKEND_HOST || 'localhost', + NEXT_PUBLIC_BACKEND_PORT: process.env.NEXT_PUBLIC_BACKEND_PORT || '1323', + NEXT_PUBLIC_BACKEND_ENVIRONMENT: process.env.NEXT_PUBLIC_BACKEND_ENVIRONMENT as 'development' | 'production', + }; + + const protocol = env.NEXT_PUBLIC_BACKEND_ENVIRONMENT === "development" ? "http" : "https"; + const baseUrl = `${protocol}://${env.NEXT_PUBLIC_BACKEND_HOST}:${env.NEXT_PUBLIC_BACKEND_PORT}/subscribe`; + return baseUrl; -} \ No newline at end of file +} From de01a41e1feb36df47f55e65c55647abec6ae18c Mon Sep 17 00:00:00 2001 From: kitretsu2809 Date: Tue, 24 Sep 2024 19:31:41 +0530 Subject: [PATCH 21/31] Fix:more fixes --- frontend/interface/interface.ts | 19 +++--- frontend/utils/alerts/alertAbnormalClose.ts | 45 +++++++------ frontend/utils/alerts/alertBadRequest.ts | 11 +-- frontend/utils/alerts/alertBannedUser.ts | 6 +- frontend/utils/alerts/alertSameUsername.ts | 11 +-- frontend/utils/alerts/alertServerError.ts | 11 +-- .../utils/websocket/handleWebSocketClose.ts | 67 ++++++++++++------- 7 files changed, 96 insertions(+), 74 deletions(-) diff --git a/frontend/interface/interface.ts b/frontend/interface/interface.ts index 72d06cf..a4c1c19 100644 --- a/frontend/interface/interface.ts +++ b/frontend/interface/interface.ts @@ -204,15 +204,9 @@ export interface WebSocketHandlers { } -export interface AlertSameUserProps { - reason: string; - navigateToLogin: () => void; -} - -export interface AlertServerErrorProps { - reason: string; - navigateToLogin: () => void; -} +export type AlertSameUserProps = (reason: string, navigate: NavigateFunction) => void; +export type AlertBadRequestProps = (reason: string, navigate: NavigateFunction) => void; +export type AlertServerErrorProps = (reason: string, navigate: NavigateFunction) => void; export interface WebSocketURLParams { userId: string; @@ -297,4 +291,9 @@ export interface BackendEnvironment { } // Create a type for the optional topic parameter - \ No newline at end of file + +export type NavigateFunction = (path: string) => void; + +export type AlertBannedUser = (reason: string, navigate: NavigateFunction) => void; + +export type AlertAbnormalCloseProps = (reason: string, navigate: NavigateFunction) => void; diff --git a/frontend/utils/alerts/alertAbnormalClose.ts b/frontend/utils/alerts/alertAbnormalClose.ts index be896f2..b2d37c9 100644 --- a/frontend/utils/alerts/alertAbnormalClose.ts +++ b/frontend/utils/alerts/alertAbnormalClose.ts @@ -1,31 +1,32 @@ "use client"; import Swal from 'sweetalert2'; import { Dispatch, SetStateAction } from 'react'; // Import types for state setters +import { AlertAbnormalCloseProps } from '../../interface/interface'; +import { navigateToLogin } from '../websocket/handleWebSocketClose'; - - -export default async function alertAbnormalClose(reason: string, - navigateToLogin: () => void){ +const alertAbnormalClose: AlertAbnormalCloseProps = async (reason, navigate) => { // Make the function async try { - const result = await Swal.fire({ - title: "Connection lost", - text: `Please try again or with a different username. Reason: ${reason}`, - icon: "warning", - iconColor: "#3670F5", - confirmButtonColor: "#3670F5", - confirmButtonText: "OK", - didOpen: (popup: HTMLElement) => { - popup.style.borderRadius = "1rem"; - }, - }); + const result = await Swal.fire({ // Corrected line + title: "Connection lost", + text: `Please try again or with a different username. Reason: ${reason}`, + icon: "warning", + iconColor: "#3670F5", + confirmButtonColor: "#3670F5", + confirmButtonText: "OK", + didOpen: (popup: HTMLElement) => { + popup.style.borderRadius = "1rem"; + }, + }); - if (result.isConfirmed) { - navigateToLogin(); - } + if (result.isConfirmed) { + navigateToLogin(); + } } catch (error) { - // More specific error handling here, e.g., log the error - console.error("Error in SweetAlert:", error); + // More specific error handling here, e.g., log the error + console.error("Error in SweetAlert:", error); } - return null; // This component doesn't render anything directly, it's just a function -}; \ No newline at end of file + return null; // This component doesn't render anything directly, it's just a function +}; + +export default alertAbnormalClose; diff --git a/frontend/utils/alerts/alertBadRequest.ts b/frontend/utils/alerts/alertBadRequest.ts index 596b470..7923049 100644 --- a/frontend/utils/alerts/alertBadRequest.ts +++ b/frontend/utils/alerts/alertBadRequest.ts @@ -1,9 +1,8 @@ "use client"; import Swal from "sweetalert2"; - - -export default function alertBadRequest(reason: string, - navigateToLogin: () => void) { +import { navigateToLogin } from "../websocket/handleWebSocketClose"; +import { AlertBadRequestProps } from "../../interface/interface"; +const alertBadRequest: AlertBadRequestProps = (reason, navigate) => { try { Swal.fire({ title: "Bad request", @@ -22,4 +21,6 @@ export default function alertBadRequest(reason: string, } catch (error) {} }); } catch (error) {} - } \ No newline at end of file + } + + export default alertBadRequest; \ No newline at end of file diff --git a/frontend/utils/alerts/alertBannedUser.ts b/frontend/utils/alerts/alertBannedUser.ts index 217eb56..9415022 100644 --- a/frontend/utils/alerts/alertBannedUser.ts +++ b/frontend/utils/alerts/alertBannedUser.ts @@ -1,8 +1,8 @@ "use client"; import Swal from "sweetalert2"; - -const alertBannedUser = async (reason: string, - navigateToLogin: () => void)=> { +import {NavigateFunction , AlertBannedUser } from "../../interface/interface"; +import { navigateToLogin } from "../websocket/handleWebSocketClose"; +const alertBannedUser: AlertBannedUser = (reason, navigate) => { try { Swal.fire({ title: "You have been banned", diff --git a/frontend/utils/alerts/alertSameUsername.ts b/frontend/utils/alerts/alertSameUsername.ts index 543fe3d..c244d34 100644 --- a/frontend/utils/alerts/alertSameUsername.ts +++ b/frontend/utils/alerts/alertSameUsername.ts @@ -1,9 +1,8 @@ "use client"; import Swal from "sweetalert2"; - - -export default function alertSameUsername( reason: string, - navigateToLogin: () => void ) { +import { navigateToLogin } from "../websocket/handleWebSocketClose"; +import {AlertSameUserProps } from "../../interface/interface"; +const alertSameUsername: AlertSameUserProps = (reason, navigate) => { try { Swal.fire({ title: "Username already exists", @@ -23,4 +22,6 @@ export default function alertSameUsername( reason: string, } catch (error) {} }); } catch (error) {} - } \ No newline at end of file + } + + export default alertSameUsername; \ No newline at end of file diff --git a/frontend/utils/alerts/alertServerError.ts b/frontend/utils/alerts/alertServerError.ts index 11ec45d..57cfd09 100644 --- a/frontend/utils/alerts/alertServerError.ts +++ b/frontend/utils/alerts/alertServerError.ts @@ -1,9 +1,8 @@ "use client"; import Swal from "sweetalert2"; - - -export default function alertServerError(reason: string, - navigateToLogin: () => void) { +import { AlertServerErrorProps } from "../../interface/interface"; +import { navigateToLogin } from "../websocket/handleWebSocketClose"; +const alertServerError: AlertServerErrorProps = (reason, navigate) => { try { Swal.fire({ title: "Server error", @@ -22,4 +21,6 @@ export default function alertServerError(reason: string, } catch (error) {} }); } catch (error) {} - } \ No newline at end of file + } + + export default alertServerError; \ No newline at end of file diff --git a/frontend/utils/websocket/handleWebSocketClose.ts b/frontend/utils/websocket/handleWebSocketClose.ts index 15cc69c..96f1c3a 100644 --- a/frontend/utils/websocket/handleWebSocketClose.ts +++ b/frontend/utils/websocket/handleWebSocketClose.ts @@ -1,30 +1,49 @@ "use client"; import { - isUserBanned, - isSameUsername, - isBadRequest, - isServerError, - isAbnormalClose, - } from "./websocketHelpers"; + isUserBanned, + isSameUsername, + isBadRequest, + isServerError, + isAbnormalClose, +} from "./websocketHelpers"; import alertBannedUser from "../alerts/alertBannedUser"; -import alertSameUsername from "../alerts/alertSameUsername"; +import alertSameUsername from "../alerts/alertSameUsername"; // Ensure all alert imports are correctly defined import alertBadRequest from "../alerts/alertBadRequest"; import alertServerError from "../alerts/alertServerError"; import alertAbnormalClose from "../alerts/alertAbnormalClose"; -export default function handleWebSocketClose(event, navigateToLogin) { - if (isUserBanned(event.code)) { - alertBannedUser(event.reason, navigateToLogin); - } - if (isSameUsername(event.code)) { - alertSameUsername(event.reason, navigateToLogin); - } - if (isBadRequest(event.code)) { - alertBadRequest(event.reason, navigateToLogin); - } - if (isServerError(event.code)) { - alertServerError(event.reason, navigateToLogin); - } - if (isAbnormalClose(event.code)) { - alertAbnormalClose(event.reason, navigateToLogin); - } - } \ No newline at end of file +import {useNavigate} from "react-dom" +// Define the type for the WebSocket close event +interface WebSocketCloseEvent { + code: number; + reason: string; +} + +const navigate = useNavigate(); + + export const navigateToLogin = () => { + navigate('/login'); // Adjust the path as needed + }; + +// Define the type for the navigate function +type NavigateFunction = (path: string) => void; + +export default function handleWebSocketClose( + event: WebSocketCloseEvent, + navigateToLogin: NavigateFunction +): void { + if (isUserBanned(event.code)) { + alertBannedUser(event.reason, navigateToLogin); + } + if (isSameUsername(event.code)) { + alertSameUsername(event.reason, navigateToLogin); + } + if (isBadRequest(event.code)) { + alertBadRequest(event.reason, navigateToLogin); + } + if (isServerError(event.code)) { + alertServerError(event.reason, navigateToLogin); + } + if (isAbnormalClose(event.code)) { + alertAbnormalClose(event.reason, navigateToLogin); + } +} From 20414f0da8656264a2eccc141d18956dfdab189d Mon Sep 17 00:00:00 2001 From: kitretsu2809 Date: Fri, 27 Sep 2024 17:11:30 +0530 Subject: [PATCH 22/31] Fix:NavigateToLogin Fixed --- backend/route/router.go | 3 +- frontend/components/chat/chatInputBox.tsx | 1 + frontend/components/chat/loginModal.tsx | 1 + frontend/package-lock.json | 42 +++++++++++++++++++ frontend/package.json | 1 + frontend/utils/alerts/alertAbnormalClose.ts | 2 +- frontend/utils/alerts/alertBadRequest.ts | 2 +- frontend/utils/alerts/alertBannedUser.ts | 2 +- frontend/utils/alerts/alertSameUsername.ts | 2 +- frontend/utils/alerts/alertServerError.ts | 2 +- .../utils/websocket/handleWebSocketClose.ts | 10 ++--- 11 files changed, 57 insertions(+), 11 deletions(-) diff --git a/backend/route/router.go b/backend/route/router.go index 1b84af6..727a3f6 100644 --- a/backend/route/router.go +++ b/backend/route/router.go @@ -12,7 +12,8 @@ func Init() { e := echo.New() e.Use(sentryecho.New(sentryecho.Options{})) e.Use(middleware.CORSWithConfig(middleware.CORSConfig{ - AllowOrigins: []string{"http://localhost:3000" , "https://mdgspace.org"}, + AllowOrigins: []string{"http://localhost:3000", "https://mdgspace.org"}, + // AllowOrigins: []string{"*"}, AllowMethods: []string{"GET", "POST"}, AllowHeaders: []string{"Content-Type"}, })) diff --git a/frontend/components/chat/chatInputBox.tsx b/frontend/components/chat/chatInputBox.tsx index bb0c3b6..f681cf6 100644 --- a/frontend/components/chat/chatInputBox.tsx +++ b/frontend/components/chat/chatInputBox.tsx @@ -18,6 +18,7 @@ const ChatInputBox: React.FC = ({ socketRef }) => { const socket = socketRef.current; if (socket && socket.readyState === WebSocket.OPEN) { + console.log(socket); socket.send(newMessage); setNewMessage(""); messageTimesRef.current.push(Date.now()); diff --git a/frontend/components/chat/loginModal.tsx b/frontend/components/chat/loginModal.tsx index e59269b..24b3f1c 100644 --- a/frontend/components/chat/loginModal.tsx +++ b/frontend/components/chat/loginModal.tsx @@ -55,6 +55,7 @@ const LoginModal: React.FC = ({ onClose, redirect }) => { if (currentUser && currentUserId) { if (currentUser === username) { + console.log(queryParams); router.push(`/chat?${queryParams.toString()}`); } else { const hasChanged = await checkAndPromptSessionChange({ diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 19bf341..dd8f4d3 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -15,6 +15,7 @@ "react": "18.2.0", "react-dom": "18.2.0", "react-icons": "^4.12.0", + "react-router-dom": "^6.26.2", "react-switch": "^7.0.0", "react-toastify": "^10.0.5", "sharp": "^0.33.1", @@ -716,6 +717,15 @@ "node": ">= 8" } }, + "node_modules/@remix-run/router": { + "version": "1.19.2", + "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.19.2.tgz", + "integrity": "sha512-baiMx18+IMuD1yyvOGaHM9QrVUPGGG0jC+z+IPHnRJWUAUvaKuWKyE8gjDj2rzv3sz9zOGoRSPgeBVHRhZnBlA==", + "license": "MIT", + "engines": { + "node": ">=14.0.0" + } + }, "node_modules/@socket.io/component-emitter": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-3.1.0.tgz", @@ -2380,6 +2390,38 @@ "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==" }, + "node_modules/react-router": { + "version": "6.26.2", + "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.26.2.tgz", + "integrity": "sha512-tvN1iuT03kHgOFnLPfLJ8V95eijteveqdOSk+srqfePtQvqCExB8eHOYnlilbOcyJyKnYkr1vJvf7YqotAJu1A==", + "license": "MIT", + "dependencies": { + "@remix-run/router": "1.19.2" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "react": ">=16.8" + } + }, + "node_modules/react-router-dom": { + "version": "6.26.2", + "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.26.2.tgz", + "integrity": "sha512-z7YkaEW0Dy35T3/QKPYB1LjMK2R1fxnHO8kWpUMTBdfVzZrWOiY9a7CtN8HqdWtDUWd5FY6Dl8HFsqVwH4uOtQ==", + "license": "MIT", + "dependencies": { + "@remix-run/router": "1.19.2", + "react-router": "6.26.2" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "react": ">=16.8", + "react-dom": ">=16.8" + } + }, "node_modules/react-switch": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/react-switch/-/react-switch-7.0.0.tgz", diff --git a/frontend/package.json b/frontend/package.json index 31c6f9c..a68540c 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -17,6 +17,7 @@ "react": "18.2.0", "react-dom": "18.2.0", "react-icons": "^4.12.0", + "react-router-dom": "^6.26.2", "react-switch": "^7.0.0", "react-toastify": "^10.0.5", "sharp": "^0.33.1", diff --git a/frontend/utils/alerts/alertAbnormalClose.ts b/frontend/utils/alerts/alertAbnormalClose.ts index b2d37c9..48f33eb 100644 --- a/frontend/utils/alerts/alertAbnormalClose.ts +++ b/frontend/utils/alerts/alertAbnormalClose.ts @@ -19,7 +19,7 @@ const alertAbnormalClose: AlertAbnormalCloseProps = async (reason, navigate) => }); if (result.isConfirmed) { - navigateToLogin(); + navigate("/"); } } catch (error) { // More specific error handling here, e.g., log the error diff --git a/frontend/utils/alerts/alertBadRequest.ts b/frontend/utils/alerts/alertBadRequest.ts index 7923049..f003dd5 100644 --- a/frontend/utils/alerts/alertBadRequest.ts +++ b/frontend/utils/alerts/alertBadRequest.ts @@ -17,7 +17,7 @@ const alertBadRequest: AlertBadRequestProps = (reason, navigate) => { }, }).then((result) => { try { - if (result.isConfirmed) navigateToLogin(); + if (result.isConfirmed) navigate("/"); } catch (error) {} }); } catch (error) {} diff --git a/frontend/utils/alerts/alertBannedUser.ts b/frontend/utils/alerts/alertBannedUser.ts index 9415022..27af9a4 100644 --- a/frontend/utils/alerts/alertBannedUser.ts +++ b/frontend/utils/alerts/alertBannedUser.ts @@ -20,7 +20,7 @@ const alertBannedUser: AlertBannedUser = (reason, navigate) => { }, }).then((result) => { try { - if (result.isConfirmed) navigateToLogin(); + if (result.isConfirmed) navigate("/"); } catch (error) {} }); } catch (error) {} diff --git a/frontend/utils/alerts/alertSameUsername.ts b/frontend/utils/alerts/alertSameUsername.ts index c244d34..c2decae 100644 --- a/frontend/utils/alerts/alertSameUsername.ts +++ b/frontend/utils/alerts/alertSameUsername.ts @@ -18,7 +18,7 @@ const alertSameUsername: AlertSameUserProps = (reason, navigate) => { }, }).then((result) => { try { - if (result.isConfirmed) navigateToLogin(); + if (result.isConfirmed) navigate("/"); } catch (error) {} }); } catch (error) {} diff --git a/frontend/utils/alerts/alertServerError.ts b/frontend/utils/alerts/alertServerError.ts index 57cfd09..338b400 100644 --- a/frontend/utils/alerts/alertServerError.ts +++ b/frontend/utils/alerts/alertServerError.ts @@ -17,7 +17,7 @@ const alertServerError: AlertServerErrorProps = (reason, navigate) => { }, }).then((result) => { try { - if (result.isConfirmed) navigateToLogin(); + if (result.isConfirmed) navigate("/"); } catch (error) {} }); } catch (error) {} diff --git a/frontend/utils/websocket/handleWebSocketClose.ts b/frontend/utils/websocket/handleWebSocketClose.ts index 96f1c3a..bd85615 100644 --- a/frontend/utils/websocket/handleWebSocketClose.ts +++ b/frontend/utils/websocket/handleWebSocketClose.ts @@ -11,18 +11,18 @@ import alertSameUsername from "../alerts/alertSameUsername"; // Ensure all alert import alertBadRequest from "../alerts/alertBadRequest"; import alertServerError from "../alerts/alertServerError"; import alertAbnormalClose from "../alerts/alertAbnormalClose"; -import {useNavigate} from "react-dom" +import {useNavigate} from "react-router-dom"; // Define the type for the WebSocket close event interface WebSocketCloseEvent { code: number; reason: string; } -const navigate = useNavigate(); - export const navigateToLogin = () => { - navigate('/login'); // Adjust the path as needed - }; +export function navigateToLogin(): void { + const navigate = useNavigate(); // Import the useNavigate hook from react-router-dom + navigate("/"); // Adjust the path as needed +} // Define the type for the navigate function type NavigateFunction = (path: string) => void; From 9af4f13edcabb2c71b9073646545ce561b89a95e Mon Sep 17 00:00:00 2001 From: kitretsu2809 Date: Sun, 29 Sep 2024 16:30:47 +0530 Subject: [PATCH 23/31] Update comments for clarity and consistency in code --- frontend/components/chat/loginModal.tsx | 2 +- frontend/components/mail.tsx | 2 +- frontend/components/usernameInput.tsx | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/components/chat/loginModal.tsx b/frontend/components/chat/loginModal.tsx index 24b3f1c..c1511d4 100644 --- a/frontend/components/chat/loginModal.tsx +++ b/frontend/components/chat/loginModal.tsx @@ -5,7 +5,7 @@ import getSessionUserId from "../../utils/session/getSessionUserId"; import setSessionUser from "../../utils/session/setSessionUser"; import removeSessionUserId from "../../utils/session/removeSessionUserId"; import checkAndPromptSessionChange from "../../utils/alerts/checkAndPromptSessionChange"; -import { toast } from "react-toastify"; // Assuming you're using react-toastify +import { toast } from "react-toastify"; import {LoginModalProps} from "../../interface/interface" const LoginModal: React.FC = ({ onClose, redirect }) => { const popupRef = useRef(null); diff --git a/frontend/components/mail.tsx b/frontend/components/mail.tsx index 60c6a0c..020138a 100644 --- a/frontend/components/mail.tsx +++ b/frontend/components/mail.tsx @@ -21,7 +21,7 @@ export default function Mail({ let timestamp = Date.now(); e.preventDefault(); try { - await subscribe(email, username, userId, channel, timestamp); + await subscribe({email, username, userId, channel, timestamp}); onClose(); } catch (error) { //todo -> enable sentry logger here diff --git a/frontend/components/usernameInput.tsx b/frontend/components/usernameInput.tsx index 53df40c..18428e5 100644 --- a/frontend/components/usernameInput.tsx +++ b/frontend/components/usernameInput.tsx @@ -9,8 +9,8 @@ const UsernameInput: React.FC = ({ value, onChange }) => { return (
-
{/* Removed p-50 */} -
{/* Added w-full for responsiveness */} +
+
Date: Sun, 29 Sep 2024 16:35:35 +0530 Subject: [PATCH 24/31] useWebSocketForChatBot Errors fixed --- frontend/hooks/useWebSocketForChatBot.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frontend/hooks/useWebSocketForChatBot.tsx b/frontend/hooks/useWebSocketForChatBot.tsx index 4c7144b..957c19e 100644 --- a/frontend/hooks/useWebSocketForChatBot.tsx +++ b/frontend/hooks/useWebSocketForChatBot.tsx @@ -38,10 +38,12 @@ const useWebsocketForChatbot=({socketRef,setMessages,router}:useWebsocketForChat const handleError = handleWebSocketError; const socket = initializeWebSocketConnection( url, + { handleOpen, handleMessage, handleClose, handleError, + } ); socketRef.current = socket; From 3b2b92a4057cb18adabea65e6cfc6d7f0781ec5d Mon Sep 17 00:00:00 2001 From: kitretsu2809 Date: Tue, 1 Oct 2024 02:21:04 +0530 Subject: [PATCH 25/31] Fix:Uncommented useLeavechat --- frontend/pages/chat_bot.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/pages/chat_bot.tsx b/frontend/pages/chat_bot.tsx index f391ee9..0798206 100644 --- a/frontend/pages/chat_bot.tsx +++ b/frontend/pages/chat_bot.tsx @@ -26,7 +26,7 @@ export default function Home() { useSettings({soundEnabled,notificationsEnabled}); useWebsocketForChatbot({socketRef,setMessages,router}); useVisibilityChange({setUnreadCount}); - // useLeaveChat(router); + useLeaveChat(router); useEffect(() => setTopic(router.query.topic as string ?? "Appetizer"), [router.query]); From 0993bc7ba32bcb72e643c0d21923627599fbbf21 Mon Sep 17 00:00:00 2001 From: Aaditya Gupta Date: Fri, 25 Oct 2024 23:55:59 +0530 Subject: [PATCH 26/31] rfac: revert all backend changes --- backend/db/client.go | 58 +++++++++++++++++++++-------------------- backend/route/router.go | 3 +-- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/backend/db/client.go b/backend/db/client.go index bd9c512..37a241d 100644 --- a/backend/db/client.go +++ b/backend/db/client.go @@ -357,23 +357,23 @@ func AddUserInfoToDb(username string, userId string, userAgent string, ip string } func GetUserInfo(userId string) string { - info, _ := redisClient.Get(ctx, fmt.Sprintf("info:%v", userId)).Result() - var _info models.UserInfo - err := json.Unmarshal([]byte(info), &_info) - if err != nil { + info, _ := redisClient.Get(ctx, fmt.Sprintf("info:%v", userId)).Result() + var _info models.UserInfo + err := json.Unmarshal([]byte(info), &_info) + if(err != nil){ logging.LogException(err) panic(err) } formattedInfo := fmt.Sprintf( - "UserID: %s\nName: %s\nIP: %s\nLocation: %s\nOS: %s\nAgent: %s\nChatChannel: %s", - _info.UserID, - _info.Username, - _info.IP, - _info.Location, - _info.OS, - _info.Agent, - _info.Channel, - ) + "UserID: %s\nName: %s\nIP: %s\nLocation: %s\nOS: %s\nAgent: %s\nChatChannel: %s", + _info.UserID, + _info.Username, + _info.IP, + _info.Location, + _info.OS, + _info.Agent, + _info.Channel, + ) return formattedInfo } @@ -423,6 +423,7 @@ func UpsertProject(project models.Project) { "projectAppStoreLink": string(project.AppStoreLink), "projectGithubLink": string(project.GithubLink), "projectPlayStoreLink": string(project.PlayStoreLink), + }).Result() if err != nil { logging.LogException(err) @@ -447,32 +448,32 @@ func UpsertProject(project models.Project) { // return project // } -func GetAllProjects() ([]models.Project, error) { +func GetAllProjects() ([]models.Project , error) { keys, err := redisClient.Keys(redisClient.Context(), "project:*").Result() if err != nil { logging.LogException(err) - return nil, err + return nil , err } var projects []models.Project for _, key := range keys { result, err := redisClient.HGetAll(redisClient.Context(), key).Result() if err != nil { logging.LogException(err) - return nil, err + return nil , err } project := models.Project{ - Name: key[len("project:"):], - Category: models.ProjectCategory(result["projectCategory"]), - ShortDesc: result["projectShortDescription"], - LongDesc: result["projectLongDescription"], - ImageLink: result["projectImageLink"], - AppStoreLink: result["projectAppStoreLink"], - GithubLink: result["projectGithubLink"], + Name: key[len("project:"):], + Category: models.ProjectCategory(result["projectCategory"]), + ShortDesc: result["projectShortDescription"], + LongDesc: result["projectLongDescription"], + ImageLink: result["projectImageLink"], + AppStoreLink: result["projectAppStoreLink"], + GithubLink: result["projectGithubLink"], PlayStoreLink: result["projectPlayStoreLink"], } projects = append(projects, project) } - return projects, nil + return projects , nil } func isValidProjectCategory(category models.ProjectCategory) bool { @@ -485,13 +486,14 @@ func isValidProjectCategory(category models.ProjectCategory) bool { } func DeleteProject(projectName string) string { - + if !projectExists(projectName) { err := fmt.Errorf("project %s does not exist", projectName) logging.LogException(err) return err.Error() } + key := "project:" + projectName _, err := redisClient.Del(redisClient.Context(), key).Result() if err != nil { @@ -499,10 +501,10 @@ func DeleteProject(projectName string) string { return err.Error() } - return fmt.Sprintf("project %v deleted succesfully", projectName) + return fmt.Sprintf("project %v deleted succesfully" , projectName) } -func projectExists(projectName string) bool { +func projectExists( projectName string) bool { key := "project:" + projectName exists, err := redisClient.Exists(redisClient.Context(), key).Result() if err != nil { @@ -510,4 +512,4 @@ func projectExists(projectName string) bool { return false } return exists == 1 -} +} \ No newline at end of file diff --git a/backend/route/router.go b/backend/route/router.go index 727a3f6..1b84af6 100644 --- a/backend/route/router.go +++ b/backend/route/router.go @@ -12,8 +12,7 @@ func Init() { e := echo.New() e.Use(sentryecho.New(sentryecho.Options{})) e.Use(middleware.CORSWithConfig(middleware.CORSConfig{ - AllowOrigins: []string{"http://localhost:3000", "https://mdgspace.org"}, - // AllowOrigins: []string{"*"}, + AllowOrigins: []string{"http://localhost:3000" , "https://mdgspace.org"}, AllowMethods: []string{"GET", "POST"}, AllowHeaders: []string{"Content-Type"}, })) From 09a1d533f6fb349a0616555ddae5b50bfe89896c Mon Sep 17 00:00:00 2001 From: kitretsu2809 Date: Sun, 27 Oct 2024 01:24:49 +0530 Subject: [PATCH 27/31] Fix:topicDorpdown and channelswitching --- .../components/chatbot/chatbotContainer.jsx | 119 ------------------ .../components/chatbot/chatbotLoginModal.tsx | 38 +++--- .../alerts/checkAndPromptSessionChange.ts | 22 ++-- 3 files changed, 32 insertions(+), 147 deletions(-) delete mode 100644 frontend/components/chatbot/chatbotContainer.jsx diff --git a/frontend/components/chatbot/chatbotContainer.jsx b/frontend/components/chatbot/chatbotContainer.jsx deleted file mode 100644 index 2e14daf..0000000 --- a/frontend/components/chatbot/chatbotContainer.jsx +++ /dev/null @@ -1,119 +0,0 @@ -import React, { useState, useEffect } from "react"; -import Echofy from "../../assets/logo.svg"; -import Image from "next/image"; -import Avatar1 from "../../assets/avatars/avatar_1.svg"; -import Avatar2 from "../../assets/avatars/avatar_2.svg"; -import Avatar3 from "../../assets/avatars/avatar_3.svg"; -import Avatar4 from "../../assets/avatars/avatar_4.svg"; -import Avatar5 from "../../assets/avatars/avatar_5.svg"; -import Avatar6 from "../../assets/avatars/avatar_6.svg"; -import Avatar7 from "../../assets/avatars/avatar_7.svg"; -import Avatar8 from "../../assets/avatars/avatar_8.svg"; -import Avatar9 from "../../assets/avatars/avatar_9.svg"; -import Avatar10 from "../../assets/avatars/avatar_10.svg"; -import Avatar11 from "../../assets/avatars/avatar_11.svg"; -import Avatar12 from "../../assets/avatars/avatar_12.svg"; -import Avatar13 from "../../assets/avatars/avatar_13.svg"; -import Avatar14 from "../../assets/avatars/avatar_14.svg"; -import Avatar15 from "../../assets/avatars/avatar_15.svg"; -import parseMessageText from "../../utils/chatbot_formatting/parseMessageText"; -import getAvatar from "../../utils/session/getAvatar"; -import { ChatContainerProps, Message } from "../../interface/interface"; - -export default function ChatContainer({ messages, messagesEndRef }: ChatContainerProps): React.JSX.Element { - const [filteredMessage, setFilteredMessage] = useState([]); - - const AvatarList = [ - Avatar1, - Avatar2, - Avatar3, - Avatar4, - Avatar5, - Avatar6, - Avatar7, - Avatar8, - Avatar9, - Avatar10, - Avatar11, - Avatar12, - Avatar13, - Avatar14, - Avatar15, - ]; - const [Avatar, setAvatar] = useState(Avatar1.src); - - useEffect(() => { - if (messagesEndRef.current) { - messagesEndRef.current.scrollIntoView({ behavior: "smooth" }); - } - - async function loadAvatar() { - const AvatarId = await getAvatar(); - const Avatar = AvatarList[AvatarId]; - setAvatar(Avatar.src); - } - loadAvatar(); - }, [messages]); - - useEffect(() => { - const filterMessages = () => { - const newMessages = messages.filter((message) => { - try { - const messageData = JSON.parse(message); - return !(messageData.userID && messageData.userID.startsWith("chatbot")); - } catch (error) { - return true; - } - }); - return newMessages; - }; - const newFilteredMessages = filterMessages() as Message[]; - setFilteredMessage(newFilteredMessages); - }, [messages]); - - return ( -
-
    - {filteredMessage?.map((message, index) => { - const parsedMessage = JSON.parse(message) as Message; - return ( -
  • -
    -
    -
    -
    - -
    -
    {parsedMessage.username}
    -
    -
    -
    -
    - {parsedMessage.isSent ? parsedMessage.text : parseMessageText(parsedMessage.text)} -
    -
    -
    -
    -
    -
  • - ); - })} -
-
-
- ); -} diff --git a/frontend/components/chatbot/chatbotLoginModal.tsx b/frontend/components/chatbot/chatbotLoginModal.tsx index e9d7d61..ec91b54 100644 --- a/frontend/components/chatbot/chatbotLoginModal.tsx +++ b/frontend/components/chatbot/chatbotLoginModal.tsx @@ -5,15 +5,22 @@ import getSessionUserId from "../../utils/session/getSessionUserId"; import setSessionUser from "../../utils/session/setSessionUser"; import removeSessionUserId from "../../utils/session/removeSessionUserId"; import checkAndPromptSessionChange from "../../utils/alerts/checkAndPromptSessionChange"; +import { TopicDropdown } from "../topicDropdown"; -interface LoginModalProps { +interface ChatBotLoginModalProps { onClose: () => void; - redirect: string; } -const LoginModal: React.FC = ({ onClose, redirect }) => { +interface DropdownProps { + topic: string; + setTopic: React.Dispatch>; + login?: boolean; +} + +const ChatBotLoginModal: React.FC = ({ onClose }) => { const popupRef = useRef(null); const [username, setUsername] = useState(""); + const [topic, setTopic] = useState("SELECT A TOPIC"); const router = useRouter(); const handleUsernameChange = (event: React.ChangeEvent) => { @@ -32,40 +39,35 @@ const LoginModal: React.FC = ({ onClose, redirect }) => { onClose(); } }; - document.addEventListener("mousedown", handleClickOutside); return () => document.removeEventListener("mousedown", handleClickOutside); }, [onClose]); const handleChatWithUsClick = async () => { - const chatType = redirect; const currentUser = getSessionUser(); const currentUserId = getSessionUserId(); - const query = { channel: chatType }; - + if (currentUser && currentUserId) { if (currentUser === username) { - router.push(`/chat?${new URLSearchParams(query).toString()}`); + router.push(`/chat_bot?topic=${encodeURIComponent(topic)}`); } else { const hasChanged = await checkAndPromptSessionChange({ - currentUsername: currentUser, - inputUsername: username, - onConfirm: () => { + currentUser, + username, + onSessionChange: () => { removeSessionUserId(); setSessionUser(username); }, }); - if (hasChanged) { - router.push(`/chat?${new URLSearchParams(query).toString()}`); + router.push(`/chat_bot?topic=${encodeURIComponent(topic)}`); } } } else { setSessionUser(username); - router.push(`/chat?${new URLSearchParams(query).toString()}`); + router.push(`/chat_bot?topic=${encodeURIComponent(topic)}`); } }; - return (
@@ -77,6 +79,7 @@ const LoginModal: React.FC = ({ onClose, redirect }) => {
Pick your username and login
+
= ({ onClose, redirect }) => { onKeyDown={handleEnterClick} />
+
- CHAT WITH US + START ASKING
@@ -99,4 +103,4 @@ const LoginModal: React.FC = ({ onClose, redirect }) => { ); }; -export default LoginModal; +export default ChatBotLoginModal; diff --git a/frontend/utils/alerts/checkAndPromptSessionChange.ts b/frontend/utils/alerts/checkAndPromptSessionChange.ts index 04a757c..6caa334 100644 --- a/frontend/utils/alerts/checkAndPromptSessionChange.ts +++ b/frontend/utils/alerts/checkAndPromptSessionChange.ts @@ -3,23 +3,23 @@ import Swal, { SweetAlertResult } from "sweetalert2"; // Interface for the function parameters interface CheckAndPromptSessionChangeProps { - currentUsername: string | null; - inputUsername: string; - onConfirm: () => void; + currentUser: string | null; + username: string | null; + onSessionChange: () => void; } // Function to check and prompt session change using SweetAlert2 export default async function checkAndPromptSessionChange({ - currentUsername, - inputUsername, - onConfirm, + currentUser, + username, + onSessionChange, }: CheckAndPromptSessionChangeProps): Promise { // Check if the current username exists and differs from the input username - if (currentUsername && currentUsername !== inputUsername) { + if (currentUser && currentUser !== username) { try { const result: SweetAlertResult = await Swal.fire({ title: "Change Username?", - text: `You already have a running session with the username "${currentUsername}". Do you want to change your username?`, + text: `You already have a running session with the username "${currentUser}". Do you want to change your username?`, icon: "question", iconColor: "#3670F5", showCancelButton: true, @@ -29,12 +29,12 @@ export default async function checkAndPromptSessionChange({ }); // If the user confirms and the new username is less than 20 characters - if (result.isConfirmed && inputUsername.length < 20) { - onConfirm(); + if (result.isConfirmed && username.length < 20) { + onSessionChange(); return true; } else { // If the input username exceeds the length limit, display a warning - if (inputUsername.length > 20) { + if (username.length > 20) { Swal.fire({ title: "Username too long", text: `Please choose a username with less than 20 characters`, From 19766387f93729369b432d59db5feaf88b12687d Mon Sep 17 00:00:00 2001 From: kitretsu2809 Date: Sun, 27 Oct 2024 01:43:52 +0530 Subject: [PATCH 28/31] Fix:index.tsx redirect props --- .gitignore | 2 +- frontend/components/chatbot/chatbotLoginModal.tsx | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index fc9158a..b42db5f 100644 --- a/.gitignore +++ b/.gitignore @@ -29,7 +29,7 @@ frontend/node_modules/ # testing /coverage - +/backend/db/client.go # next.js frontend/.next/ /out/ diff --git a/frontend/components/chatbot/chatbotLoginModal.tsx b/frontend/components/chatbot/chatbotLoginModal.tsx index ec91b54..adaa47b 100644 --- a/frontend/components/chatbot/chatbotLoginModal.tsx +++ b/frontend/components/chatbot/chatbotLoginModal.tsx @@ -9,6 +9,7 @@ import { TopicDropdown } from "../topicDropdown"; interface ChatBotLoginModalProps { onClose: () => void; + redirect; } interface DropdownProps { @@ -17,7 +18,7 @@ interface DropdownProps { login?: boolean; } -const ChatBotLoginModal: React.FC = ({ onClose }) => { +const ChatBotLoginModal: React.FC = ({ onClose , redirect}) => { const popupRef = useRef(null); const [username, setUsername] = useState(""); const [topic, setTopic] = useState("SELECT A TOPIC"); From b3a29bd0fc95b09bd83991ea738d3cb521b4368f Mon Sep 17 00:00:00 2001 From: kitretsu2809 Date: Sun, 27 Oct 2024 23:11:05 +0530 Subject: [PATCH 29/31] chore: remove debug console logs --- .gitignore | 1 - frontend/components/chat/chatInputBox.tsx | 1 - frontend/components/chat/loginModal.tsx | 5 ++--- frontend/components/chatbot/chatbotLoginModal.tsx | 2 +- frontend/services/api/api.ts | 1 - frontend/utils/alerts/checkAndPromptSessionChange.ts | 6 +++--- 6 files changed, 6 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index b42db5f..34a7f16 100644 --- a/.gitignore +++ b/.gitignore @@ -29,7 +29,6 @@ frontend/node_modules/ # testing /coverage -/backend/db/client.go # next.js frontend/.next/ /out/ diff --git a/frontend/components/chat/chatInputBox.tsx b/frontend/components/chat/chatInputBox.tsx index f681cf6..bb0c3b6 100644 --- a/frontend/components/chat/chatInputBox.tsx +++ b/frontend/components/chat/chatInputBox.tsx @@ -18,7 +18,6 @@ const ChatInputBox: React.FC = ({ socketRef }) => { const socket = socketRef.current; if (socket && socket.readyState === WebSocket.OPEN) { - console.log(socket); socket.send(newMessage); setNewMessage(""); messageTimesRef.current.push(Date.now()); diff --git a/frontend/components/chat/loginModal.tsx b/frontend/components/chat/loginModal.tsx index c1511d4..283faae 100644 --- a/frontend/components/chat/loginModal.tsx +++ b/frontend/components/chat/loginModal.tsx @@ -55,12 +55,11 @@ const LoginModal: React.FC = ({ onClose, redirect }) => { if (currentUser && currentUserId) { if (currentUser === username) { - console.log(queryParams); router.push(`/chat?${queryParams.toString()}`); } else { const hasChanged = await checkAndPromptSessionChange({ - currentUsername: currentUser, - inputUsername: username, + currentUser: currentUser, + username: username, onConfirm: () => { removeSessionUserId(); setSessionUser(username); diff --git a/frontend/components/chatbot/chatbotLoginModal.tsx b/frontend/components/chatbot/chatbotLoginModal.tsx index adaa47b..d4cac22 100644 --- a/frontend/components/chatbot/chatbotLoginModal.tsx +++ b/frontend/components/chatbot/chatbotLoginModal.tsx @@ -55,7 +55,7 @@ const ChatBotLoginModal: React.FC = ({ onClose , redirec const hasChanged = await checkAndPromptSessionChange({ currentUser, username, - onSessionChange: () => { + onConfirm: () => { removeSessionUserId(); setSessionUser(username); }, diff --git a/frontend/services/api/api.ts b/frontend/services/api/api.ts index 6d41fa2..516175c 100644 --- a/frontend/services/api/api.ts +++ b/frontend/services/api/api.ts @@ -9,7 +9,6 @@ export function initializeWebSocketConnection( url: string, handlers: WebSocketHandlers ): WebSocket { - console.log("WebSocket URL:", url); const socket = new WebSocket(url); socket.onopen = handlers.handleOpen; diff --git a/frontend/utils/alerts/checkAndPromptSessionChange.ts b/frontend/utils/alerts/checkAndPromptSessionChange.ts index 6caa334..05a8a7b 100644 --- a/frontend/utils/alerts/checkAndPromptSessionChange.ts +++ b/frontend/utils/alerts/checkAndPromptSessionChange.ts @@ -5,14 +5,14 @@ import Swal, { SweetAlertResult } from "sweetalert2"; interface CheckAndPromptSessionChangeProps { currentUser: string | null; username: string | null; - onSessionChange: () => void; + onConfirm: () => void; } // Function to check and prompt session change using SweetAlert2 export default async function checkAndPromptSessionChange({ currentUser, username, - onSessionChange, + onConfirm, }: CheckAndPromptSessionChangeProps): Promise { // Check if the current username exists and differs from the input username if (currentUser && currentUser !== username) { @@ -30,7 +30,7 @@ export default async function checkAndPromptSessionChange({ // If the user confirms and the new username is less than 20 characters if (result.isConfirmed && username.length < 20) { - onSessionChange(); + onConfirm(); return true; } else { // If the input username exceeds the length limit, display a warning From 9e830f3cb418a42b93d7a93d5ef778cb4591a652 Mon Sep 17 00:00:00 2001 From: kitretsu2809 Date: Wed, 30 Oct 2024 03:21:14 +0530 Subject: [PATCH 30/31] chore:ChatBotButton Disabled --- frontend/next-env.d.ts | 2 +- frontend/package-lock.json | 404 +++++++++++++++++-------------------- frontend/package.json | 2 +- frontend/pages/index.tsx | 14 +- 4 files changed, 200 insertions(+), 222 deletions(-) diff --git a/frontend/next-env.d.ts b/frontend/next-env.d.ts index 4f11a03..a4a7b3f 100644 --- a/frontend/next-env.d.ts +++ b/frontend/next-env.d.ts @@ -2,4 +2,4 @@ /// // NOTE: This file should not be edited -// see https://nextjs.org/docs/basic-features/typescript for more information. +// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information. diff --git a/frontend/package-lock.json b/frontend/package-lock.json index dd8f4d3..90a99dd 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -4,6 +4,7 @@ "requires": true, "packages": { "": { + "name": "frontend", "dependencies": { "autoprefixer": "^10.4.16", "axios": "^1.6.8", @@ -22,7 +23,7 @@ "socket.io": "^4.7.2", "socket.io-client": "^4.7.2", "start": "^5.1.0", - "sweetalert2": "^11.10.1", + "sweetalert2": "^11.6.13", "tailwindcss": "^3.3.3" }, "devDependencies": { @@ -483,13 +484,13 @@ } }, "node_modules/@jridgewell/gen-mapping": { - "version": "0.3.3", - "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.3.tgz", - "integrity": "sha512-HLhSWOLRi875zjjMG/r+Nv0oCW8umGb0BgEhyX3dDX3egwZtB8PqLnjz3yedt8R5StBrzcg4aBpnh8UA9D1BoQ==", + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.5.tgz", + "integrity": "sha512-IzL8ZoEDIBRWEzlCcRhOaCupYyN5gdIK+Q6fbFdPDg6HqX6jpkItn7DFIpW9LQzXG6Df9sA7+OKnq0qlz/GaQg==", "dependencies": { - "@jridgewell/set-array": "^1.0.1", + "@jridgewell/set-array": "^1.2.1", "@jridgewell/sourcemap-codec": "^1.4.10", - "@jridgewell/trace-mapping": "^0.3.9" + "@jridgewell/trace-mapping": "^0.3.24" }, "engines": { "node": ">=6.0.0" @@ -504,21 +505,21 @@ } }, "node_modules/@jridgewell/set-array": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.1.2.tgz", - "integrity": "sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.2.1.tgz", + "integrity": "sha512-R8gLRTZeyp03ymzP/6Lil/28tGeGEzhx1q2k703KGWRAI1VdvPIXdG70VJc2pAMw3NA6JKL5hhFu1sJX0Mnn/A==", "engines": { "node": ">=6.0.0" } }, "node_modules/@jridgewell/source-map": { - "version": "0.3.5", - "resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.5.tgz", - "integrity": "sha512-UTYAUj/wviwdsMfzoSJspJxbkH5o1snzwX0//0ENX1u/55kkZZkcTZP6u9bwKGkv+dkk9at4m1Cpt0uY80kcpQ==", + "version": "0.3.6", + "resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.6.tgz", + "integrity": "sha512-1ZJTZebgqllO79ue2bm3rIGud/bOe0pP5BjSRCRxxYkEZS8STV7zN84UBbiYu7jy+eCKSnVIUgoWWE/tt+shMQ==", "peer": true, "dependencies": { - "@jridgewell/gen-mapping": "^0.3.0", - "@jridgewell/trace-mapping": "^0.3.9" + "@jridgewell/gen-mapping": "^0.3.5", + "@jridgewell/trace-mapping": "^0.3.25" } }, "node_modules/@jridgewell/sourcemap-codec": { @@ -527,28 +528,26 @@ "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==" }, "node_modules/@jridgewell/trace-mapping": { - "version": "0.3.19", - "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.19.tgz", - "integrity": "sha512-kf37QtfW+Hwx/buWGMPcR60iF9ziHa6r/CZJIHbmcm4+0qrXiVdxegAH0F6yddEVQ7zdkjcGCgCzUu+BcbhQxw==", + "version": "0.3.25", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.25.tgz", + "integrity": "sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==", "dependencies": { "@jridgewell/resolve-uri": "^3.1.0", "@jridgewell/sourcemap-codec": "^1.4.14" } }, "node_modules/@next/env": { - "version": "14.2.5", - "resolved": "https://registry.npmjs.org/@next/env/-/env-14.2.5.tgz", - "integrity": "sha512-/zZGkrTOsraVfYjGP8uM0p6r0BDT6xWpkjdVbcz66PJVSpwXX3yNiRycxAuDfBKGWBrZBXRuK/YVlkNgxHGwmA==", - "license": "MIT" + "version": "14.2.15", + "resolved": "https://registry.npmjs.org/@next/env/-/env-14.2.15.tgz", + "integrity": "sha512-S1qaj25Wru2dUpcIZMjxeMVSwkt8BK4dmWHHiBuRstcIyOsMapqT4A4jSB6onvqeygkSSmOkyny9VVx8JIGamQ==" }, "node_modules/@next/swc-darwin-arm64": { - "version": "14.2.5", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.5.tgz", - "integrity": "sha512-/9zVxJ+K9lrzSGli1///ujyRfon/ZneeZ+v4ptpiPoOU+GKZnm8Wj8ELWU1Pm7GHltYRBklmXMTUqM/DqQ99FQ==", + "version": "14.2.15", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.15.tgz", + "integrity": "sha512-Rvh7KU9hOUBnZ9TJ28n2Oa7dD9cvDBKua9IKx7cfQQ0GoYUwg9ig31O2oMwH3wm+pE3IkAQ67ZobPfEgurPZIA==", "cpu": [ "arm64" ], - "license": "MIT", "optional": true, "os": [ "darwin" @@ -558,13 +557,12 @@ } }, "node_modules/@next/swc-darwin-x64": { - "version": "14.2.5", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.5.tgz", - "integrity": "sha512-vXHOPCwfDe9qLDuq7U1OYM2wUY+KQ4Ex6ozwsKxp26BlJ6XXbHleOUldenM67JRyBfVjv371oneEvYd3H2gNSA==", + "version": "14.2.15", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.15.tgz", + "integrity": "sha512-5TGyjFcf8ampZP3e+FyCax5zFVHi+Oe7sZyaKOngsqyaNEpOgkKB3sqmymkZfowy3ufGA/tUgDPPxpQx931lHg==", "cpu": [ "x64" ], - "license": "MIT", "optional": true, "os": [ "darwin" @@ -574,13 +572,12 @@ } }, "node_modules/@next/swc-linux-arm64-gnu": { - "version": "14.2.5", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.5.tgz", - "integrity": "sha512-vlhB8wI+lj8q1ExFW8lbWutA4M2ZazQNvMWuEDqZcuJJc78iUnLdPPunBPX8rC4IgT6lIx/adB+Cwrl99MzNaA==", + "version": "14.2.15", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.15.tgz", + "integrity": "sha512-3Bwv4oc08ONiQ3FiOLKT72Q+ndEMyLNsc/D3qnLMbtUYTQAmkx9E/JRu0DBpHxNddBmNT5hxz1mYBphJ3mfrrw==", "cpu": [ "arm64" ], - "license": "MIT", "optional": true, "os": [ "linux" @@ -590,13 +587,12 @@ } }, "node_modules/@next/swc-linux-arm64-musl": { - "version": "14.2.5", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.5.tgz", - "integrity": "sha512-NpDB9NUR2t0hXzJJwQSGu1IAOYybsfeB+LxpGsXrRIb7QOrYmidJz3shzY8cM6+rO4Aojuef0N/PEaX18pi9OA==", + "version": "14.2.15", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.15.tgz", + "integrity": "sha512-k5xf/tg1FBv/M4CMd8S+JL3uV9BnnRmoe7F+GWC3DxkTCD9aewFRH1s5rJ1zkzDa+Do4zyN8qD0N8c84Hu96FQ==", "cpu": [ "arm64" ], - "license": "MIT", "optional": true, "os": [ "linux" @@ -606,13 +602,12 @@ } }, "node_modules/@next/swc-linux-x64-gnu": { - "version": "14.2.5", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.5.tgz", - "integrity": "sha512-8XFikMSxWleYNryWIjiCX+gU201YS+erTUidKdyOVYi5qUQo/gRxv/3N1oZFCgqpesN6FPeqGM72Zve+nReVXQ==", + "version": "14.2.15", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.15.tgz", + "integrity": "sha512-kE6q38hbrRbKEkkVn62reLXhThLRh6/TvgSP56GkFNhU22TbIrQDEMrO7j0IcQHcew2wfykq8lZyHFabz0oBrA==", "cpu": [ "x64" ], - "license": "MIT", "optional": true, "os": [ "linux" @@ -622,13 +617,12 @@ } }, "node_modules/@next/swc-linux-x64-musl": { - "version": "14.2.5", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.5.tgz", - "integrity": "sha512-6QLwi7RaYiQDcRDSU/os40r5o06b5ue7Jsk5JgdRBGGp8l37RZEh9JsLSM8QF0YDsgcosSeHjglgqi25+m04IQ==", + "version": "14.2.15", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.15.tgz", + "integrity": "sha512-PZ5YE9ouy/IdO7QVJeIcyLn/Rc4ml9M2G4y3kCM9MNf1YKvFY4heg3pVa/jQbMro+tP6yc4G2o9LjAz1zxD7tQ==", "cpu": [ "x64" ], - "license": "MIT", "optional": true, "os": [ "linux" @@ -638,13 +632,12 @@ } }, "node_modules/@next/swc-win32-arm64-msvc": { - "version": "14.2.5", - "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.5.tgz", - "integrity": "sha512-1GpG2VhbspO+aYoMOQPQiqc/tG3LzmsdBH0LhnDS3JrtDx2QmzXe0B6mSZZiN3Bq7IOMXxv1nlsjzoS1+9mzZw==", + "version": "14.2.15", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.15.tgz", + "integrity": "sha512-2raR16703kBvYEQD9HNLyb0/394yfqzmIeyp2nDzcPV4yPjqNUG3ohX6jX00WryXz6s1FXpVhsCo3i+g4RUX+g==", "cpu": [ "arm64" ], - "license": "MIT", "optional": true, "os": [ "win32" @@ -654,13 +647,12 @@ } }, "node_modules/@next/swc-win32-ia32-msvc": { - "version": "14.2.5", - "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.5.tgz", - "integrity": "sha512-Igh9ZlxwvCDsu6438FXlQTHlRno4gFpJzqPjSIBZooD22tKeI4fE/YMRoHVJHmrQ2P5YL1DoZ0qaOKkbeFWeMg==", + "version": "14.2.15", + "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.15.tgz", + "integrity": "sha512-fyTE8cklgkyR1p03kJa5zXEaZ9El+kDNM5A+66+8evQS5e/6v0Gk28LqA0Jet8gKSOyP+OTm/tJHzMlGdQerdQ==", "cpu": [ "ia32" ], - "license": "MIT", "optional": true, "os": [ "win32" @@ -670,13 +662,12 @@ } }, "node_modules/@next/swc-win32-x64-msvc": { - "version": "14.2.5", - "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.5.tgz", - "integrity": "sha512-tEQ7oinq1/CjSG9uSTerca3v4AZ+dFa+4Yu6ihaG8Ud8ddqLQgFGcnwYls13H5X5CPDPZJdYxyeMui6muOLd4g==", + "version": "14.2.15", + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.15.tgz", + "integrity": "sha512-SzqGbsLsP9OwKNUG9nekShTwhj6JSB9ZLMWQ8g1gG6hdE5gQLncbnbymrwy2yVmH9nikSLYRYxYMFu78Ggp7/g==", "cpu": [ "x64" ], - "license": "MIT", "optional": true, "os": [ "win32" @@ -753,37 +744,17 @@ "integrity": "sha512-XW/Aa8APYr6jSVVA1y/DEIZX0/GMKLEVekNG727R8cs56ahETkRAy/3DR7+fJyh7oUgGwNQaRfXCun0+KbWY7Q==" }, "node_modules/@types/cors": { - "version": "2.8.15", - "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.15.tgz", - "integrity": "sha512-n91JxbNLD8eQIuXDIChAN1tCKNWCEgpceU9b7ZMbFA+P+Q4yIeh80jizFLEvolRPc1ES0VdwFlGv+kJTSirogw==", + "version": "2.8.17", + "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.17.tgz", + "integrity": "sha512-8CGDvrBj1zgo2qE+oS3pOCyYNqCPryMWY2bGfwA0dcfopWGgxs+78df0Rs3rc9THP4JkOhLsAa+15VdpAqkcUA==", "dependencies": { "@types/node": "*" } }, - "node_modules/@types/eslint": { - "version": "8.56.0", - "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.56.0.tgz", - "integrity": "sha512-FlsN0p4FhuYRjIxpbdXovvHQhtlG05O1GG/RNWvdAxTboR438IOTwmrY/vLA+Xfgg06BTkP045M3vpFwTMv1dg==", - "peer": true, - "dependencies": { - "@types/estree": "*", - "@types/json-schema": "*" - } - }, - "node_modules/@types/eslint-scope": { - "version": "3.7.7", - "resolved": "https://registry.npmjs.org/@types/eslint-scope/-/eslint-scope-3.7.7.tgz", - "integrity": "sha512-MzMFlSLBqNF2gcHWO0G1vP/YQyfvrxZ0bF+u7mzUdZ1/xK4A4sru+nraZz5i3iEIk1l1uyicaDVTB4QbbEkAYg==", - "peer": true, - "dependencies": { - "@types/eslint": "*", - "@types/estree": "*" - } - }, "node_modules/@types/estree": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", - "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.6.tgz", + "integrity": "sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw==", "peer": true }, "node_modules/@types/json-schema": { @@ -819,9 +790,9 @@ } }, "node_modules/@webassemblyjs/ast": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.6.tgz", - "integrity": "sha512-IN1xI7PwOvLPgjcf180gC1bqn3q/QaOCwYUahIOhbYUu8KA/3tw2RT/T0Gidi1l7Hhj5D/INhJxiICObqpMu4Q==", + "version": "1.12.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.12.1.tgz", + "integrity": "sha512-EKfMUOPRRUTy5UII4qJDGPpqfwjOmZ5jeGFwid9mnoqIFK+e0vqoi1qH56JpmZSzEL53jKnNzScdmftJyG5xWg==", "peer": true, "dependencies": { "@webassemblyjs/helper-numbers": "1.11.6", @@ -841,9 +812,9 @@ "peer": true }, "node_modules/@webassemblyjs/helper-buffer": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-buffer/-/helper-buffer-1.11.6.tgz", - "integrity": "sha512-z3nFzdcp1mb8nEOFFk8DrYLpHvhKC3grJD2ardfKOzmbmJvEf/tPIqCY+sNcwZIY8ZD7IkB2l7/pqhUhqm7hLA==", + "version": "1.12.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-buffer/-/helper-buffer-1.12.1.tgz", + "integrity": "sha512-nzJwQw99DNDKr9BVCOZcLuJJUlqkJh+kVzVl6Fmq/tI5ZtEyWT1KZMyOXltXLZJmDtvLCDgwsyrkohEtopTXCw==", "peer": true }, "node_modules/@webassemblyjs/helper-numbers": { @@ -864,15 +835,15 @@ "peer": true }, "node_modules/@webassemblyjs/helper-wasm-section": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.11.6.tgz", - "integrity": "sha512-LPpZbSOwTpEC2cgn4hTydySy1Ke+XEu+ETXuoyvuyezHO3Kjdu90KK95Sh9xTbmjrCsUwvWwCOQQNta37VrS9g==", + "version": "1.12.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.12.1.tgz", + "integrity": "sha512-Jif4vfB6FJlUlSbgEMHUyk1j234GTNG9dBJ4XJdOySoj518Xj0oGsNi59cUQF4RRMS9ouBUxDDdyBVfPTypa5g==", "peer": true, "dependencies": { - "@webassemblyjs/ast": "1.11.6", - "@webassemblyjs/helper-buffer": "1.11.6", + "@webassemblyjs/ast": "1.12.1", + "@webassemblyjs/helper-buffer": "1.12.1", "@webassemblyjs/helper-wasm-bytecode": "1.11.6", - "@webassemblyjs/wasm-gen": "1.11.6" + "@webassemblyjs/wasm-gen": "1.12.1" } }, "node_modules/@webassemblyjs/ieee754": { @@ -900,28 +871,28 @@ "peer": true }, "node_modules/@webassemblyjs/wasm-edit": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-edit/-/wasm-edit-1.11.6.tgz", - "integrity": "sha512-Ybn2I6fnfIGuCR+Faaz7YcvtBKxvoLV3Lebn1tM4o/IAJzmi9AWYIPWpyBfU8cC+JxAO57bk4+zdsTjJR+VTOw==", + "version": "1.12.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-edit/-/wasm-edit-1.12.1.tgz", + "integrity": "sha512-1DuwbVvADvS5mGnXbE+c9NfA8QRcZ6iKquqjjmR10k6o+zzsRVesil54DKexiowcFCPdr/Q0qaMgB01+SQ1u6g==", "peer": true, "dependencies": { - "@webassemblyjs/ast": "1.11.6", - "@webassemblyjs/helper-buffer": "1.11.6", + "@webassemblyjs/ast": "1.12.1", + "@webassemblyjs/helper-buffer": "1.12.1", "@webassemblyjs/helper-wasm-bytecode": "1.11.6", - "@webassemblyjs/helper-wasm-section": "1.11.6", - "@webassemblyjs/wasm-gen": "1.11.6", - "@webassemblyjs/wasm-opt": "1.11.6", - "@webassemblyjs/wasm-parser": "1.11.6", - "@webassemblyjs/wast-printer": "1.11.6" + "@webassemblyjs/helper-wasm-section": "1.12.1", + "@webassemblyjs/wasm-gen": "1.12.1", + "@webassemblyjs/wasm-opt": "1.12.1", + "@webassemblyjs/wasm-parser": "1.12.1", + "@webassemblyjs/wast-printer": "1.12.1" } }, "node_modules/@webassemblyjs/wasm-gen": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-gen/-/wasm-gen-1.11.6.tgz", - "integrity": "sha512-3XOqkZP/y6B4F0PBAXvI1/bky7GryoogUtfwExeP/v7Nzwo1QLcq5oQmpKlftZLbT+ERUOAZVQjuNVak6UXjPA==", + "version": "1.12.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-gen/-/wasm-gen-1.12.1.tgz", + "integrity": "sha512-TDq4Ojh9fcohAw6OIMXqiIcTq5KUXTGRkVxbSo1hQnSy6lAM5GSdfwWeSxpAo0YzgsgF182E/U0mDNhuA0tW7w==", "peer": true, "dependencies": { - "@webassemblyjs/ast": "1.11.6", + "@webassemblyjs/ast": "1.12.1", "@webassemblyjs/helper-wasm-bytecode": "1.11.6", "@webassemblyjs/ieee754": "1.11.6", "@webassemblyjs/leb128": "1.11.6", @@ -929,24 +900,24 @@ } }, "node_modules/@webassemblyjs/wasm-opt": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-opt/-/wasm-opt-1.11.6.tgz", - "integrity": "sha512-cOrKuLRE7PCe6AsOVl7WasYf3wbSo4CeOk6PkrjS7g57MFfVUF9u6ysQBBODX0LdgSvQqRiGz3CXvIDKcPNy4g==", + "version": "1.12.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-opt/-/wasm-opt-1.12.1.tgz", + "integrity": "sha512-Jg99j/2gG2iaz3hijw857AVYekZe2SAskcqlWIZXjji5WStnOpVoat3gQfT/Q5tb2djnCjBtMocY/Su1GfxPBg==", "peer": true, "dependencies": { - "@webassemblyjs/ast": "1.11.6", - "@webassemblyjs/helper-buffer": "1.11.6", - "@webassemblyjs/wasm-gen": "1.11.6", - "@webassemblyjs/wasm-parser": "1.11.6" + "@webassemblyjs/ast": "1.12.1", + "@webassemblyjs/helper-buffer": "1.12.1", + "@webassemblyjs/wasm-gen": "1.12.1", + "@webassemblyjs/wasm-parser": "1.12.1" } }, "node_modules/@webassemblyjs/wasm-parser": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-parser/-/wasm-parser-1.11.6.tgz", - "integrity": "sha512-6ZwPeGzMJM3Dqp3hCsLgESxBGtT/OeCvCZ4TA1JUPYgmhAx38tTPR9JaKy0S5H3evQpO/h2uWs2j6Yc/fjkpTQ==", + "version": "1.12.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-parser/-/wasm-parser-1.12.1.tgz", + "integrity": "sha512-xikIi7c2FHXysxXe3COrVUPSheuBtpcfhbpFj4gmu7KRLYOzANztwUU0IbsqvMqzuNK2+glRGWCEqZo1WCLyAQ==", "peer": true, "dependencies": { - "@webassemblyjs/ast": "1.11.6", + "@webassemblyjs/ast": "1.12.1", "@webassemblyjs/helper-api-error": "1.11.6", "@webassemblyjs/helper-wasm-bytecode": "1.11.6", "@webassemblyjs/ieee754": "1.11.6", @@ -955,12 +926,12 @@ } }, "node_modules/@webassemblyjs/wast-printer": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wast-printer/-/wast-printer-1.11.6.tgz", - "integrity": "sha512-JM7AhRcE+yW2GWYaKeHL5vt4xqee5N2WcezptmgyhNS+ScggqcT1OtXykhAb13Sn5Yas0j2uv9tHgrjwvzAP4A==", + "version": "1.12.1", + "resolved": "https://registry.npmjs.org/@webassemblyjs/wast-printer/-/wast-printer-1.12.1.tgz", + "integrity": "sha512-+X4WAlOisVWQMikjbcvY2e0rwPsKQ9F688lksZhBcPycBBuii3O7m8FACbDMWDojpAqvjIncrG8J0XHKyQfVeA==", "peer": true, "dependencies": { - "@webassemblyjs/ast": "1.11.6", + "@webassemblyjs/ast": "1.12.1", "@xtuc/long": "4.2.2" } }, @@ -989,9 +960,9 @@ } }, "node_modules/acorn": { - "version": "8.11.2", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.2.tgz", - "integrity": "sha512-nc0Axzp/0FILLEVsm4fNwLCwMttvhEI263QtVPQcbpfZZ3ts0hLsZGOpE6czNlid7CJ9MlyH8reXkpsf3YUY4w==", + "version": "8.12.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.1.tgz", + "integrity": "sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==", "peer": true, "bin": { "acorn": "bin/acorn" @@ -1000,10 +971,10 @@ "node": ">=0.4.0" } }, - "node_modules/acorn-import-assertions": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/acorn-import-assertions/-/acorn-import-assertions-1.9.0.tgz", - "integrity": "sha512-cmMwop9x+8KFhxvKrKfPYmN6/pKTYYHBqLa0DfvVZcKMJWNyWLnaqND7dx/qn66R7ewM1UX5XMaDVP5wlVTaVA==", + "node_modules/acorn-import-attributes": { + "version": "1.9.5", + "resolved": "https://registry.npmjs.org/acorn-import-attributes/-/acorn-import-attributes-1.9.5.tgz", + "integrity": "sha512-n02Vykv5uA3eHGM/Z2dQrcD56kL8TyDb2p1+0P83PClMnC/nc+anbQRhIOWnSq4Ke/KvDPrY3C9hDtC/A3eHnQ==", "peer": true, "peerDependencies": { "acorn": "^8" @@ -1096,9 +1067,9 @@ } }, "node_modules/axios": { - "version": "1.6.8", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz", - "integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==", + "version": "1.7.7", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", + "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", @@ -1144,11 +1115,11 @@ } }, "node_modules/braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", "dependencies": { - "fill-range": "^7.0.1" + "fill-range": "^7.1.1" }, "engines": { "node": ">=8" @@ -1352,9 +1323,9 @@ "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" }, "node_modules/cookie": { - "version": "0.4.2", - "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz", - "integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==", + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", + "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", "engines": { "node": ">= 0.6" } @@ -1445,34 +1416,34 @@ } }, "node_modules/engine.io": { - "version": "6.5.3", - "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.5.3.tgz", - "integrity": "sha512-IML/R4eG/pUS5w7OfcDE0jKrljWS9nwnEfsxWCIJF5eO6AHo6+Hlv+lQbdlAYsiJPHzUthLm1RUjnBzWOs45cw==", + "version": "6.6.2", + "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.6.2.tgz", + "integrity": "sha512-gmNvsYi9C8iErnZdVcJnvCpSKbWTt1E8+JZo8b+daLninywUWi5NQ5STSHZ9rFjFO7imNcvb8Pc5pe/wMR5xEw==", "dependencies": { "@types/cookie": "^0.4.1", "@types/cors": "^2.8.12", "@types/node": ">=10.0.0", "accepts": "~1.3.4", "base64id": "2.0.0", - "cookie": "~0.4.1", + "cookie": "~0.7.2", "cors": "~2.8.5", "debug": "~4.3.1", "engine.io-parser": "~5.2.1", - "ws": "~8.11.0" + "ws": "~8.17.1" }, "engines": { "node": ">=10.2.0" } }, "node_modules/engine.io-client": { - "version": "6.5.2", - "resolved": "https://registry.npmjs.org/engine.io-client/-/engine.io-client-6.5.2.tgz", - "integrity": "sha512-CQZqbrpEYnrpGqC07a9dJDz4gePZUgTPMU3NKJPSeQOyw27Tst4Pl3FemKoFGAlHzgZmKjoRmiJvbWfhCXUlIg==", + "version": "6.5.4", + "resolved": "https://registry.npmjs.org/engine.io-client/-/engine.io-client-6.5.4.tgz", + "integrity": "sha512-GeZeeRjpD2qf49cZQ0Wvh/8NJNfeXkXXcoGh+F77oEAgo9gUHwT1fCRxSNU+YEEaysOJTnsFHmM5oAcPy4ntvQ==", "dependencies": { "@socket.io/component-emitter": "~3.1.0", "debug": "~4.3.1", "engine.io-parser": "~5.2.1", - "ws": "~8.11.0", + "ws": "~8.17.1", "xmlhttprequest-ssl": "~2.0.0" } }, @@ -1485,9 +1456,9 @@ } }, "node_modules/enhanced-resolve": { - "version": "5.15.0", - "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.15.0.tgz", - "integrity": "sha512-LXYT42KJ7lpIKECr2mAXIaMldcNCh/7E0KBKOu4KSfkHmP+mZmSs+8V5gBAqisWBy0OO4W5Oyys0GO1Y8KtdKg==", + "version": "5.17.1", + "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.17.1.tgz", + "integrity": "sha512-LMHl3dXhTcfv8gM4kEzIUeTQ+7fpdA0l2tUf34BddXPkz2A5xJ5L/Pchd5BL6rdccM9QGvu0sWZzK1Z1t4wwyg==", "peer": true, "dependencies": { "graceful-fs": "^4.2.4", @@ -1627,9 +1598,9 @@ } }, "node_modules/fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "dependencies": { "to-regex-range": "^5.0.1" }, @@ -1954,11 +1925,11 @@ } }, "node_modules/micromatch": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", - "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", + "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", "dependencies": { - "braces": "^3.0.2", + "braces": "^3.0.3", "picomatch": "^2.3.1" }, "engines": { @@ -2050,12 +2021,11 @@ "peer": true }, "node_modules/next": { - "version": "14.2.5", - "resolved": "https://registry.npmjs.org/next/-/next-14.2.5.tgz", - "integrity": "sha512-0f8aRfBVL+mpzfBjYfQuLWh2WyAwtJXCRfkPF4UJ5qd2YwrHczsrSzXU4tRMV0OAxR8ZJZWPFn6uhSC56UTsLA==", - "license": "MIT", + "version": "14.2.15", + "resolved": "https://registry.npmjs.org/next/-/next-14.2.15.tgz", + "integrity": "sha512-h9ctmOokpoDphRvMGnwOJAedT6zKhwqyZML9mDtspgf4Rh3Pn7UTYKqePNoDvhsWBAO5GoPNYshnAUGIazVGmw==", "dependencies": { - "@next/env": "14.2.5", + "@next/env": "14.2.15", "@swc/helpers": "0.5.5", "busboy": "1.6.0", "caniuse-lite": "^1.0.30001579", @@ -2070,15 +2040,15 @@ "node": ">=18.17.0" }, "optionalDependencies": { - "@next/swc-darwin-arm64": "14.2.5", - "@next/swc-darwin-x64": "14.2.5", - "@next/swc-linux-arm64-gnu": "14.2.5", - "@next/swc-linux-arm64-musl": "14.2.5", - "@next/swc-linux-x64-gnu": "14.2.5", - "@next/swc-linux-x64-musl": "14.2.5", - "@next/swc-win32-arm64-msvc": "14.2.5", - "@next/swc-win32-ia32-msvc": "14.2.5", - "@next/swc-win32-x64-msvc": "14.2.5" + "@next/swc-darwin-arm64": "14.2.15", + "@next/swc-darwin-x64": "14.2.15", + "@next/swc-linux-arm64-gnu": "14.2.15", + "@next/swc-linux-arm64-musl": "14.2.15", + "@next/swc-linux-x64-gnu": "14.2.15", + "@next/swc-linux-x64-musl": "14.2.15", + "@next/swc-win32-arm64-msvc": "14.2.15", + "@next/swc-win32-ia32-msvc": "14.2.15", + "@next/swc-win32-x64-msvc": "14.2.15" }, "peerDependencies": { "@opentelemetry/api": "^1.1.0", @@ -2573,9 +2543,9 @@ } }, "node_modules/serialize-javascript": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.1.tgz", - "integrity": "sha512-owoXEFjWRllis8/M1Q+Cw5k8ZH40e3zhp/ovX+Xr/vi1qj6QesbyXXViFbpNvWvPNAD62SutwEXavefrLJWj7w==", + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.2.tgz", + "integrity": "sha512-Saa1xPByTTq2gdeFZYLLo+RFE35NHZkAbqZeWNd3BpzppeVisAqpDjcp8dyf6uIvEqJRd46jemmyA4iFIeVk8g==", "peer": true, "dependencies": { "randombytes": "^2.1.0" @@ -2629,15 +2599,15 @@ } }, "node_modules/socket.io": { - "version": "4.7.2", - "resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.7.2.tgz", - "integrity": "sha512-bvKVS29/I5fl2FGLNHuXlQaUH/BlzX1IN6S+NKLNZpBsPZIDH+90eQmCs2Railn4YUiww4SzUedJ6+uzwFnKLw==", + "version": "4.8.0", + "resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.8.0.tgz", + "integrity": "sha512-8U6BEgGjQOfGz3HHTYaC/L1GaxDCJ/KM0XTkJly0EhZ5U/du9uNEZy4ZgYzEzIqlx2CMm25CrCqr1ck899eLNA==", "dependencies": { "accepts": "~1.3.4", "base64id": "~2.0.0", "cors": "~2.8.5", "debug": "~4.3.2", - "engine.io": "~6.5.2", + "engine.io": "~6.6.0", "socket.io-adapter": "~2.5.2", "socket.io-parser": "~4.2.4" }, @@ -2646,11 +2616,12 @@ } }, "node_modules/socket.io-adapter": { - "version": "2.5.2", - "resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-2.5.2.tgz", - "integrity": "sha512-87C3LO/NOMc+eMcpcxUBebGjkpMDkNBS9tf7KJqcDsmL936EChtVva71Dw2q4tQcuVC+hAUy4an2NO/sYXmwRA==", + "version": "2.5.5", + "resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-2.5.5.tgz", + "integrity": "sha512-eLDQas5dzPgOWCk9GuuJC2lBqItuhKI4uxGgo9aIV7MYbk2h9Q6uULEh8WBzThoI7l+qU9Ast9fVUmkqPP9wYg==", "dependencies": { - "ws": "~8.11.0" + "debug": "~4.3.4", + "ws": "~8.17.1" } }, "node_modules/socket.io-client": { @@ -2793,9 +2764,9 @@ } }, "node_modules/sweetalert2": { - "version": "11.10.1", - "resolved": "https://registry.npmjs.org/sweetalert2/-/sweetalert2-11.10.1.tgz", - "integrity": "sha512-qu145oBuFfjYr5yZW9OSdG6YmRxDf8CnkgT/sXMfrXGe+asFy2imC2vlaLQ/L/naZ/JZna1MPAY56G4qYM0VUQ==", + "version": "11.6.13", + "resolved": "https://registry.npmjs.org/sweetalert2/-/sweetalert2-11.6.13.tgz", + "integrity": "sha512-n5yVF0FNx1lm4XzpPyb1HIaiptzODfVyeCzmB809tpK+1bPdoKoevKOxYjrtId75DV7xuIp4r6cjn8xUAB8dPQ==", "funding": { "type": "individual", "url": "https://github.com/sponsors/limonte" @@ -2875,9 +2846,9 @@ } }, "node_modules/terser": { - "version": "5.26.0", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.26.0.tgz", - "integrity": "sha512-dytTGoE2oHgbNV9nTzgBEPaqAWvcJNl66VZ0BkJqlvp71IjO8CxdBx/ykCNb47cLnCmCvRZ6ZR0tLkqvZCdVBQ==", + "version": "5.34.1", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.34.1.tgz", + "integrity": "sha512-FsJZ7iZLd/BXkz+4xrRTGJ26o/6VTjQytUk8b8OxkwcD2I+79VPJlz7qss1+zE7h8GNIScFqXcDyJ/KqBYZFVA==", "peer": true, "dependencies": { "@jridgewell/source-map": "^0.3.3", @@ -2893,16 +2864,16 @@ } }, "node_modules/terser-webpack-plugin": { - "version": "5.3.9", - "resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-5.3.9.tgz", - "integrity": "sha512-ZuXsqE07EcggTWQjXUj+Aot/OMcD0bMKGgF63f7UxYcu5/AJF53aIpK1YoP5xR9l6s/Hy2b+t1AM0bLNPRuhwA==", + "version": "5.3.10", + "resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-5.3.10.tgz", + "integrity": "sha512-BKFPWlPDndPs+NGGCr1U59t0XScL5317Y0UReNrHaw9/FwhPENlq6bfgs+4yPfyP51vqC1bQ4rp1EfXW5ZSH9w==", "peer": true, "dependencies": { - "@jridgewell/trace-mapping": "^0.3.17", + "@jridgewell/trace-mapping": "^0.3.20", "jest-worker": "^27.4.5", "schema-utils": "^3.1.1", "serialize-javascript": "^6.0.1", - "terser": "^5.16.8" + "terser": "^5.26.0" }, "engines": { "node": ">= 10.13.0" @@ -3043,9 +3014,9 @@ } }, "node_modules/watchpack": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.4.0.tgz", - "integrity": "sha512-Lcvm7MGST/4fup+ifyKi2hjyIAwcdI4HRgtvTpIUxBRhB+RFtUh8XtDOxUfctVCnhVi+QQj49i91OyvzkJl6cg==", + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.4.2.tgz", + "integrity": "sha512-TnbFSbcOCcDgjZ4piURLCbJ3nJhznVh9kw6F6iokjiFPl8ONxe9A6nMDVXDiNbrSfLILs6vB07F7wLBrwPYzJw==", "peer": true, "dependencies": { "glob-to-regexp": "^0.4.1", @@ -3056,34 +3027,33 @@ } }, "node_modules/webpack": { - "version": "5.89.0", - "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.89.0.tgz", - "integrity": "sha512-qyfIC10pOr70V+jkmud8tMfajraGCZMBWJtrmuBymQKCrLTRejBI8STDp1MCyZu/QTdZSeacCQYpYNQVOzX5kw==", + "version": "5.95.0", + "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.95.0.tgz", + "integrity": "sha512-2t3XstrKULz41MNMBF+cJ97TyHdyQ8HCt//pqErqDvNjU9YQBnZxIHa11VXsi7F3mb5/aO2tuDxdeTPdU7xu9Q==", "peer": true, "dependencies": { - "@types/eslint-scope": "^3.7.3", - "@types/estree": "^1.0.0", - "@webassemblyjs/ast": "^1.11.5", - "@webassemblyjs/wasm-edit": "^1.11.5", - "@webassemblyjs/wasm-parser": "^1.11.5", + "@types/estree": "^1.0.5", + "@webassemblyjs/ast": "^1.12.1", + "@webassemblyjs/wasm-edit": "^1.12.1", + "@webassemblyjs/wasm-parser": "^1.12.1", "acorn": "^8.7.1", - "acorn-import-assertions": "^1.9.0", - "browserslist": "^4.14.5", + "acorn-import-attributes": "^1.9.5", + "browserslist": "^4.21.10", "chrome-trace-event": "^1.0.2", - "enhanced-resolve": "^5.15.0", + "enhanced-resolve": "^5.17.1", "es-module-lexer": "^1.2.1", "eslint-scope": "5.1.1", "events": "^3.2.0", "glob-to-regexp": "^0.4.1", - "graceful-fs": "^4.2.9", + "graceful-fs": "^4.2.11", "json-parse-even-better-errors": "^2.3.1", "loader-runner": "^4.2.0", "mime-types": "^2.1.27", "neo-async": "^2.6.2", "schema-utils": "^3.2.0", "tapable": "^2.1.1", - "terser-webpack-plugin": "^5.3.7", - "watchpack": "^2.4.0", + "terser-webpack-plugin": "^5.3.10", + "watchpack": "^2.4.1", "webpack-sources": "^3.2.3" }, "bin": { @@ -3117,15 +3087,15 @@ "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" }, "node_modules/ws": { - "version": "8.11.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.11.0.tgz", - "integrity": "sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg==", + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz", + "integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==", "engines": { "node": ">=10.0.0" }, "peerDependencies": { "bufferutil": "^4.0.1", - "utf-8-validate": "^5.0.2" + "utf-8-validate": ">=5.0.2" }, "peerDependenciesMeta": { "bufferutil": { diff --git a/frontend/package.json b/frontend/package.json index a68540c..eb9087c 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -24,7 +24,7 @@ "socket.io": "^4.7.2", "socket.io-client": "^4.7.2", "start": "^5.1.0", - "sweetalert2": "^11.10.1", + "sweetalert2": "^11.6.13", "tailwindcss": "^3.3.3" }, "devDependencies": { diff --git a/frontend/pages/index.tsx b/frontend/pages/index.tsx index 77ea60b..7f394ee 100644 --- a/frontend/pages/index.tsx +++ b/frontend/pages/index.tsx @@ -10,6 +10,7 @@ export default function Home() { const [isModalOpen, setIsModalOpen] = useState(false); const [isChatBotModalOpen, setISChatBotModalOpen] = useState(false); const [redirect, setRedirect] = useState(""); + const [IsHoveringPublicChat,setIsHoveringPublicChat]=useState(false); const openModal = (redirect:string) => { setIsModalOpen(true); @@ -91,11 +92,18 @@ export default function Home() {
setIsHoveringPublicChat(true)} + onMouseLeave={()=>setIsHoveringPublicChat(false)} + + onClick={() => window.open("/404", "_blank")} > -

+

{"slack - PUBLIC MDG CHAT FORUM + {IsHoveringPublicChat ? "COMING SOON" : "PUBLIC MDG CHAT FORUM"}

From b933b7fcb262654cd9d06b6d3072873b9654d9c1 Mon Sep 17 00:00:00 2001 From: kitretsu2809 Date: Wed, 30 Oct 2024 03:28:11 +0530 Subject: [PATCH 31/31] Revert "chore:ChatBotButton Disabled" This reverts commit 9e830f3cb418a42b93d7a93d5ef778cb4591a652. --- frontend/next-env.d.ts | 2 +- frontend/package-lock.json | 404 ++++++++++++++++++++----------------- frontend/package.json | 2 +- frontend/pages/index.tsx | 14 +- 4 files changed, 222 insertions(+), 200 deletions(-) diff --git a/frontend/next-env.d.ts b/frontend/next-env.d.ts index a4a7b3f..4f11a03 100644 --- a/frontend/next-env.d.ts +++ b/frontend/next-env.d.ts @@ -2,4 +2,4 @@ /// // NOTE: This file should not be edited -// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information. +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 90a99dd..dd8f4d3 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -4,7 +4,6 @@ "requires": true, "packages": { "": { - "name": "frontend", "dependencies": { "autoprefixer": "^10.4.16", "axios": "^1.6.8", @@ -23,7 +22,7 @@ "socket.io": "^4.7.2", "socket.io-client": "^4.7.2", "start": "^5.1.0", - "sweetalert2": "^11.6.13", + "sweetalert2": "^11.10.1", "tailwindcss": "^3.3.3" }, "devDependencies": { @@ -484,13 +483,13 @@ } }, "node_modules/@jridgewell/gen-mapping": { - "version": "0.3.5", - "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.5.tgz", - "integrity": "sha512-IzL8ZoEDIBRWEzlCcRhOaCupYyN5gdIK+Q6fbFdPDg6HqX6jpkItn7DFIpW9LQzXG6Df9sA7+OKnq0qlz/GaQg==", + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.3.tgz", + "integrity": "sha512-HLhSWOLRi875zjjMG/r+Nv0oCW8umGb0BgEhyX3dDX3egwZtB8PqLnjz3yedt8R5StBrzcg4aBpnh8UA9D1BoQ==", "dependencies": { - "@jridgewell/set-array": "^1.2.1", + "@jridgewell/set-array": "^1.0.1", "@jridgewell/sourcemap-codec": "^1.4.10", - "@jridgewell/trace-mapping": "^0.3.24" + "@jridgewell/trace-mapping": "^0.3.9" }, "engines": { "node": ">=6.0.0" @@ -505,21 +504,21 @@ } }, "node_modules/@jridgewell/set-array": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.2.1.tgz", - "integrity": "sha512-R8gLRTZeyp03ymzP/6Lil/28tGeGEzhx1q2k703KGWRAI1VdvPIXdG70VJc2pAMw3NA6JKL5hhFu1sJX0Mnn/A==", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.1.2.tgz", + "integrity": "sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==", "engines": { "node": ">=6.0.0" } }, "node_modules/@jridgewell/source-map": { - "version": "0.3.6", - "resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.6.tgz", - "integrity": "sha512-1ZJTZebgqllO79ue2bm3rIGud/bOe0pP5BjSRCRxxYkEZS8STV7zN84UBbiYu7jy+eCKSnVIUgoWWE/tt+shMQ==", + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.5.tgz", + "integrity": "sha512-UTYAUj/wviwdsMfzoSJspJxbkH5o1snzwX0//0ENX1u/55kkZZkcTZP6u9bwKGkv+dkk9at4m1Cpt0uY80kcpQ==", "peer": true, "dependencies": { - "@jridgewell/gen-mapping": "^0.3.5", - "@jridgewell/trace-mapping": "^0.3.25" + "@jridgewell/gen-mapping": "^0.3.0", + "@jridgewell/trace-mapping": "^0.3.9" } }, "node_modules/@jridgewell/sourcemap-codec": { @@ -528,26 +527,28 @@ "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==" }, "node_modules/@jridgewell/trace-mapping": { - "version": "0.3.25", - "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.25.tgz", - "integrity": "sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==", + "version": "0.3.19", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.19.tgz", + "integrity": "sha512-kf37QtfW+Hwx/buWGMPcR60iF9ziHa6r/CZJIHbmcm4+0qrXiVdxegAH0F6yddEVQ7zdkjcGCgCzUu+BcbhQxw==", "dependencies": { "@jridgewell/resolve-uri": "^3.1.0", "@jridgewell/sourcemap-codec": "^1.4.14" } }, "node_modules/@next/env": { - "version": "14.2.15", - "resolved": "https://registry.npmjs.org/@next/env/-/env-14.2.15.tgz", - "integrity": "sha512-S1qaj25Wru2dUpcIZMjxeMVSwkt8BK4dmWHHiBuRstcIyOsMapqT4A4jSB6onvqeygkSSmOkyny9VVx8JIGamQ==" + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/env/-/env-14.2.5.tgz", + "integrity": "sha512-/zZGkrTOsraVfYjGP8uM0p6r0BDT6xWpkjdVbcz66PJVSpwXX3yNiRycxAuDfBKGWBrZBXRuK/YVlkNgxHGwmA==", + "license": "MIT" }, "node_modules/@next/swc-darwin-arm64": { - "version": "14.2.15", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.15.tgz", - "integrity": "sha512-Rvh7KU9hOUBnZ9TJ28n2Oa7dD9cvDBKua9IKx7cfQQ0GoYUwg9ig31O2oMwH3wm+pE3IkAQ67ZobPfEgurPZIA==", + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.5.tgz", + "integrity": "sha512-/9zVxJ+K9lrzSGli1///ujyRfon/ZneeZ+v4ptpiPoOU+GKZnm8Wj8ELWU1Pm7GHltYRBklmXMTUqM/DqQ99FQ==", "cpu": [ "arm64" ], + "license": "MIT", "optional": true, "os": [ "darwin" @@ -557,12 +558,13 @@ } }, "node_modules/@next/swc-darwin-x64": { - "version": "14.2.15", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.15.tgz", - "integrity": "sha512-5TGyjFcf8ampZP3e+FyCax5zFVHi+Oe7sZyaKOngsqyaNEpOgkKB3sqmymkZfowy3ufGA/tUgDPPxpQx931lHg==", + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.5.tgz", + "integrity": "sha512-vXHOPCwfDe9qLDuq7U1OYM2wUY+KQ4Ex6ozwsKxp26BlJ6XXbHleOUldenM67JRyBfVjv371oneEvYd3H2gNSA==", "cpu": [ "x64" ], + "license": "MIT", "optional": true, "os": [ "darwin" @@ -572,12 +574,13 @@ } }, "node_modules/@next/swc-linux-arm64-gnu": { - "version": "14.2.15", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.15.tgz", - "integrity": "sha512-3Bwv4oc08ONiQ3FiOLKT72Q+ndEMyLNsc/D3qnLMbtUYTQAmkx9E/JRu0DBpHxNddBmNT5hxz1mYBphJ3mfrrw==", + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.5.tgz", + "integrity": "sha512-vlhB8wI+lj8q1ExFW8lbWutA4M2ZazQNvMWuEDqZcuJJc78iUnLdPPunBPX8rC4IgT6lIx/adB+Cwrl99MzNaA==", "cpu": [ "arm64" ], + "license": "MIT", "optional": true, "os": [ "linux" @@ -587,12 +590,13 @@ } }, "node_modules/@next/swc-linux-arm64-musl": { - "version": "14.2.15", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.15.tgz", - "integrity": "sha512-k5xf/tg1FBv/M4CMd8S+JL3uV9BnnRmoe7F+GWC3DxkTCD9aewFRH1s5rJ1zkzDa+Do4zyN8qD0N8c84Hu96FQ==", + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.5.tgz", + "integrity": "sha512-NpDB9NUR2t0hXzJJwQSGu1IAOYybsfeB+LxpGsXrRIb7QOrYmidJz3shzY8cM6+rO4Aojuef0N/PEaX18pi9OA==", "cpu": [ "arm64" ], + "license": "MIT", "optional": true, "os": [ "linux" @@ -602,12 +606,13 @@ } }, "node_modules/@next/swc-linux-x64-gnu": { - "version": "14.2.15", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.15.tgz", - "integrity": "sha512-kE6q38hbrRbKEkkVn62reLXhThLRh6/TvgSP56GkFNhU22TbIrQDEMrO7j0IcQHcew2wfykq8lZyHFabz0oBrA==", + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.5.tgz", + "integrity": "sha512-8XFikMSxWleYNryWIjiCX+gU201YS+erTUidKdyOVYi5qUQo/gRxv/3N1oZFCgqpesN6FPeqGM72Zve+nReVXQ==", "cpu": [ "x64" ], + "license": "MIT", "optional": true, "os": [ "linux" @@ -617,12 +622,13 @@ } }, "node_modules/@next/swc-linux-x64-musl": { - "version": "14.2.15", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.15.tgz", - "integrity": "sha512-PZ5YE9ouy/IdO7QVJeIcyLn/Rc4ml9M2G4y3kCM9MNf1YKvFY4heg3pVa/jQbMro+tP6yc4G2o9LjAz1zxD7tQ==", + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.5.tgz", + "integrity": "sha512-6QLwi7RaYiQDcRDSU/os40r5o06b5ue7Jsk5JgdRBGGp8l37RZEh9JsLSM8QF0YDsgcosSeHjglgqi25+m04IQ==", "cpu": [ "x64" ], + "license": "MIT", "optional": true, "os": [ "linux" @@ -632,12 +638,13 @@ } }, "node_modules/@next/swc-win32-arm64-msvc": { - "version": "14.2.15", - "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.15.tgz", - "integrity": "sha512-2raR16703kBvYEQD9HNLyb0/394yfqzmIeyp2nDzcPV4yPjqNUG3ohX6jX00WryXz6s1FXpVhsCo3i+g4RUX+g==", + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.5.tgz", + "integrity": "sha512-1GpG2VhbspO+aYoMOQPQiqc/tG3LzmsdBH0LhnDS3JrtDx2QmzXe0B6mSZZiN3Bq7IOMXxv1nlsjzoS1+9mzZw==", "cpu": [ "arm64" ], + "license": "MIT", "optional": true, "os": [ "win32" @@ -647,12 +654,13 @@ } }, "node_modules/@next/swc-win32-ia32-msvc": { - "version": "14.2.15", - "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.15.tgz", - "integrity": "sha512-fyTE8cklgkyR1p03kJa5zXEaZ9El+kDNM5A+66+8evQS5e/6v0Gk28LqA0Jet8gKSOyP+OTm/tJHzMlGdQerdQ==", + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.5.tgz", + "integrity": "sha512-Igh9ZlxwvCDsu6438FXlQTHlRno4gFpJzqPjSIBZooD22tKeI4fE/YMRoHVJHmrQ2P5YL1DoZ0qaOKkbeFWeMg==", "cpu": [ "ia32" ], + "license": "MIT", "optional": true, "os": [ "win32" @@ -662,12 +670,13 @@ } }, "node_modules/@next/swc-win32-x64-msvc": { - "version": "14.2.15", - "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.15.tgz", - "integrity": "sha512-SzqGbsLsP9OwKNUG9nekShTwhj6JSB9ZLMWQ8g1gG6hdE5gQLncbnbymrwy2yVmH9nikSLYRYxYMFu78Ggp7/g==", + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.5.tgz", + "integrity": "sha512-tEQ7oinq1/CjSG9uSTerca3v4AZ+dFa+4Yu6ihaG8Ud8ddqLQgFGcnwYls13H5X5CPDPZJdYxyeMui6muOLd4g==", "cpu": [ "x64" ], + "license": "MIT", "optional": true, "os": [ "win32" @@ -744,17 +753,37 @@ "integrity": "sha512-XW/Aa8APYr6jSVVA1y/DEIZX0/GMKLEVekNG727R8cs56ahETkRAy/3DR7+fJyh7oUgGwNQaRfXCun0+KbWY7Q==" }, "node_modules/@types/cors": { - "version": "2.8.17", - "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.17.tgz", - "integrity": "sha512-8CGDvrBj1zgo2qE+oS3pOCyYNqCPryMWY2bGfwA0dcfopWGgxs+78df0Rs3rc9THP4JkOhLsAa+15VdpAqkcUA==", + "version": "2.8.15", + "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.15.tgz", + "integrity": "sha512-n91JxbNLD8eQIuXDIChAN1tCKNWCEgpceU9b7ZMbFA+P+Q4yIeh80jizFLEvolRPc1ES0VdwFlGv+kJTSirogw==", "dependencies": { "@types/node": "*" } }, + "node_modules/@types/eslint": { + "version": "8.56.0", + "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.56.0.tgz", + "integrity": "sha512-FlsN0p4FhuYRjIxpbdXovvHQhtlG05O1GG/RNWvdAxTboR438IOTwmrY/vLA+Xfgg06BTkP045M3vpFwTMv1dg==", + "peer": true, + "dependencies": { + "@types/estree": "*", + "@types/json-schema": "*" + } + }, + "node_modules/@types/eslint-scope": { + "version": "3.7.7", + "resolved": "https://registry.npmjs.org/@types/eslint-scope/-/eslint-scope-3.7.7.tgz", + "integrity": "sha512-MzMFlSLBqNF2gcHWO0G1vP/YQyfvrxZ0bF+u7mzUdZ1/xK4A4sru+nraZz5i3iEIk1l1uyicaDVTB4QbbEkAYg==", + "peer": true, + "dependencies": { + "@types/eslint": "*", + "@types/estree": "*" + } + }, "node_modules/@types/estree": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.6.tgz", - "integrity": "sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw==", + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", + "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==", "peer": true }, "node_modules/@types/json-schema": { @@ -790,9 +819,9 @@ } }, "node_modules/@webassemblyjs/ast": { - "version": "1.12.1", - "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.12.1.tgz", - "integrity": "sha512-EKfMUOPRRUTy5UII4qJDGPpqfwjOmZ5jeGFwid9mnoqIFK+e0vqoi1qH56JpmZSzEL53jKnNzScdmftJyG5xWg==", + "version": "1.11.6", + "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.6.tgz", + "integrity": "sha512-IN1xI7PwOvLPgjcf180gC1bqn3q/QaOCwYUahIOhbYUu8KA/3tw2RT/T0Gidi1l7Hhj5D/INhJxiICObqpMu4Q==", "peer": true, "dependencies": { "@webassemblyjs/helper-numbers": "1.11.6", @@ -812,9 +841,9 @@ "peer": true }, "node_modules/@webassemblyjs/helper-buffer": { - "version": "1.12.1", - "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-buffer/-/helper-buffer-1.12.1.tgz", - "integrity": "sha512-nzJwQw99DNDKr9BVCOZcLuJJUlqkJh+kVzVl6Fmq/tI5ZtEyWT1KZMyOXltXLZJmDtvLCDgwsyrkohEtopTXCw==", + "version": "1.11.6", + "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-buffer/-/helper-buffer-1.11.6.tgz", + "integrity": "sha512-z3nFzdcp1mb8nEOFFk8DrYLpHvhKC3grJD2ardfKOzmbmJvEf/tPIqCY+sNcwZIY8ZD7IkB2l7/pqhUhqm7hLA==", "peer": true }, "node_modules/@webassemblyjs/helper-numbers": { @@ -835,15 +864,15 @@ "peer": true }, "node_modules/@webassemblyjs/helper-wasm-section": { - "version": "1.12.1", - "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.12.1.tgz", - "integrity": "sha512-Jif4vfB6FJlUlSbgEMHUyk1j234GTNG9dBJ4XJdOySoj518Xj0oGsNi59cUQF4RRMS9ouBUxDDdyBVfPTypa5g==", + "version": "1.11.6", + "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.11.6.tgz", + "integrity": "sha512-LPpZbSOwTpEC2cgn4hTydySy1Ke+XEu+ETXuoyvuyezHO3Kjdu90KK95Sh9xTbmjrCsUwvWwCOQQNta37VrS9g==", "peer": true, "dependencies": { - "@webassemblyjs/ast": "1.12.1", - "@webassemblyjs/helper-buffer": "1.12.1", + "@webassemblyjs/ast": "1.11.6", + "@webassemblyjs/helper-buffer": "1.11.6", "@webassemblyjs/helper-wasm-bytecode": "1.11.6", - "@webassemblyjs/wasm-gen": "1.12.1" + "@webassemblyjs/wasm-gen": "1.11.6" } }, "node_modules/@webassemblyjs/ieee754": { @@ -871,28 +900,28 @@ "peer": true }, "node_modules/@webassemblyjs/wasm-edit": { - "version": "1.12.1", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-edit/-/wasm-edit-1.12.1.tgz", - "integrity": "sha512-1DuwbVvADvS5mGnXbE+c9NfA8QRcZ6iKquqjjmR10k6o+zzsRVesil54DKexiowcFCPdr/Q0qaMgB01+SQ1u6g==", + "version": "1.11.6", + "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-edit/-/wasm-edit-1.11.6.tgz", + "integrity": "sha512-Ybn2I6fnfIGuCR+Faaz7YcvtBKxvoLV3Lebn1tM4o/IAJzmi9AWYIPWpyBfU8cC+JxAO57bk4+zdsTjJR+VTOw==", "peer": true, "dependencies": { - "@webassemblyjs/ast": "1.12.1", - "@webassemblyjs/helper-buffer": "1.12.1", + "@webassemblyjs/ast": "1.11.6", + "@webassemblyjs/helper-buffer": "1.11.6", "@webassemblyjs/helper-wasm-bytecode": "1.11.6", - "@webassemblyjs/helper-wasm-section": "1.12.1", - "@webassemblyjs/wasm-gen": "1.12.1", - "@webassemblyjs/wasm-opt": "1.12.1", - "@webassemblyjs/wasm-parser": "1.12.1", - "@webassemblyjs/wast-printer": "1.12.1" + "@webassemblyjs/helper-wasm-section": "1.11.6", + "@webassemblyjs/wasm-gen": "1.11.6", + "@webassemblyjs/wasm-opt": "1.11.6", + "@webassemblyjs/wasm-parser": "1.11.6", + "@webassemblyjs/wast-printer": "1.11.6" } }, "node_modules/@webassemblyjs/wasm-gen": { - "version": "1.12.1", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-gen/-/wasm-gen-1.12.1.tgz", - "integrity": "sha512-TDq4Ojh9fcohAw6OIMXqiIcTq5KUXTGRkVxbSo1hQnSy6lAM5GSdfwWeSxpAo0YzgsgF182E/U0mDNhuA0tW7w==", + "version": "1.11.6", + "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-gen/-/wasm-gen-1.11.6.tgz", + "integrity": "sha512-3XOqkZP/y6B4F0PBAXvI1/bky7GryoogUtfwExeP/v7Nzwo1QLcq5oQmpKlftZLbT+ERUOAZVQjuNVak6UXjPA==", "peer": true, "dependencies": { - "@webassemblyjs/ast": "1.12.1", + "@webassemblyjs/ast": "1.11.6", "@webassemblyjs/helper-wasm-bytecode": "1.11.6", "@webassemblyjs/ieee754": "1.11.6", "@webassemblyjs/leb128": "1.11.6", @@ -900,24 +929,24 @@ } }, "node_modules/@webassemblyjs/wasm-opt": { - "version": "1.12.1", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-opt/-/wasm-opt-1.12.1.tgz", - "integrity": "sha512-Jg99j/2gG2iaz3hijw857AVYekZe2SAskcqlWIZXjji5WStnOpVoat3gQfT/Q5tb2djnCjBtMocY/Su1GfxPBg==", + "version": "1.11.6", + "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-opt/-/wasm-opt-1.11.6.tgz", + "integrity": "sha512-cOrKuLRE7PCe6AsOVl7WasYf3wbSo4CeOk6PkrjS7g57MFfVUF9u6ysQBBODX0LdgSvQqRiGz3CXvIDKcPNy4g==", "peer": true, "dependencies": { - "@webassemblyjs/ast": "1.12.1", - "@webassemblyjs/helper-buffer": "1.12.1", - "@webassemblyjs/wasm-gen": "1.12.1", - "@webassemblyjs/wasm-parser": "1.12.1" + "@webassemblyjs/ast": "1.11.6", + "@webassemblyjs/helper-buffer": "1.11.6", + "@webassemblyjs/wasm-gen": "1.11.6", + "@webassemblyjs/wasm-parser": "1.11.6" } }, "node_modules/@webassemblyjs/wasm-parser": { - "version": "1.12.1", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-parser/-/wasm-parser-1.12.1.tgz", - "integrity": "sha512-xikIi7c2FHXysxXe3COrVUPSheuBtpcfhbpFj4gmu7KRLYOzANztwUU0IbsqvMqzuNK2+glRGWCEqZo1WCLyAQ==", + "version": "1.11.6", + "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-parser/-/wasm-parser-1.11.6.tgz", + "integrity": "sha512-6ZwPeGzMJM3Dqp3hCsLgESxBGtT/OeCvCZ4TA1JUPYgmhAx38tTPR9JaKy0S5H3evQpO/h2uWs2j6Yc/fjkpTQ==", "peer": true, "dependencies": { - "@webassemblyjs/ast": "1.12.1", + "@webassemblyjs/ast": "1.11.6", "@webassemblyjs/helper-api-error": "1.11.6", "@webassemblyjs/helper-wasm-bytecode": "1.11.6", "@webassemblyjs/ieee754": "1.11.6", @@ -926,12 +955,12 @@ } }, "node_modules/@webassemblyjs/wast-printer": { - "version": "1.12.1", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wast-printer/-/wast-printer-1.12.1.tgz", - "integrity": "sha512-+X4WAlOisVWQMikjbcvY2e0rwPsKQ9F688lksZhBcPycBBuii3O7m8FACbDMWDojpAqvjIncrG8J0XHKyQfVeA==", + "version": "1.11.6", + "resolved": "https://registry.npmjs.org/@webassemblyjs/wast-printer/-/wast-printer-1.11.6.tgz", + "integrity": "sha512-JM7AhRcE+yW2GWYaKeHL5vt4xqee5N2WcezptmgyhNS+ScggqcT1OtXykhAb13Sn5Yas0j2uv9tHgrjwvzAP4A==", "peer": true, "dependencies": { - "@webassemblyjs/ast": "1.12.1", + "@webassemblyjs/ast": "1.11.6", "@xtuc/long": "4.2.2" } }, @@ -960,9 +989,9 @@ } }, "node_modules/acorn": { - "version": "8.12.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.1.tgz", - "integrity": "sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==", + "version": "8.11.2", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.2.tgz", + "integrity": "sha512-nc0Axzp/0FILLEVsm4fNwLCwMttvhEI263QtVPQcbpfZZ3ts0hLsZGOpE6czNlid7CJ9MlyH8reXkpsf3YUY4w==", "peer": true, "bin": { "acorn": "bin/acorn" @@ -971,10 +1000,10 @@ "node": ">=0.4.0" } }, - "node_modules/acorn-import-attributes": { - "version": "1.9.5", - "resolved": "https://registry.npmjs.org/acorn-import-attributes/-/acorn-import-attributes-1.9.5.tgz", - "integrity": "sha512-n02Vykv5uA3eHGM/Z2dQrcD56kL8TyDb2p1+0P83PClMnC/nc+anbQRhIOWnSq4Ke/KvDPrY3C9hDtC/A3eHnQ==", + "node_modules/acorn-import-assertions": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/acorn-import-assertions/-/acorn-import-assertions-1.9.0.tgz", + "integrity": "sha512-cmMwop9x+8KFhxvKrKfPYmN6/pKTYYHBqLa0DfvVZcKMJWNyWLnaqND7dx/qn66R7ewM1UX5XMaDVP5wlVTaVA==", "peer": true, "peerDependencies": { "acorn": "^8" @@ -1067,9 +1096,9 @@ } }, "node_modules/axios": { - "version": "1.7.7", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", - "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", + "version": "1.6.8", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz", + "integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==", "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", @@ -1115,11 +1144,11 @@ } }, "node_modules/braces": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", - "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", "dependencies": { - "fill-range": "^7.1.1" + "fill-range": "^7.0.1" }, "engines": { "node": ">=8" @@ -1323,9 +1352,9 @@ "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" }, "node_modules/cookie": { - "version": "0.7.2", - "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", - "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz", + "integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==", "engines": { "node": ">= 0.6" } @@ -1416,34 +1445,34 @@ } }, "node_modules/engine.io": { - "version": "6.6.2", - "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.6.2.tgz", - "integrity": "sha512-gmNvsYi9C8iErnZdVcJnvCpSKbWTt1E8+JZo8b+daLninywUWi5NQ5STSHZ9rFjFO7imNcvb8Pc5pe/wMR5xEw==", + "version": "6.5.3", + "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.5.3.tgz", + "integrity": "sha512-IML/R4eG/pUS5w7OfcDE0jKrljWS9nwnEfsxWCIJF5eO6AHo6+Hlv+lQbdlAYsiJPHzUthLm1RUjnBzWOs45cw==", "dependencies": { "@types/cookie": "^0.4.1", "@types/cors": "^2.8.12", "@types/node": ">=10.0.0", "accepts": "~1.3.4", "base64id": "2.0.0", - "cookie": "~0.7.2", + "cookie": "~0.4.1", "cors": "~2.8.5", "debug": "~4.3.1", "engine.io-parser": "~5.2.1", - "ws": "~8.17.1" + "ws": "~8.11.0" }, "engines": { "node": ">=10.2.0" } }, "node_modules/engine.io-client": { - "version": "6.5.4", - "resolved": "https://registry.npmjs.org/engine.io-client/-/engine.io-client-6.5.4.tgz", - "integrity": "sha512-GeZeeRjpD2qf49cZQ0Wvh/8NJNfeXkXXcoGh+F77oEAgo9gUHwT1fCRxSNU+YEEaysOJTnsFHmM5oAcPy4ntvQ==", + "version": "6.5.2", + "resolved": "https://registry.npmjs.org/engine.io-client/-/engine.io-client-6.5.2.tgz", + "integrity": "sha512-CQZqbrpEYnrpGqC07a9dJDz4gePZUgTPMU3NKJPSeQOyw27Tst4Pl3FemKoFGAlHzgZmKjoRmiJvbWfhCXUlIg==", "dependencies": { "@socket.io/component-emitter": "~3.1.0", "debug": "~4.3.1", "engine.io-parser": "~5.2.1", - "ws": "~8.17.1", + "ws": "~8.11.0", "xmlhttprequest-ssl": "~2.0.0" } }, @@ -1456,9 +1485,9 @@ } }, "node_modules/enhanced-resolve": { - "version": "5.17.1", - "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.17.1.tgz", - "integrity": "sha512-LMHl3dXhTcfv8gM4kEzIUeTQ+7fpdA0l2tUf34BddXPkz2A5xJ5L/Pchd5BL6rdccM9QGvu0sWZzK1Z1t4wwyg==", + "version": "5.15.0", + "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.15.0.tgz", + "integrity": "sha512-LXYT42KJ7lpIKECr2mAXIaMldcNCh/7E0KBKOu4KSfkHmP+mZmSs+8V5gBAqisWBy0OO4W5Oyys0GO1Y8KtdKg==", "peer": true, "dependencies": { "graceful-fs": "^4.2.4", @@ -1598,9 +1627,9 @@ } }, "node_modules/fill-range": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", - "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", "dependencies": { "to-regex-range": "^5.0.1" }, @@ -1925,11 +1954,11 @@ } }, "node_modules/micromatch": { - "version": "4.0.8", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", - "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", + "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", "dependencies": { - "braces": "^3.0.3", + "braces": "^3.0.2", "picomatch": "^2.3.1" }, "engines": { @@ -2021,11 +2050,12 @@ "peer": true }, "node_modules/next": { - "version": "14.2.15", - "resolved": "https://registry.npmjs.org/next/-/next-14.2.15.tgz", - "integrity": "sha512-h9ctmOokpoDphRvMGnwOJAedT6zKhwqyZML9mDtspgf4Rh3Pn7UTYKqePNoDvhsWBAO5GoPNYshnAUGIazVGmw==", + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/next/-/next-14.2.5.tgz", + "integrity": "sha512-0f8aRfBVL+mpzfBjYfQuLWh2WyAwtJXCRfkPF4UJ5qd2YwrHczsrSzXU4tRMV0OAxR8ZJZWPFn6uhSC56UTsLA==", + "license": "MIT", "dependencies": { - "@next/env": "14.2.15", + "@next/env": "14.2.5", "@swc/helpers": "0.5.5", "busboy": "1.6.0", "caniuse-lite": "^1.0.30001579", @@ -2040,15 +2070,15 @@ "node": ">=18.17.0" }, "optionalDependencies": { - "@next/swc-darwin-arm64": "14.2.15", - "@next/swc-darwin-x64": "14.2.15", - "@next/swc-linux-arm64-gnu": "14.2.15", - "@next/swc-linux-arm64-musl": "14.2.15", - "@next/swc-linux-x64-gnu": "14.2.15", - "@next/swc-linux-x64-musl": "14.2.15", - "@next/swc-win32-arm64-msvc": "14.2.15", - "@next/swc-win32-ia32-msvc": "14.2.15", - "@next/swc-win32-x64-msvc": "14.2.15" + "@next/swc-darwin-arm64": "14.2.5", + "@next/swc-darwin-x64": "14.2.5", + "@next/swc-linux-arm64-gnu": "14.2.5", + "@next/swc-linux-arm64-musl": "14.2.5", + "@next/swc-linux-x64-gnu": "14.2.5", + "@next/swc-linux-x64-musl": "14.2.5", + "@next/swc-win32-arm64-msvc": "14.2.5", + "@next/swc-win32-ia32-msvc": "14.2.5", + "@next/swc-win32-x64-msvc": "14.2.5" }, "peerDependencies": { "@opentelemetry/api": "^1.1.0", @@ -2543,9 +2573,9 @@ } }, "node_modules/serialize-javascript": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.2.tgz", - "integrity": "sha512-Saa1xPByTTq2gdeFZYLLo+RFE35NHZkAbqZeWNd3BpzppeVisAqpDjcp8dyf6uIvEqJRd46jemmyA4iFIeVk8g==", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.1.tgz", + "integrity": "sha512-owoXEFjWRllis8/M1Q+Cw5k8ZH40e3zhp/ovX+Xr/vi1qj6QesbyXXViFbpNvWvPNAD62SutwEXavefrLJWj7w==", "peer": true, "dependencies": { "randombytes": "^2.1.0" @@ -2599,15 +2629,15 @@ } }, "node_modules/socket.io": { - "version": "4.8.0", - "resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.8.0.tgz", - "integrity": "sha512-8U6BEgGjQOfGz3HHTYaC/L1GaxDCJ/KM0XTkJly0EhZ5U/du9uNEZy4ZgYzEzIqlx2CMm25CrCqr1ck899eLNA==", + "version": "4.7.2", + "resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.7.2.tgz", + "integrity": "sha512-bvKVS29/I5fl2FGLNHuXlQaUH/BlzX1IN6S+NKLNZpBsPZIDH+90eQmCs2Railn4YUiww4SzUedJ6+uzwFnKLw==", "dependencies": { "accepts": "~1.3.4", "base64id": "~2.0.0", "cors": "~2.8.5", "debug": "~4.3.2", - "engine.io": "~6.6.0", + "engine.io": "~6.5.2", "socket.io-adapter": "~2.5.2", "socket.io-parser": "~4.2.4" }, @@ -2616,12 +2646,11 @@ } }, "node_modules/socket.io-adapter": { - "version": "2.5.5", - "resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-2.5.5.tgz", - "integrity": "sha512-eLDQas5dzPgOWCk9GuuJC2lBqItuhKI4uxGgo9aIV7MYbk2h9Q6uULEh8WBzThoI7l+qU9Ast9fVUmkqPP9wYg==", + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-2.5.2.tgz", + "integrity": "sha512-87C3LO/NOMc+eMcpcxUBebGjkpMDkNBS9tf7KJqcDsmL936EChtVva71Dw2q4tQcuVC+hAUy4an2NO/sYXmwRA==", "dependencies": { - "debug": "~4.3.4", - "ws": "~8.17.1" + "ws": "~8.11.0" } }, "node_modules/socket.io-client": { @@ -2764,9 +2793,9 @@ } }, "node_modules/sweetalert2": { - "version": "11.6.13", - "resolved": "https://registry.npmjs.org/sweetalert2/-/sweetalert2-11.6.13.tgz", - "integrity": "sha512-n5yVF0FNx1lm4XzpPyb1HIaiptzODfVyeCzmB809tpK+1bPdoKoevKOxYjrtId75DV7xuIp4r6cjn8xUAB8dPQ==", + "version": "11.10.1", + "resolved": "https://registry.npmjs.org/sweetalert2/-/sweetalert2-11.10.1.tgz", + "integrity": "sha512-qu145oBuFfjYr5yZW9OSdG6YmRxDf8CnkgT/sXMfrXGe+asFy2imC2vlaLQ/L/naZ/JZna1MPAY56G4qYM0VUQ==", "funding": { "type": "individual", "url": "https://github.com/sponsors/limonte" @@ -2846,9 +2875,9 @@ } }, "node_modules/terser": { - "version": "5.34.1", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.34.1.tgz", - "integrity": "sha512-FsJZ7iZLd/BXkz+4xrRTGJ26o/6VTjQytUk8b8OxkwcD2I+79VPJlz7qss1+zE7h8GNIScFqXcDyJ/KqBYZFVA==", + "version": "5.26.0", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.26.0.tgz", + "integrity": "sha512-dytTGoE2oHgbNV9nTzgBEPaqAWvcJNl66VZ0BkJqlvp71IjO8CxdBx/ykCNb47cLnCmCvRZ6ZR0tLkqvZCdVBQ==", "peer": true, "dependencies": { "@jridgewell/source-map": "^0.3.3", @@ -2864,16 +2893,16 @@ } }, "node_modules/terser-webpack-plugin": { - "version": "5.3.10", - "resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-5.3.10.tgz", - "integrity": "sha512-BKFPWlPDndPs+NGGCr1U59t0XScL5317Y0UReNrHaw9/FwhPENlq6bfgs+4yPfyP51vqC1bQ4rp1EfXW5ZSH9w==", + "version": "5.3.9", + "resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-5.3.9.tgz", + "integrity": "sha512-ZuXsqE07EcggTWQjXUj+Aot/OMcD0bMKGgF63f7UxYcu5/AJF53aIpK1YoP5xR9l6s/Hy2b+t1AM0bLNPRuhwA==", "peer": true, "dependencies": { - "@jridgewell/trace-mapping": "^0.3.20", + "@jridgewell/trace-mapping": "^0.3.17", "jest-worker": "^27.4.5", "schema-utils": "^3.1.1", "serialize-javascript": "^6.0.1", - "terser": "^5.26.0" + "terser": "^5.16.8" }, "engines": { "node": ">= 10.13.0" @@ -3014,9 +3043,9 @@ } }, "node_modules/watchpack": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.4.2.tgz", - "integrity": "sha512-TnbFSbcOCcDgjZ4piURLCbJ3nJhznVh9kw6F6iokjiFPl8ONxe9A6nMDVXDiNbrSfLILs6vB07F7wLBrwPYzJw==", + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.4.0.tgz", + "integrity": "sha512-Lcvm7MGST/4fup+ifyKi2hjyIAwcdI4HRgtvTpIUxBRhB+RFtUh8XtDOxUfctVCnhVi+QQj49i91OyvzkJl6cg==", "peer": true, "dependencies": { "glob-to-regexp": "^0.4.1", @@ -3027,33 +3056,34 @@ } }, "node_modules/webpack": { - "version": "5.95.0", - "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.95.0.tgz", - "integrity": "sha512-2t3XstrKULz41MNMBF+cJ97TyHdyQ8HCt//pqErqDvNjU9YQBnZxIHa11VXsi7F3mb5/aO2tuDxdeTPdU7xu9Q==", + "version": "5.89.0", + "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.89.0.tgz", + "integrity": "sha512-qyfIC10pOr70V+jkmud8tMfajraGCZMBWJtrmuBymQKCrLTRejBI8STDp1MCyZu/QTdZSeacCQYpYNQVOzX5kw==", "peer": true, "dependencies": { - "@types/estree": "^1.0.5", - "@webassemblyjs/ast": "^1.12.1", - "@webassemblyjs/wasm-edit": "^1.12.1", - "@webassemblyjs/wasm-parser": "^1.12.1", + "@types/eslint-scope": "^3.7.3", + "@types/estree": "^1.0.0", + "@webassemblyjs/ast": "^1.11.5", + "@webassemblyjs/wasm-edit": "^1.11.5", + "@webassemblyjs/wasm-parser": "^1.11.5", "acorn": "^8.7.1", - "acorn-import-attributes": "^1.9.5", - "browserslist": "^4.21.10", + "acorn-import-assertions": "^1.9.0", + "browserslist": "^4.14.5", "chrome-trace-event": "^1.0.2", - "enhanced-resolve": "^5.17.1", + "enhanced-resolve": "^5.15.0", "es-module-lexer": "^1.2.1", "eslint-scope": "5.1.1", "events": "^3.2.0", "glob-to-regexp": "^0.4.1", - "graceful-fs": "^4.2.11", + "graceful-fs": "^4.2.9", "json-parse-even-better-errors": "^2.3.1", "loader-runner": "^4.2.0", "mime-types": "^2.1.27", "neo-async": "^2.6.2", "schema-utils": "^3.2.0", "tapable": "^2.1.1", - "terser-webpack-plugin": "^5.3.10", - "watchpack": "^2.4.1", + "terser-webpack-plugin": "^5.3.7", + "watchpack": "^2.4.0", "webpack-sources": "^3.2.3" }, "bin": { @@ -3087,15 +3117,15 @@ "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" }, "node_modules/ws": { - "version": "8.17.1", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz", - "integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==", + "version": "8.11.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.11.0.tgz", + "integrity": "sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg==", "engines": { "node": ">=10.0.0" }, "peerDependencies": { "bufferutil": "^4.0.1", - "utf-8-validate": ">=5.0.2" + "utf-8-validate": "^5.0.2" }, "peerDependenciesMeta": { "bufferutil": { diff --git a/frontend/package.json b/frontend/package.json index eb9087c..a68540c 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -24,7 +24,7 @@ "socket.io": "^4.7.2", "socket.io-client": "^4.7.2", "start": "^5.1.0", - "sweetalert2": "^11.6.13", + "sweetalert2": "^11.10.1", "tailwindcss": "^3.3.3" }, "devDependencies": { diff --git a/frontend/pages/index.tsx b/frontend/pages/index.tsx index 7f394ee..77ea60b 100644 --- a/frontend/pages/index.tsx +++ b/frontend/pages/index.tsx @@ -10,7 +10,6 @@ export default function Home() { const [isModalOpen, setIsModalOpen] = useState(false); const [isChatBotModalOpen, setISChatBotModalOpen] = useState(false); const [redirect, setRedirect] = useState(""); - const [IsHoveringPublicChat,setIsHoveringPublicChat]=useState(false); const openModal = (redirect:string) => { setIsModalOpen(true); @@ -92,18 +91,11 @@ export default function Home() {
setIsHoveringPublicChat(true)} - onMouseLeave={()=>setIsHoveringPublicChat(false)} - - onClick={() => window.open("/404", "_blank")} + onClick={goToPublicChat} > -

+

{"slack - {IsHoveringPublicChat ? "COMING SOON" : "PUBLIC MDG CHAT FORUM"} + PUBLIC MDG CHAT FORUM