diff --git a/src/app/chat/Channel.js b/src/app/chat/Channel.js index 1b704fd..c22d8a5 100644 --- a/src/app/chat/Channel.js +++ b/src/app/chat/Channel.js @@ -9,7 +9,6 @@ const Channel = ({ handleChannelSelect, isSelected = false, }) => { - console.log('c', participants); return (
{ return (
-
+

Channels

{list} diff --git a/src/app/chat/ChatHeader.js b/src/app/chat/ChatHeader.js new file mode 100644 index 0000000..99207a6 --- /dev/null +++ b/src/app/chat/ChatHeader.js @@ -0,0 +1,22 @@ +const ChatHeader = ({ channelName }) => { + const disabledStyles = + 'bg-gray-300 px-4 py-2 rounded-md cursor-not-allowed opacity-50'; + + return ( +
+

+ {channelName ?? 'Select channel'}{' '} +

+ +
+ ); +}; + +export default ChatHeader; diff --git a/src/app/chat/MessagesPanel.js b/src/app/chat/MessagesPanel.js index f5c307c..0d2a8ea 100644 --- a/src/app/chat/MessagesPanel.js +++ b/src/app/chat/MessagesPanel.js @@ -9,9 +9,6 @@ const MessagesPanel = ({ messages, currentUser, typingStatus }) => { return (
-
-

Chat

-
{messages.map((message) => diff --git a/src/app/chat/page.js b/src/app/chat/page.js index acece8b..d2e1d34 100644 --- a/src/app/chat/page.js +++ b/src/app/chat/page.js @@ -8,7 +8,8 @@ import socketIO from 'socket.io-client'; import Notification from '../components/Notification'; import { useAuthContext } from '../context/AuthContext'; import { db } from '../../database/firebase'; -import { onValue, ref, update } from 'firebase/database'; +import { onValue, ref, set } from 'firebase/database'; +import ChatHeader from './ChatHeader'; const SERVER = 'http://127.0.0.1:8081'; @@ -35,13 +36,7 @@ const Chat = () => { }, [socket, messages]); const handleChannelSelect = (channelId) => { - const participantRef = ref( - db, - `channels/${channelId}/participants/${currentUser.userName}`, - ); - - update(participantRef, { - name: currentUser.displayName, + set(ref(db, `channels/${channelId}/participants/` + currentUser.id), { username: currentUser.userName, }) .then(() => { @@ -92,6 +87,7 @@ const Chat = () => { selectedChannel={selectedChannel} />
+ { />
- {notifications.map(({ id }) => ( + {/* {notifications.map(({ id }) => ( deleteNotification(id)} key={id}> This is a notification! - ))} + ))} */}
); }; diff --git a/src/app/components/Modal.js b/src/app/components/Modal.js deleted file mode 100644 index a08fb3d..0000000 --- a/src/app/components/Modal.js +++ /dev/null @@ -1,101 +0,0 @@ -'use client'; - -import React, { useRef, useState } from 'react'; -import { useAuthContext } from '../context/AuthContext'; - -const FIELD_EMPTY = 'Field is empty'; - -const Modal = () => { - const [error, setError] = useState(null); - const [isLoginForm, setIsLoginForm] = useState(true); - const displayNameRef = useRef(''); - const userNameRef = useRef(''); - - const { handleAuth, registerUser, isOpen, closeModal } = useAuthContext(); - - if (!isOpen) return null; - - const onSubmit = (e) => { - e.preventDefault(); - - const displayName = displayNameRef?.current?.value; - const userName = userNameRef.current.value; - - if (userName) { - handleAuth(userName); - } else { - setError(FIELD_EMPTY); - } - - setIsLoginForm(false); - if (displayName && userName) { - registerUser({ - displayName, - userName, - }); - } else { - setError(FIELD_EMPTY); - } - }; - - return ( -
-
-
-
-
-

User Info

- -
-
- {!isLoginForm ? ( -
- - -
- ) : null} -
- - -
-
-
- {error ? ( - {error} - ) : null} - - -
-
-
-
-
- ); -}; - -export default Modal; diff --git a/src/app/context/AuthContext.js b/src/app/context/AuthContext.js index 12f2a9b..ccff9d5 100644 --- a/src/app/context/AuthContext.js +++ b/src/app/context/AuthContext.js @@ -1,4 +1,3 @@ -import useAuth from '../hooks/useAuth'; import { createContext, useMemo, useContext, useState } from 'react'; const AuthContext = createContext({}); diff --git a/src/app/hooks/useAuth.js b/src/app/hooks/useAuth.js deleted file mode 100644 index 86ecc61..0000000 --- a/src/app/hooks/useAuth.js +++ /dev/null @@ -1,37 +0,0 @@ -import { useEffect, useState } from 'react'; - -const useAuth = (onClose, setCurrentUser) => { - const [users, setUsers] = useState([]); - - useEffect(() => { - const users = localStorage.getItem('users'); - if (users) { - setUsers(JSON.parse(users)); - } - }, []); - - const handleAuth = (username) => { - const userExists = users.find((u) => u.userName === username); - - if (userExists) { - setCurrentUser(userExists); - onClose(); - } - }; - - const registerUser = (user) => { - const existingUsers = [...users]; - existingUsers.push(user); - setUsers(existingUsers); - localStorage.setItem('users', JSON.stringify(existingUsers)); - setCurrentUser(user); - onClose(); - }; - - return { - handleAuth, - registerUser, - }; -}; - -export default useAuth;