Skip to content

Commit

Permalink
Merge pull request #124 from advanced-computer-lab-2023/chat-ui-impro…
Browse files Browse the repository at this point in the history
…vement

add dragabble chat button
  • Loading branch information
YehiaFarghaly authored Dec 17, 2023
2 parents 96370b5 + b7576a7 commit 299696e
Show file tree
Hide file tree
Showing 14 changed files with 869 additions and 131 deletions.
109 changes: 109 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
"react-apexcharts": "^1.4.0",
"react-copy-to-clipboard": "^5.1.0",
"react-device-detect": "^2.2.2",
"react-dnd": "^16.0.1",
"react-dnd-html5-backend": "^16.0.1",
"react-dom": "^18.2.0",
"react-perfect-scrollbar": "^1.5.8",
"react-redux": "^8.0.2",
Expand Down
5 changes: 4 additions & 1 deletion client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import { LocalizationProvider } from '@mui/x-date-pickers';
import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
import Loader from 'ui-component/Loader';
import { authenticationAxios } from './utils/AxiosConfig';

import { DndProvider } from 'react-dnd';
import { HTML5Backend } from 'react-dnd-html5-backend';


// ==============================|| APP ||============================== //
Expand Down Expand Up @@ -58,13 +59,15 @@ const App = () => {
}, []);

return (
<DndProvider backend={HTML5Backend}>
<ThemeProvider theme={themes(customization)}>
<CssBaseline />
<LocalizationProvider dateAdapter={AdapterDateFns}>
{isLoading && <Loader />}
{!isLoading && <Routes />}
</LocalizationProvider>
</ThemeProvider>
</DndProvider>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,6 @@ const pages = {
url: '/doctor/pages/add-available-slots',
target: false,
},
{
id: 'chat',
title: 'Chat',
type: 'item',
icon: icons.ChatIcon,
url: '/doctor/pages/chat',
target: false,
},
],
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,7 @@ const pages = {
icon: icons.IconStethoscope,
url: '/patient/pages/doctors',
target: false,
},
{
id: 'chat',
title: 'Chat',
type: 'item',
icon: icons.ChatIcon,
url: '/patient/pages/chat',
target: false,
},
}
],
};

Expand Down
22 changes: 15 additions & 7 deletions client/src/layout/MainLayout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {

import Header from './Header';
import Sidebar from './Sidebar';
import Chat from '../../pages/chat/Chat';
// import Customization from '../Customization';

import { drawerWidth } from 'store/constant';
Expand Down Expand Up @@ -66,6 +67,7 @@ const Main = styled('main', { shouldForwardProp: (prop) => prop !== 'open' })(
// ==============================|| MAIN LAYOUT ||============================== //

const MainLayout = ({ userType }) => {
Outlet;
const theme = useTheme();
const matchDownMd = useMediaQuery(theme.breakpoints.down('md'));
const navigate = useNavigate();
Expand Down Expand Up @@ -138,13 +140,19 @@ const MainLayout = ({ userType }) => {
/>
)}

{/* main content */}
<Main theme={theme} open={leftDrawerOpened}>
{(!user || user.type != userType) && (
<h1>not autherized!!</h1>
)}
{user && user.type == userType && <Outlet />}
</Main>
{/* main content */}
<Main theme={theme} open={leftDrawerOpened} sx={{ position: 'relative' }}>
{(!user || user.type != userType) && (
<h1>not autherized!!</h1>
)}
{user && user.type == userType &&
<Chat>
<div>
<Outlet />
</div>
</Chat>
}
</Main>

{/* <Customization /> */}
</Box>
Expand Down
84 changes: 66 additions & 18 deletions client/src/pages/chat/Chat.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,69 @@
import ChatBox from './ChatBox';
import ChatList from './ChatList';
import { Card } from '@mui/material';

const Chat = () => {

return (
<Card
sx={{
backgroundColor: 'transparent',
display: 'flex',
justifyContent: 'space-between',
height: '100%',
}}>
<ChatBox></ChatBox>
<ChatList></ChatList>
</Card>
);
import { Container } from '@mui/system';
import ChatCard from './ChatCard';
import DraggableChatButton from './DraggableChatButton';
import React, { useState } from 'react';
import { useDrop } from 'react-dnd';

const Chat = ({ children }) => {
const [isChatOpen, setChatOpen] = useState(false);
const [position, setPosition] = useState({
left: window.innerWidth - window.innerWidth * 0.25,
top: window.innerHeight - window.innerHeight * 0.22,
});

const handleDrop = (delta) => {
const maxLeft = window.innerWidth - window.innerWidth * 0.25;
const maxTop = window.innerHeight - window.innerHeight * 0.22;

const newLeft = Math.min(Math.max(position.left + delta.x, 0), maxLeft);
const newTop = Math.min(Math.max(position.top + delta.y, 0), maxTop);

setPosition({
left: newLeft,
top: newTop,
});
};

const [, drop] = useDrop({
accept: 'CHAT_BUTTON',
drop: (item, monitor) => {
const delta = monitor.getDifferenceFromInitialOffset();
if (delta) {
handleDrop(delta);
}
},
});

const containerStyle = {
display: 'flex',
justifyContent: 'space-between',
width: '100%',
height: '100%',
position: 'absolute',
left: '50%',
top: '50%',
transform: 'translate(-50%, -50%)', // Center the container
padding: 3,
};

const childrenWithStyles = React.Children.map(children, (child) => {
return React.cloneElement(child, {
style: {
...child.props.style,
pointerEvents: isChatOpen ? 'none' : 'auto',
opacity: isChatOpen ? 0.5: 1,
width: isChatOpen ? '70%' : '100%',
},
});
});

return (
<Container ref={drop} sx={containerStyle}>
<DraggableChatButton isChatOpen={isChatOpen} position={position} setChatOpen={setChatOpen} />
{childrenWithStyles}
{isChatOpen && <ChatCard setChatOpen= {setChatOpen}/>}
</Container>
);
};

export default Chat;
Loading

0 comments on commit 299696e

Please sign in to comment.