-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatContainer.js
More file actions
36 lines (27 loc) · 1.12 KB
/
ChatContainer.js
File metadata and controls
36 lines (27 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"use client";
import { useEffect, useState } from "react";
import Chat from "./Chat";
import { DEFAULT_IMAGE } from "./ChatUtilities";
import importedStyles from "./ChatContainer.module.css";
export default function ChatContainer(props) {
const chatConfiguration = props.chatConfiguration;
const chatHandler = props.chatHandler;
const chats = props.chats;
const defaultImage = props.defaultImage || DEFAULT_IMAGE;
const linkFactory = props.linkFactory;
const setChats = props.setChats;
const styles = props.styles || importedStyles;
const [chatsReversed, setChatsReversed] = useState([]);
useEffect(() => {
const newChats = [...chats];
const newChatsReversed = newChats.reverse();
setChatsReversed(newChatsReversed);
}, [chats]);
return (
<div className={styles.chat_container}>
{chatsReversed.map((chat, chatIndex) => (
<Chat chat={chat} chatConfiguration={chatConfiguration} chatHandler={chatHandler} chatIndex={chatIndex} chats={chats} defaultImage={defaultImage} key={chat.key || "chat-" + chatIndex} linkFactory={linkFactory} setChats={setChats} />
))}
</div>
);
}