Skip to content

Commit

Permalink
message menu on mobile: long press
Browse files Browse the repository at this point in the history
  • Loading branch information
roienatan committed Oct 18, 2023
1 parent 449066f commit 87bf7c6
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/shared/components/Chat/ChatMessage/ChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import React, {
useMemo,
} from "react";
import classNames from "classnames";
import { useLongPress } from "use-long-press";
import {
ElementDropdown,
UserAvatar,
Expand Down Expand Up @@ -224,12 +225,18 @@ export default function ChatMessage({
}
};

const handleMessageClick: MouseEventHandler<HTMLDivElement> = () => {
if (isTabletView) {
setIsMenuOpen(true);
}
const handleLongPress = () => {
setIsMenuOpen(true);
};

const getLongPressProps = useLongPress(
isTabletView ? handleLongPress : null,
{
threshold: 400,
cancelOnMovement: true,
},
);

const handleContextMenu: MouseEventHandler<HTMLLIElement> = (event) => {
if (!isTabletView) {
event.preventDefault();
Expand Down Expand Up @@ -387,7 +394,7 @@ export default function ChatMessage({
[styles.highlightedOwn]:
highlighted && !isNotCurrentUserMessage,
})}
onClick={handleMessageClick}
{...getLongPressProps()}
>
{isNotCurrentUserMessage && !isSystemMessage && (
<div className={styles.messageName} onClick={handleUserClick}>
Expand Down

0 comments on commit 87bf7c6

Please sign in to comment.