first commit
This commit is contained in:
35
Frontend/Electron/src/pages/Chat.jsx
Normal file
35
Frontend/Electron/src/pages/Chat.jsx
Normal file
@@ -0,0 +1,35 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import Sidebar from '../components/Sidebar';
|
||||
import ChatArea from '../components/ChatArea';
|
||||
|
||||
const Chat = () => {
|
||||
const [activeChannel, setActiveChannel] = useState(null);
|
||||
const [channels, setChannels] = useState([]);
|
||||
|
||||
useEffect(() => {
|
||||
fetch('http://localhost:3000/api/channels')
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
setChannels(data);
|
||||
if (data.length > 0 && !activeChannel) {
|
||||
setActiveChannel(data[0].id);
|
||||
}
|
||||
})
|
||||
.catch(err => console.error('Error fetching channels:', err));
|
||||
}, []);
|
||||
|
||||
if (!activeChannel) return <div style={{ color: 'white', padding: 20 }}>Loading...</div>;
|
||||
|
||||
return (
|
||||
<div className="app-container">
|
||||
<Sidebar
|
||||
channels={channels}
|
||||
activeChannel={activeChannel}
|
||||
onSelectChannel={setActiveChannel}
|
||||
/>
|
||||
<ChatArea channelId={activeChannel} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Chat;
|
||||
Reference in New Issue
Block a user