mirror of
https://github.com/SableClient/Sable.git
synced 2026-12-01 22:32:32 -08:00
add visual indication when pressing on message
This commit is contained in:
1 parent
b5eeae70bf
commit
4f77d641be
3 files changed
+16
-5
No files matched your search
@@ -351,7 +351,13 @@ export function RoomNavItem({
|
||||
|
||||
const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);
|
||||
|
||||
const { onTouchStart, onTouchEnd, onTouchMove, firedRef: longPressFiredRef } = useMobileLongPress(() => {
|
||||
const {
|
||||
onTouchStart,
|
||||
onTouchEnd,
|
||||
onTouchMove,
|
||||
firedRef: longPressFiredRef,
|
||||
isPressing,
|
||||
} = useMobileLongPress(() => {
|
||||
setIsMobileMenuOpen(true);
|
||||
});
|
||||
|
||||
@@ -458,7 +464,7 @@ export function RoomNavItem({
|
||||
radii="400"
|
||||
highlight={shouldShowUnreadIndicator}
|
||||
aria-selected={selected}
|
||||
data-hover={!!menuAnchor}
|
||||
data-hover={!!menuAnchor || isPressing || isMobileMenuOpen}
|
||||
onContextMenu={handleContextMenu}
|
||||
{...hoverProps}
|
||||
{...focusWithinProps}
|
||||
|
||||
@@ -838,6 +838,7 @@ function MessageInternal(
|
||||
onTouchEnd,
|
||||
onTouchMove,
|
||||
firedRef: longPressFiredRef,
|
||||
isPressing,
|
||||
} = useMobileLongPress(() => {
|
||||
if (!edit) openMobileOptions();
|
||||
});
|
||||
@@ -898,7 +899,7 @@ function MessageInternal(
|
||||
collapse={collapse}
|
||||
highlight={highlight}
|
||||
notifyHighlight={highlightMentions ? notifyHighlight : undefined}
|
||||
selected={!!menuAnchor || isEmoji}
|
||||
selected={!!menuAnchor || isEmoji || isPressing}
|
||||
isMarked={isMarked}
|
||||
mobile={mobileOrTablet()}
|
||||
{...props}
|
||||
|
||||
@@ -1,22 +1,26 @@
|
||||
import { useRef, useCallback } from 'react';
|
||||
import { useRef, useCallback, useState } from 'react';
|
||||
import { mobileOrTablet } from '$utils/user-agent';
|
||||
|
||||
export function useMobileLongPress(callback: () => void, delay = 500) {
|
||||
const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
const firedRef = useRef(false);
|
||||
const [isPressing, setIsPressing] = useState(false);
|
||||
|
||||
const clear = useCallback(() => {
|
||||
if (timerRef.current !== null) {
|
||||
clearTimeout(timerRef.current);
|
||||
timerRef.current = null;
|
||||
}
|
||||
setIsPressing(false);
|
||||
}, []);
|
||||
|
||||
const onTouchStart = useCallback(() => {
|
||||
if (!mobileOrTablet()) return;
|
||||
firedRef.current = false;
|
||||
setIsPressing(true);
|
||||
timerRef.current = setTimeout(() => {
|
||||
firedRef.current = true;
|
||||
setIsPressing(false);
|
||||
callback();
|
||||
}, delay);
|
||||
}, [callback, delay]);
|
||||
@@ -29,5 +33,5 @@ export function useMobileLongPress(callback: () => void, delay = 500) {
|
||||
clear();
|
||||
}, [clear]);
|
||||
|
||||
return { onTouchStart, onTouchEnd, onTouchMove, firedRef };
|
||||
return { onTouchStart, onTouchEnd, onTouchMove, firedRef, isPressing };
|
||||
}
|
||||
Reference in new issue
Block a user