diff --git a/src/hooks/useFolderManager.ts b/src/hooks/useFolderManager.ts index 3d6b000a..435f73eb 100644 --- a/src/hooks/useFolderManager.ts +++ b/src/hooks/useFolderManager.ts @@ -1,4 +1,5 @@ -import { useEffect, useState } from '../lib/teact/teact'; +import { useEffect } from '../lib/teact/teact'; + import { getOrderedIds, getUnreadCounters, @@ -7,27 +8,28 @@ import { addUnreadCountersCallback, addChatsCountCallback, } from '../util/folderManager'; +import useForceUpdate from './useForceUpdate'; export function useFolderManagerForOrderedIds(folderId: number) { - const [orderedIds, setOrderedIds] = useState(getOrderedIds(folderId)); + const forceUpdate = useForceUpdate(); - useEffect(() => addOrderedIdsCallback(folderId, setOrderedIds), [folderId]); + useEffect(() => addOrderedIdsCallback(folderId, forceUpdate), [folderId, forceUpdate]); - return orderedIds; + return getOrderedIds(folderId); } export function useFolderManagerForUnreadCounters() { - const [unreadCounters, setUnreadCounters] = useState(getUnreadCounters()); + const forceUpdate = useForceUpdate(); - useEffect(() => addUnreadCountersCallback(setUnreadCounters), []); + useEffect(() => addUnreadCountersCallback(forceUpdate), [forceUpdate]); - return unreadCounters; + return getUnreadCounters(); } export function useFolderManagerForChatsCount() { - const [chatsCount, setChatsCount] = useState(getChatsCount()); + const forceUpdate = useForceUpdate(); - useEffect(() => addChatsCountCallback(setChatsCount), []); + useEffect(() => addChatsCountCallback(forceUpdate), [forceUpdate]); - return chatsCount; + return getChatsCount(); } diff --git a/src/hooks/useInfiniteScroll.ts b/src/hooks/useInfiniteScroll.ts index 1a0c5be6..200fe010 100644 --- a/src/hooks/useInfiniteScroll.ts +++ b/src/hooks/useInfiniteScroll.ts @@ -46,6 +46,8 @@ const useInfiniteScroll = ( if (!viewportIdsRef.current || !areSortedArraysEqual(viewportIdsRef.current, newViewportIds)) { viewportIdsRef.current = newViewportIds; } + } else if (!listIds) { + viewportIdsRef.current = undefined; } const getMore: GetMore = useCallback(({