Fix-jump-latest-senstivity (#1440)
authorAjay Bura <32841439+ajbura@users.noreply.github.com>
Sat, 7 Oct 2023 13:09:43 +0000 (00:09 +1100)
committerGitHub <noreply@github.com>
Sat, 7 Oct 2023 13:09:43 +0000 (00:09 +1100)
* fix jump to latest sensitivity

* select mention space as tab

src/app/hooks/useVirtualPaginator.ts
src/app/organisms/room/RoomTimeline.tsx

index 550e11c032b7240f9ceabaea35702da74e9ba65c..9ffc7f914d96941f751d9ec502bc1bb75fe81741 100644 (file)
@@ -319,7 +319,7 @@ export const useVirtualPaginator = <TScrollElement extends HTMLElement>(
 
   const intersectionObserver = useIntersectionObserver(
     handlePaginatorElIntersection,
-    useMemo(
+    useCallback(
       () => ({
         root: getScrollElement(),
       }),
index c41bfbb81d1b9c9574375f3c9f20bff46f16aa9e..96555f3d7fa4cb5587bdf61b8592e704e7a2de98 100644 (file)
@@ -90,7 +90,7 @@ import {
   openJoinAlias,
   openProfileViewer,
   selectRoom,
-  selectSpace,
+  selectTab,
 } from '../../../client/action/navigation';
 import { useForceUpdate } from '../../hooks/useForceUpdate';
 import { parseGeoUri, scaleYDimension } from '../../utils/common';
@@ -115,7 +115,6 @@ import { useMemberEventParser } from '../../hooks/useMemberEventParser';
 import * as customHtmlCss from '../../styles/CustomHtml.css';
 import { RoomIntro } from '../../components/room-intro';
 import {
-  OnIntersectionCallback,
   getIntersectionObserverEntry,
   useIntersectionObserver,
 } from '../../hooks/useIntersectionObserver';
@@ -541,7 +540,7 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli
             return;
           }
           if (isRoomId(mentionId) && mx.getRoom(mentionId)) {
-            if (mx.getRoom(mentionId)?.isSpaceRoom()) selectSpace(mentionId);
+            if (mx.getRoom(mentionId)?.isSpaceRoom()) selectTab(mentionId);
             else selectRoom(mentionId);
             return;
           }
@@ -674,18 +673,24 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli
     useCallback(() => roomInputRef.current, [roomInputRef])
   );
 
-  const handleAtBottomIntersection: OnIntersectionCallback = useCallback((entries) => {
-    const target = atBottomAnchorRef.current;
-    if (!target) return;
-    const targetEntry = getIntersectionObserverEntry(target, entries);
-
-    setAtBottom(targetEntry?.isIntersecting === true);
-  }, []);
+  const debounceSetAtBottom = useDebounce(
+    useCallback((entry: IntersectionObserverEntry) => {
+      if (!entry.isIntersecting) setAtBottom(false);
+    }, []),
+    { wait: 1000 }
+  );
   useIntersectionObserver(
-    useDebounce(handleAtBottomIntersection, {
-      wait: 200,
-    }),
-    useMemo(
+    useCallback(
+      (entries) => {
+        const target = atBottomAnchorRef.current;
+        if (!target) return;
+        const targetEntry = getIntersectionObserverEntry(target, entries);
+        if (targetEntry) debounceSetAtBottom(targetEntry);
+        if (targetEntry?.isIntersecting) setAtBottom(true);
+      },
+      [debounceSetAtBottom]
+    ),
+    useCallback(
       () => ({
         root: getScrollElement(),
         rootMargin: '100px',