Skip to content

Commit

Permalink
fetchChats
Browse files Browse the repository at this point in the history
  • Loading branch information
Celesca committed Nov 25, 2024
1 parent 5afd12e commit 97aef86
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion frontend/src/message.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,40 @@
import { useState } from 'react';
import { useState, useEffect } from 'react';
import ChatList from './components/ChatList';
import ChatBox from './components/ChatBox';
import axios from 'axios';

const Message = () => {
const [activeChat, setActiveChat] = useState(null);
const [userID, setUserID] = useState(null);

const contacts = [
{ id: 1, name: 'John Doe', message: 'Hey! How are you?' },
{ id: 2, name: 'Jane Smith', message: 'Let’s catch up soon!' },
{ id: 3, name: 'Mark Taylor', message: 'Check this out.' },
];

const fetchChats = async () => {
try {
const response = await axios.get(`http://localhost:3000/message/inbox/${userID}`);
console.log(response.data[0]);
setActiveChat(response.data[0]);
} catch (error) {
console.error('Error fetching chats:', error);
}
};

fetchChats();

useEffect(() => {
const user = localStorage.getItem('UserID');
if (user) {
setUserID(user);
console.log(user);
}
}, [])



const handleChatSelect = (contact) => {
setActiveChat(contact);
};
Expand Down

0 comments on commit 97aef86

Please sign in to comment.