Skip to content

Commit

Permalink
add copying chat name by clicking on text
Browse files Browse the repository at this point in the history
  • Loading branch information
Lopkop committed Apr 1, 2024
1 parent 69ed469 commit 67295d4
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions frontend/src/routes/Chat.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,30 @@ export default function Chat() {

function handleKeyPress(event) {
if (event.key === 'Enter') {
event.preventDefault(); // Prevent default behavior of tabbing
// Trigger the click event of the "Send" button
event.preventDefault();
document.getElementById("sendButton").click();
}
}

function copyText() {
var textToCopy = document.getElementById('copyText').textContent;
navigator.clipboard.writeText(textToCopy).then(function() {
console.log('Text copied to clipboard: ' + textToCopy);
}, function(err) {
console.error('Unable to copy text: ', err);
});
}
return (
<div>
<div className="chat-container">
<header className="chat-header">
<h1>{chatname}</h1>
<div className="container" id="container">
<h1 onClick={copyText} className="chat-name" id="copyText">{chatname}</h1>
</div>
</header>
<div className="chat-messages" ref={messagesRef}></div>
<div className="chat-input">
<TextInput id="messageInput" labelText="Type a message" onKeyDown={handleKeyPress}/>
<TextInput id="messageInput" placeholder="Type a message" onKeyDown={handleKeyPress}/>
<Button id="sendButton" onClick={sendMessage}>Send</Button>
</div>
</div>
Expand Down

0 comments on commit 67295d4

Please sign in to comment.