-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from advanced-computer-lab-2023/chat-ui-impro…
…vement add dragabble chat button
- Loading branch information
Showing
14 changed files
with
869 additions
and
131 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.