Commit 8af1e1fa authored by Balasuriya D.A.M.'s avatar Balasuriya D.A.M.

Chats Page Side Drawer Frontend 1st step

parent 9c42371e
import React from "react"; import { Box } from "@chakra-ui/react";
import axios from "axios"; import { ChatState } from "../Context/ChatProvider";
import { useEffect, useState } from "react"; import SideDrawer from "../components/miscellaneous/SideDrawer";
import MyChats from "../components/MyChats";
import ChatBox from "../components/ChatBox";
const ChatPage = () => { const ChatPage = () => {
const [chats, setsChats] = useState([])
const fetchChats = async () => {
const { data } = await axios.get("/api/chat");
setsChats(data);
};
useEffect(() => {
fetchChats();
}, []);
const { user } = ChatState();
return ( return (
<div> <div style={{ width: "100%" }}>
{chats.map((chat) => ( {user && <SideDrawer/>}
<div key={chat._id}>{chat.chatName}</div>))} <Box
d="flex"
justifyContent="space-between"
w="100%"
h="91.5vh"
p="10px"
>
{user && <MyChats/>}
{user && <ChatBox/>}
</Box>
</div> </div>
); );
}
};
export default ChatPage export default ChatPage;
\ No newline at end of file \ No newline at end of file
...@@ -18,10 +18,10 @@ const Homepage = () => { ...@@ -18,10 +18,10 @@ const Homepage = () => {
const history = useHistory(); const history = useHistory();
useEffect(() => { useEffect(() => {
const user = JSON.parse(localStorage.getItem("userInfo")); const user = JSON.parse(localStorage.getItem("userInfo"));
//check if user is loged in //check if user is loged in push back to the chat page
if (user) history.push("/chats"); if (user) history.push("/chats");
...@@ -51,23 +51,23 @@ const Homepage = () => { ...@@ -51,23 +51,23 @@ const Homepage = () => {
borderWidth="1px" borderWidth="1px"
> >
<Tabs variant='soft-rounded' colorScheme='green'> <Tabs variant='soft-rounded' colorScheme='green'>
<TabList mb="1em"> <TabList mb="1em">
<Tab width="50%">Login</Tab> <Tab width="50%">Login</Tab>
<Tab width="50%">Sign Up</Tab> <Tab width="50%">Sign Up</Tab>
</TabList> </TabList>
<TabPanels> <TabPanels>
<TabPanel> <TabPanel>
<Login /> <Login />
</TabPanel> </TabPanel>
<TabPanel> <TabPanel>
<Signup /> <Signup />
</TabPanel> </TabPanel>
</TabPanels> </TabPanels>
</Tabs> </Tabs>
</Box> </Box>
</Container> </Container>
); );
} };
export default Homepage; export default Homepage;
\ No newline at end of file
import React from "react";
const ChatBox = () => {
return (
<div>ChatBox</div>
);
};
export default ChatBox;
\ No newline at end of file
import React from "react";
const MyChats = () => {
return (
<div>MyChats</div>
);
};
export default MyChats;
\ No newline at end of file
import React from "react";
const SideDrawer = () => {
return (
<div>SideDrawer</div>
);
};
export default SideDrawer;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment