mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-20 17:11:17 -08:00
fix: make modals work again
This commit is contained in:
1 parent
f72eb6cfea
commit
b5eeae70bf
4 files changed
+69
-41
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import React, { useRef, useState } from 'react';
|
||||
import React, { useRef, useState, useEffect } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { Box } from 'folds';
|
||||
import * as css from '$features/room/message/styles.css';
|
||||
|
||||
@@ -19,6 +20,11 @@ export function MobileSwipeDownModal({ children, requestClose }: MobileSwipeDown
|
||||
const [touchYDiff, setTouchYDiff] = useState(0);
|
||||
const date = new Date();
|
||||
const startTime = useRef(0);
|
||||
const [mounted, setMounted] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setMounted(true);
|
||||
}, []);
|
||||
|
||||
const handleTouchStart = (e: React.TouchEvent) => {
|
||||
touchStartY.current = e.touches[0]?.clientY ?? null;
|
||||
@@ -58,7 +64,9 @@ export function MobileSwipeDownModal({ children, requestClose }: MobileSwipeDown
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
if (!mounted) return null;
|
||||
|
||||
return createPortal(
|
||||
<Box
|
||||
className={css.MessageMobileOptionsWrapped}
|
||||
data-gestures="ignore"
|
||||
@@ -77,6 +85,7 @@ export function MobileSwipeDownModal({ children, requestClose }: MobileSwipeDown
|
||||
>
|
||||
{children(dragHandleJSX, dragHandlers)}
|
||||
</Box>
|
||||
</Box>
|
||||
</Box>,
|
||||
document.body
|
||||
);
|
||||
}
|
||||
@@ -36,6 +36,7 @@ import { copyToClipboard } from '$utils/dom';
|
||||
import { markAsRead } from '$utils/notifications';
|
||||
import { UseStateProvider } from '$components/UseStateProvider';
|
||||
import { LeaveRoomPrompt } from '$components/leave-room-prompt';
|
||||
import { useMobileLongPress } from '$hooks/useMobileLongPress';
|
||||
import { useRoomTypingMember } from '$hooks/useRoomTypingMembers';
|
||||
import { TypingIndicator } from '$components/typing-indicator';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
@@ -350,18 +351,29 @@ export function RoomNavItem({
|
||||
|
||||
const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);
|
||||
|
||||
const { onTouchStart, onTouchEnd, onTouchMove, firedRef: longPressFiredRef } = useMobileLongPress(() => {
|
||||
setIsMobileMenuOpen(true);
|
||||
});
|
||||
|
||||
const handleContextMenu: MouseEventHandler<HTMLElement> = (evt) => {
|
||||
evt.preventDefault();
|
||||
if (isMobile) {
|
||||
if (longPressFiredRef.current) {
|
||||
evt.preventDefault();
|
||||
longPressFiredRef.current = false;
|
||||
return;
|
||||
}
|
||||
evt.preventDefault();
|
||||
setIsMobileMenuOpen(true);
|
||||
} else {
|
||||
setMenuAnchor({
|
||||
x: evt.clientX,
|
||||
y: evt.clientY,
|
||||
width: 0,
|
||||
height: 0,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
evt.preventDefault();
|
||||
setMenuAnchor({
|
||||
x: evt.clientX,
|
||||
y: evt.clientY,
|
||||
width: 0,
|
||||
height: 0,
|
||||
});
|
||||
};
|
||||
|
||||
const handleOpenMenu: MouseEventHandler<HTMLButtonElement> = (evt) => {
|
||||
@@ -437,6 +449,9 @@ export function RoomNavItem({
|
||||
userSelect: 'none',
|
||||
WebkitUserSelect: 'none',
|
||||
}}
|
||||
onTouchStart={onTouchStart}
|
||||
onTouchEnd={onTouchEnd}
|
||||
onTouchMove={onTouchMove}
|
||||
>
|
||||
<NavItem
|
||||
variant="Background"
|
||||
|
||||
@@ -121,36 +121,7 @@ export type MessageProps = {
|
||||
msc2723ForwardedMessageProps?: MSC2723ForwardedMessageProps;
|
||||
};
|
||||
|
||||
function useMobileLongPress(callback: () => void, delay = 500) {
|
||||
const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
const firedRef = useRef(false);
|
||||
|
||||
const clear = useCallback(() => {
|
||||
if (timerRef.current !== null) {
|
||||
clearTimeout(timerRef.current);
|
||||
timerRef.current = null;
|
||||
}
|
||||
}, []);
|
||||
|
||||
const onTouchStart = useCallback(() => {
|
||||
if (!mobileOrTablet()) return;
|
||||
firedRef.current = false;
|
||||
timerRef.current = setTimeout(() => {
|
||||
firedRef.current = true;
|
||||
callback();
|
||||
}, delay);
|
||||
}, [callback, delay]);
|
||||
|
||||
const onTouchEnd = useCallback(() => {
|
||||
clear();
|
||||
}, [clear]);
|
||||
|
||||
const onTouchMove = useCallback(() => {
|
||||
clear();
|
||||
}, [clear]);
|
||||
|
||||
return { onTouchStart, onTouchEnd, onTouchMove, firedRef };
|
||||
}
|
||||
import { useMobileLongPress } from '$hooks/useMobileLongPress';
|
||||
|
||||
const clamp = (str: string, len: number) => (str.length > len ? `${str.slice(0, len)}...` : str);
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { useRef, useCallback } 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 clear = useCallback(() => {
|
||||
if (timerRef.current !== null) {
|
||||
clearTimeout(timerRef.current);
|
||||
timerRef.current = null;
|
||||
}
|
||||
}, []);
|
||||
|
||||
const onTouchStart = useCallback(() => {
|
||||
if (!mobileOrTablet()) return;
|
||||
firedRef.current = false;
|
||||
timerRef.current = setTimeout(() => {
|
||||
firedRef.current = true;
|
||||
callback();
|
||||
}, delay);
|
||||
}, [callback, delay]);
|
||||
|
||||
const onTouchEnd = useCallback(() => {
|
||||
clear();
|
||||
}, [clear]);
|
||||
|
||||
const onTouchMove = useCallback(() => {
|
||||
clear();
|
||||
}, [clear]);
|
||||
|
||||
return { onTouchStart, onTouchEnd, onTouchMove, firedRef };
|
||||
}
|
||||
Reference in new issue
Block a user