diff --git a/src/components/middle/MobileSearch.tsx b/src/components/middle/MobileSearch.tsx index daf224057..d76773326 100644 --- a/src/components/middle/MobileSearch.tsx +++ b/src/components/middle/MobileSearch.tsx @@ -7,7 +7,12 @@ import { getActions, withGlobal } from '../../global'; import type { ApiChat } from '../../api/types'; import { debounce } from '../../util/schedulers'; -import { selectCurrentTextSearch, selectCurrentChat, selectTabState } from '../../global/selectors'; +import { + selectCurrentTextSearch, + selectCurrentChat, + selectTabState, + selectCurrentMessageList, +} from '../../global/selectors'; import { getDayStartAt } from '../../util/dateFormat'; import Button from '../ui/Button'; @@ -22,6 +27,7 @@ export type OwnProps = { type StateProps = { isActive?: boolean; chat?: ApiChat; + threadId?: number; query?: string; totalCount?: number; foundIds?: number[]; @@ -33,6 +39,7 @@ const runDebouncedForSearch = debounce((cb) => cb(), 200, false); const MobileSearchFooter: FC = ({ isActive, chat, + threadId, query, totalCount, foundIds, @@ -81,12 +88,12 @@ const MobileSearchFooter: FC = ({ // Focus message useEffect(() => { if (chat?.id && foundIds?.length) { - focusMessage({ chatId: chat.id, messageId: foundIds[0] }); + focusMessage({ chatId: chat.id, messageId: foundIds[0], threadId }); setFocusedIndex(0); } else { setFocusedIndex(-1); } - }, [chat?.id, focusMessage, foundIds]); + }, [chat?.id, focusMessage, foundIds, threadId]); // Disable native up/down buttons on iOS useEffect(() => { @@ -122,18 +129,18 @@ const MobileSearchFooter: FC = ({ const handleUp = useCallback(() => { if (chat && foundIds) { const newFocusIndex = focusedIndex + 1; - focusMessage({ chatId: chat.id, messageId: foundIds[newFocusIndex] }); + focusMessage({ chatId: chat.id, messageId: foundIds[newFocusIndex], threadId }); setFocusedIndex(newFocusIndex); } - }, [chat, focusedIndex, focusMessage, foundIds]); + }, [chat, foundIds, focusedIndex, threadId]); const handleDown = useCallback(() => { if (chat && foundIds) { const newFocusIndex = focusedIndex - 1; - focusMessage({ chatId: chat.id, messageId: foundIds[newFocusIndex] }); + focusMessage({ chatId: chat.id, messageId: foundIds[newFocusIndex], threadId }); setFocusedIndex(newFocusIndex); } - }, [chat, focusedIndex, focusMessage, foundIds]); + }, [chat, foundIds, focusedIndex, threadId]); const handleCloseLocalTextSearch = useCallback(() => { closeLocalTextSearch(); @@ -210,12 +217,14 @@ export default memo(withGlobal( } const { query, results } = selectCurrentTextSearch(global) || {}; + const { threadId } = selectCurrentMessageList(global) || {}; const { totalCount, foundIds } = results || {}; return { chat, query, totalCount, + threadId, foundIds, isHistoryCalendarOpen: Boolean(selectTabState(global).historyCalendarSelectedAt), };