From 4673052e0920c815769587275dddb3841aab264c Mon Sep 17 00:00:00 2001 From: Chris-1010 <122332721@umail.ucc.ie> Date: Tue, 18 Feb 2025 02:48:24 +0000 Subject: [PATCH] REFACTOR: Rename user_id to userId for consistency across components; --- frontend/src/App.tsx | 6 +++--- frontend/src/components/Video/ChatPanel.tsx | 8 ++++---- frontend/src/context/AuthContext.tsx | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index dd9592a..c485ba2 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -15,14 +15,14 @@ import { QuickSettingsProvider } from "./context/QuickSettingsContext"; function App() { const [isLoggedIn, setIsLoggedIn] = useState(false); - const [user_id, setUserID] = useState(null); + const [userId, setUserId] = useState(null); const [username, setUsername] = useState(null); useEffect(() => { fetch("/api/user/login_status") .then((response) => response.json()) .then((data) => { - setUserID(data.user_id); + setUserId(data.user_id); setIsLoggedIn(data.status); setUsername(data.username); }) @@ -34,7 +34,7 @@ function App() { return ( diff --git a/frontend/src/components/Video/ChatPanel.tsx b/frontend/src/components/Video/ChatPanel.tsx index b244346..60b2b08 100644 --- a/frontend/src/components/Video/ChatPanel.tsx +++ b/frontend/src/components/Video/ChatPanel.tsx @@ -22,7 +22,7 @@ const ChatPanel: React.FC = ({ streamId, onViewerCountChange, }) => { - const { isLoggedIn, username, user_id} = useAuth(); + const { isLoggedIn, username, userId} = useAuth(); const { showAuthModal, setShowAuthModal } = useAuthModal(); const { socket, isConnected } = useSocket(); const [messages, setMessages] = useState([]); @@ -35,7 +35,7 @@ const ChatPanel: React.FC = ({ if (socket && isConnected) { // Add username check socket.emit("join", { - user_id: user_id ? user_id : null, + userId: userId ? userId : null, username: username ? username : "Guest", stream_id: streamId, }); @@ -43,7 +43,7 @@ const ChatPanel: React.FC = ({ // Handle beforeunload event const handleBeforeUnload = () => { socket.emit("leave", { - user_id: user_id ? user_id : null, + userId: userId ? userId : null, username: username ? username : "Guest", stream_id: streamId, }); socket.disconnect(); @@ -85,7 +85,7 @@ const ChatPanel: React.FC = ({ socket.disconnect(); }; } - }, [socket, isConnected, user_id, username, streamId]); + }, [socket, isConnected, userId, username, streamId]); // Auto-scroll to bottom when new messages arrive useEffect(() => { diff --git a/frontend/src/context/AuthContext.tsx b/frontend/src/context/AuthContext.tsx index f7d296b..6315f3b 100644 --- a/frontend/src/context/AuthContext.tsx +++ b/frontend/src/context/AuthContext.tsx @@ -3,7 +3,7 @@ import { createContext, useContext } from "react"; interface AuthContextType { isLoggedIn: boolean; username: string | null; - user_id: number | null; + userId: number | null; setIsLoggedIn: (value: boolean) => void; setUsername: (value: string | null) => void; setUserId: (value: number | null) => void;