diff --git a/surfsense_web/components/layout/ui/sidebar/AllPrivateChatsSidebar.tsx b/surfsense_web/components/layout/ui/sidebar/AllPrivateChatsSidebar.tsx index 01cd5b556..28b259bdc 100644 --- a/surfsense_web/components/layout/ui/sidebar/AllPrivateChatsSidebar.tsx +++ b/surfsense_web/components/layout/ui/sidebar/AllPrivateChatsSidebar.tsx @@ -17,6 +17,7 @@ import { import { useParams, useRouter } from "next/navigation"; import { useTranslations } from "next-intl"; import { useCallback, useEffect, useMemo, useRef, useState } from "react"; +import { useLongPress } from "@/hooks/use-long-press"; import { toast } from "sonner"; import { Button } from "@/components/ui/button"; import { @@ -85,23 +86,14 @@ export function AllPrivateChatsSidebar({ const [isRenaming, setIsRenaming] = useState(false); const debouncedSearchQuery = useDebouncedValue(searchQuery, 300); - const longPressTimerRef = useRef | null>(null); - const longPressTriggeredRef = useRef(false); - - const handleLongPressStart = useCallback((threadId: number) => { - longPressTriggeredRef.current = false; - longPressTimerRef.current = setTimeout(() => { - longPressTriggeredRef.current = true; - setOpenDropdownId(threadId); - }, 500); - }, []); - - const handleLongPressCancel = useCallback(() => { - if (longPressTimerRef.current) { - clearTimeout(longPressTimerRef.current); - longPressTimerRef.current = null; - } - }, []); + const pendingThreadIdRef = useRef(null); + const { handlers: longPressHandlers, wasLongPress } = useLongPress( + useCallback(() => { + if (pendingThreadIdRef.current !== null) { + setOpenDropdownId(pendingThreadIdRef.current); + } + }, []) + ); const isSearchMode = !!debouncedSearchQuery.trim(); @@ -376,15 +368,15 @@ export function AllPrivateChatsSidebar({