From 4cef87e2abda505b051006d7bea8c203fcd545a8 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Tue, 31 May 2022 20:58:55 +0400 Subject: [PATCH] Fix exceptions when signing out --- src/hooks/useFolderManager.ts | 22 ++++++++++++---------- src/hooks/useInfiniteScroll.ts | 2 ++ 2 files changed, 14 insertions(+), 10 deletions(-) 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(({