Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
sankhadip-roy committed Jul 30, 2024
1 parent c715a44 commit 534e5cd
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
chat-app: chat room where useres can chat with each other in real time
chat-app: chat room where users can chat with each other in real time
2 changes: 1 addition & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>chat</title>
<title>Chat Room</title>
</head>

<body>
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/components/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export default function Login() {
// console.log(result) //log
if (result.data.stat === "Success") {
setUser(result.data.user);

// localStorage.setItem('user', JSON.stringify(user)); // locally storing the logged in user

navigate("/")
// console.log(user); //log
alert('login successful: ' + result.data.user) //using result.data.user instead of user because useRecoilState is a asyncronous function taking time in updating the user variable
Expand Down
30 changes: 18 additions & 12 deletions frontend/src/components/MessageRoom.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ export default function App() {
<div>
<NavbarSimple />
</div>
<div className="flex justify-around">
<div>

{/* {JSON.parse(localStorage.getItem('user'))} */}

<div className="flex justify-evenly">
<div className='p-3 w-72'>
<OnlineUsers />
</div>

Expand All @@ -87,23 +90,26 @@ export default function App() {
<Button onClick={sendMessage}>Send</Button>
</div>
</div>

</div>

<div className="p-5">
<h3 className="font-bold pb-2">Chat Room</h3>
<h3 className="font-bold pb-2">Messeges</h3>
<div className="rounded-md" style={{
border: '1px solid black',
padding: '10px'
}}>
{data_rcv.map((msg, i) => (
<div key={i}>
{i + 1}.&nbsp;
<span>[{formatDate(msg.createdTime)}]</span> &nbsp;
<span>{msg.username}</span> : &nbsp;
<span>{msg.message}</span>
</div>
))}
{
data_rcv.length === 0 ? (<div>Fetching ... </div>)
: (data_rcv.map((msg, i) => (
<div key={i}>
{i + 1}.&nbsp;
<span>[{formatDate(msg.createdTime)}]</span> &nbsp;
<span>{msg.username}</span> : &nbsp;
<span>{msg.message}</span>
</div>
))
)
}
</div>
</div>

Expand Down
11 changes: 9 additions & 2 deletions frontend/src/components/OnlineUsers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,20 @@ const OnlineUsers = React.memo(() => {

return (
<>
<div className="p-3 w-72">
<div>
<h3 className="font-bold pb-2">Online Users Socket Id [{Math.floor(onlineUsersList.length / 2)}]</h3>
<div className="rounded-md overflow-y-auto max-h-64" style={{
border: '1px solid black',
padding: '10px'
}}>
{memoizedUsers}
{
onlineUsersList.length === 0 ? (<div>Fetching ...</div>) :
(
<div>
{memoizedUsers}
</div>
)
}
</div>
</div>
</>
Expand Down

0 comments on commit 534e5cd

Please sign in to comment.