-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathChatSidebar.tsx
More file actions
44 lines (40 loc) · 1.17 KB
/
ChatSidebar.tsx
File metadata and controls
44 lines (40 loc) · 1.17 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
37
38
39
40
41
42
43
44
import React, { useState, useEffect } from 'react';
import { XmtpClient, Message } from '@xmtp/xmtp-js';
const ChatSidebar = () => {
const [messages, setMessages] = useState<Message[]>([]);
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
const fetchMessages = async () => {
setIsLoading(true);
try {
const client = await XmtpClient.connect();
const conversation = await client.conversations.newConversation('recipientAddress');
const messages = await conversation.messages();
setMessages(messages);
} catch (error) {
console.error('Error fetching messages:', error);
} finally {
setIsLoading(false);
}
};
fetchMessages();
}, []);
return (
<div className="chat-sidebar">
<h2>Messages</h2>
{isLoading ? (
<div>Loading...</div>
) : (
<div className="message-list">
{messages.map((message, index) => (
<div key={index} className="message-item">
<p>{message.sender}</p>
<p>{message.text}</p>
</div>
))}
</div>
)}
</div>
);
};
export default ChatSidebar;