Forum Panel: Fix blinking general topic when switching forums (#2815)
This commit is contained in:
parent
033422581b
commit
e86ee7bcdf
@ -25,7 +25,7 @@ import { useFolderManagerForOrderedIds } from '../../../hooks/useFolderManager';
|
||||
import { useIntersectionObserver } from '../../../hooks/useIntersectionObserver';
|
||||
import { useHotkeys } from '../../../hooks/useHotkeys';
|
||||
import useDebouncedCallback from '../../../hooks/useDebouncedCallback';
|
||||
import useChatOrderDiff from './hooks/useChatOrderDiff';
|
||||
import useOrderDiff from './hooks/useOrderDiff';
|
||||
|
||||
import InfiniteScroll from '../../ui/InfiniteScroll';
|
||||
import Loading from '../../ui/Loading';
|
||||
@ -78,7 +78,7 @@ const ChatList: FC<OwnProps> = ({
|
||||
const archiveHeight = shouldDisplayArchive
|
||||
? archiveSettings.isMinimized ? ARCHIVE_MINIMIZED_HEIGHT : CHAT_HEIGHT_PX : 0;
|
||||
|
||||
const { orderDiffById, getAnimationType } = useChatOrderDiff(orderedIds);
|
||||
const { orderDiffById, getAnimationType } = useOrderDiff(orderedIds);
|
||||
|
||||
const [viewportIds, getMore] = useInfiniteScroll(undefined, orderedIds, undefined, CHAT_LIST_SLICE);
|
||||
|
||||
|
||||
@ -23,7 +23,7 @@ import { captureEvents, SwipeDirection } from '../../../util/captureEvents';
|
||||
|
||||
import useInfiniteScroll from '../../../hooks/useInfiniteScroll';
|
||||
import { useIntersectionObserver, useOnIntersect } from '../../../hooks/useIntersectionObserver';
|
||||
import useChatOrderDiff from './hooks/useChatOrderDiff';
|
||||
import useOrderDiff from './hooks/useOrderDiff';
|
||||
import useLang from '../../../hooks/useLang';
|
||||
import usePrevious from '../../../hooks/usePrevious';
|
||||
import useHistoryBack from '../../../hooks/useHistoryBack';
|
||||
@ -119,7 +119,7 @@ const ForumPanel: FC<OwnProps & StateProps> = ({
|
||||
: [];
|
||||
}, [chat]);
|
||||
|
||||
const { orderDiffById, getAnimationType } = useChatOrderDiff(orderedIds);
|
||||
const { orderDiffById, getAnimationType } = useOrderDiff(orderedIds, chat?.id);
|
||||
|
||||
const [viewportIds, getMore] = useInfiniteScroll(() => {
|
||||
if (!chat || !lastSyncTime) return;
|
||||
|
||||
@ -3,7 +3,7 @@ import usePrevious from '../../../../hooks/usePrevious';
|
||||
import { mapValues } from '../../../../util/iteratees';
|
||||
import { useChatAnimationType } from './useChatAnimationType';
|
||||
|
||||
export default function useChatOrderDiff(orderedIds: (string | number)[] | undefined) {
|
||||
export default function useOrderDiff(orderedIds: (string | number)[] | undefined, key?: string) {
|
||||
const orderById = useMemo(() => {
|
||||
if (!orderedIds) {
|
||||
return undefined;
|
||||
@ -16,16 +16,17 @@ export default function useChatOrderDiff(orderedIds: (string | number)[] | undef
|
||||
}, [orderedIds]);
|
||||
|
||||
const prevOrderById = usePrevious(orderById);
|
||||
const prevChatId = usePrevious(key);
|
||||
|
||||
const orderDiffById = useMemo(() => {
|
||||
if (!orderById || !prevOrderById) {
|
||||
if (!orderById || !prevOrderById || key !== prevChatId) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return mapValues(orderById, (order, id) => {
|
||||
return prevOrderById[id] !== undefined ? order - prevOrderById[id] : -Infinity;
|
||||
});
|
||||
}, [orderById, prevOrderById]);
|
||||
}, [key, orderById, prevChatId, prevOrderById]);
|
||||
|
||||
const getAnimationType = useChatAnimationType(orderDiffById);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user