-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c868fa6
commit 1d1821e
Showing
5 changed files
with
226 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Avatar, Tooltip } from "@chakra-ui/react"; | ||
import React from "react"; | ||
import { | ||
isLastMessage, | ||
isSameSender, | ||
isSameSenderMargin, | ||
isSameUser, | ||
} from "../config/ChatLogics"; | ||
import { ChatState } from "../Context/ChatProvider"; | ||
|
||
const ScrollableChat = ({ messages }) => { | ||
const { user } = ChatState(); | ||
|
||
return ( | ||
<div style={{ overflowX: "hidden", overflowY: "auto" }}> | ||
{messages && | ||
messages.map((m, i) => ( | ||
<div style={{ display: "flex" }} key={m._id}> | ||
{(isSameSender(messages, m, i, user._id) || | ||
isLastMessage(messages, i, user._id)) && ( | ||
<Tooltip label={m.sender.name} placement="bottom-start" hasArrow> | ||
<Avatar | ||
mt="7px" | ||
mr={1} | ||
size="sm" | ||
cursor="pointer" | ||
name={m.sender.name} | ||
src={m.sender.pic} | ||
/> | ||
</Tooltip> | ||
)} | ||
|
||
<span | ||
style={{ | ||
backgroundColor: `${ | ||
m.sender._id === user._id ? "#BEE3F8" : "#20f099b7" | ||
}`, | ||
borderRadius: "20px", | ||
padding: "5px 15px", | ||
maxWidth: "75%", | ||
marginLeft: isSameSenderMargin(messages, m, i, user._id), | ||
marginTop: isSameUser(messages, m, i) ? 3 : 10, | ||
}} | ||
> | ||
{m.content} | ||
</span> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export default ScrollableChat; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.messages{ | ||
display: flex; | ||
flex-direction: column; | ||
overflow-y: scroll; | ||
scrollbar-width: none; | ||
/* background-color: #20f099b7; */ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters