Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added send message by [ctrl+enter] key #337

Merged
merged 5 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion client/src/App.jsx
Dun-sin marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ function App() {
element={<ProtectedRoutes isLoggedIn={isLoggedIn} />}
>
<Route exact path="/" element={<Start />} />
{/* TODO: Sepreate searching and foundUser into different routes */}
{/* TODO: Sepreate searching
and foundUser into different routes */}
<Route exact path="/founduser" element={<Searching />} />
<Route exact path="/friends" element={<ComingSoon />} />
<Route exact path="/profile" element={<Profile />} />
Expand Down
15 changes: 15 additions & 0 deletions client/src/components/Chat.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable max-len */
import { useEffect, useRef, useContext, useMemo, useState } from 'react';
import { SocketContext } from 'context/Context';
import useKeyPress from 'src/hooks/useKeyPress';

import 'styles/chat.css';

Expand Down Expand Up @@ -265,6 +266,20 @@ const Chat = () => {
}
};

const handleSendWithCtrlEnter = (event) => {


if ((event.ctrlKey || event.metaKey) && event.key === 'Enter') {
event.preventDefault();
handleSubmit(event);
}
};

// Use the useKeyPress hook to listen for Ctrl + Enter keypress
useKeyPress(['Control', 'Meta', 'Enter'], handleSendWithCtrlEnter);



const handleResend = (id) => {
if (!messageExists(id)) {
return;
Expand Down
Loading