Follow-up

This commit is contained in:
Alexander Zinchuk 2021-05-06 03:08:31 +03:00
parent b971b82406
commit dc2dfe2fff
6 changed files with 28 additions and 26 deletions

View File

@ -161,7 +161,7 @@ const ChatList: FC<OwnProps & StateProps & DispatchProps> = ({
onLoadMore={getMore}
preloadBackwards={CHAT_LIST_SLICE}
noFastList
isDisabled
noScrollRestore
>
{viewportIds && viewportIds.length && chatArrays ? (
renderChats()

View File

@ -146,7 +146,7 @@ const ForwardPicker: FC<OwnProps & StateProps & DispatchProps> = ({
className="picker-list custom-scroll"
items={viewportIds}
onLoadMore={getMore}
isDisabled={Boolean(filter)}
noScrollRestore={Boolean(filter)}
>
{viewportIds.map((id) => (
<ListItem

View File

@ -14,10 +14,15 @@ import {
MediaViewerOrigin, ProfileState, ProfileTabType, SharedMediaType,
} from '../../types';
import { MEMBERS_SLICE, SHARED_MEDIA_SLICE, SLIDE_TRANSITION_DURATION } from '../../config';
import {
MEMBERS_SLICE,
PROFILE_SENSITIVE_AREA,
SHARED_MEDIA_SLICE,
SLIDE_TRANSITION_DURATION,
} from '../../config';
import { IS_TOUCH_ENV } from '../../util/environment';
import {
isChatAdmin, isChatBasicGroup, isChatChannel, isChatGroup, isChatPrivate,
isChatAdmin, isChatChannel, isChatGroup, isChatPrivate,
} from '../../modules/helpers';
import {
selectChatMessages,
@ -57,7 +62,6 @@ type OwnProps = {
};
type StateProps = {
isBasicGroup?: boolean;
isChannel?: boolean;
resolvedUserId?: number;
chatMessages?: Record<number, ApiMessage>;
@ -90,7 +94,6 @@ const Profile: FC<OwnProps & StateProps & DispatchProps> = ({
chatId,
profileState,
onProfileStateChange,
isBasicGroup,
isChannel,
resolvedUserId,
chatMessages,
@ -307,11 +310,10 @@ const Profile: FC<OwnProps & StateProps & DispatchProps> = ({
ref={containerRef}
className="Profile custom-scroll"
itemSelector={buildInfiniteScrollItemSelector(resultType)}
items={viewportIds}
items={canRenderContents ? viewportIds : undefined}
cacheBuster={cacheBuster}
sensitiveArea={500}
preloadBackwards={resultType === 'members' ? MEMBERS_SLICE : SHARED_MEDIA_SLICE}
isDisabled={resultType === 'members' && isBasicGroup}
sensitiveArea={PROFILE_SENSITIVE_AREA}
preloadBackwards={canRenderContents ? (resultType === 'members' ? MEMBERS_SLICE : SHARED_MEDIA_SLICE) : 0}
noFastList
onLoadMore={getMore}
onScroll={handleScroll}
@ -370,7 +372,6 @@ export default memo(withGlobal<OwnProps>(
const { byId: usersById } = global.users;
const isGroup = chat && isChatGroup(chat);
const isBasicGroup = chat && isChatBasicGroup(chat);
const isChannel = chat && isChatChannel(chat);
const hasMembersTab = isGroup || (isChannel && isChatAdmin(chat!));
const members = chat && chat.fullInfo && chat.fullInfo.members;
@ -384,7 +385,6 @@ export default memo(withGlobal<OwnProps>(
}
return {
isBasicGroup,
isChannel,
resolvedUserId,
chatMessages,

View File

@ -17,7 +17,7 @@ type OwnProps = {
itemSelector?: string;
preloadBackwards?: number;
sensitiveArea?: number;
isDisabled?: boolean;
noScrollRestore?: boolean;
noFastList?: boolean;
cacheBuster?: any;
children: any;
@ -36,8 +36,8 @@ const InfiniteScroll: FC<OwnProps> = ({
itemSelector = DEFAULT_LIST_SELECTOR,
preloadBackwards = DEFAULT_PRELOAD_BACKWARDS,
sensitiveArea = DEFAULT_SENSITIVE_AREA,
// Used to turn off preloading and restoring scroll position (e.g. for frequently re-ordered chat or user lists)
isDisabled = false,
// Used to turn off restoring scroll position (e.g. for frequently re-ordered chat or user lists)
noScrollRestore = false,
noFastList,
// Used to re-query `listItemElements` if rendering is delayed by transition
cacheBuster,
@ -70,19 +70,20 @@ const InfiniteScroll: FC<OwnProps> = ({
// Initial preload
useEffect(() => {
if (isDisabled || !loadMoreBackwards) {
if (!loadMoreBackwards) {
return;
}
if (!items || items.length < preloadBackwards) {
if (preloadBackwards > 0 && (!items || items.length < preloadBackwards)) {
loadMoreBackwards();
} else {
const { scrollHeight, clientHeight } = containerRef.current!;
if (clientHeight && scrollHeight <= clientHeight) {
loadMoreBackwards();
}
return;
}
}, [isDisabled, items, loadMoreBackwards, preloadBackwards]);
const { scrollHeight, clientHeight } = containerRef.current!;
if (clientHeight && scrollHeight <= clientHeight) {
loadMoreBackwards();
}
}, [items, loadMoreBackwards, preloadBackwards]);
// Restore `scrollTop` after adding items
useLayoutEffect(() => {
@ -91,7 +92,7 @@ const InfiniteScroll: FC<OwnProps> = ({
state.listItemElements = container.querySelectorAll<HTMLDivElement>(itemSelector);
if (isDisabled) {
if (noScrollRestore) {
return;
}
@ -112,7 +113,7 @@ const InfiniteScroll: FC<OwnProps> = ({
resetScroll(container, newScrollTop);
state.isScrollTopJustUpdated = true;
}, [isDisabled, itemSelector, items, cacheBuster]);
}, [noScrollRestore, itemSelector, items, cacheBuster]);
const handleScroll = useCallback((e: UIEvent<HTMLDivElement>) => {
if (loadMoreForwards && loadMoreBackwards) {

View File

@ -58,6 +58,7 @@ export const MEMBERS_LOAD_SLICE = 200;
export const PINNED_MESSAGES_LIMIT = 50;
export const BLOCKED_LIST_LIMIT = 100;
export const PROFILE_PHOTOS_LIMIT = 40;
export const PROFILE_SENSITIVE_AREA = 500;
export const TOP_CHAT_MESSAGES_PRELOAD_LIMIT = 25;
export const ALL_CHATS_PRELOAD_DISABLED = false;

View File

@ -673,7 +673,7 @@ addReducer('loadMoreMembers', (global) => {
(async () => {
const { chatId } = selectCurrentMessageList(global) || {};
const chat = chatId ? selectChat(global, chatId) : undefined;
if (!chat) {
if (!chat || isChatBasicGroup(chat)) {
return;
}