Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/modules/emote_menu/components/EmoteMenu.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {autoUpdate, offset, useDismiss, useFloating, useInteractions} from '@floating-ui/react';
import {useDisclosure, useFocusTrap} from '@mantine/hooks';
import classNames from 'classnames';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import React, {useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState} from 'react';
import {ScrollbarSizeTargetContext} from '@/common/components/Scrollbar';
import useEmoteMenuViewStoreUpdated from '@/common/hooks/EmoteMenuViewStore';
import emoteMenuViewStore, {CategoryPositions} from '@/common/stores/emote-menu-view-store';
Expand Down Expand Up @@ -69,6 +69,7 @@ function EmoteMenu({
const gifContext = useGifPickerStore((state) => state.gifContext);
const width = useHorizontalResize({boundingQuerySelector, handleRef, open: opened, placement});
const emoteListRef = useRef(null);
const pendingScrollRowIndexRef = useRef(null);
const [emoteListCoords, setEmoteListCoords] = useState({x: 0, y: 0});
const [navigationMode, setNavigationMode] = useState(NavigationModeTypes.ARROW_KEYS);
const focusRef = useFocusTrap(opened && navigationMode === NavigationModeTypes.ARROW_KEYS);
Expand Down Expand Up @@ -141,6 +142,7 @@ function EmoteMenu({
const handleScrollToPendingRow = useCallback((pendingScrollRowIndex) => {
const listEl = emoteListRef.current;
if (listEl == null) {
pendingScrollRowIndexRef.current = pendingScrollRowIndex;
return;
}

Expand All @@ -153,6 +155,16 @@ function EmoteMenu({
listEl.scrollTo(0, scrollTop);
}, []);

useLayoutEffect(() => {
const pendingScrollRowIndex = pendingScrollRowIndexRef.current;
if (mode !== EmoteMenuModes.EMOTES || pendingScrollRowIndex == null) {
return;
}

pendingScrollRowIndexRef.current = null;
handleScrollToPendingRow(pendingScrollRowIndex);
}, [mode, handleScrollToPendingRow]);

const updateEmoteListData = useCallback((currentSearch = '') => {
let rows = emoteMenuViewStore.rows;

Expand Down
Loading