import type { FC } from '../../lib/teact/teact'; import React, { memo, useRef, useCallback } from '../../lib/teact/teact'; import { CHAT_HEIGHT_PX } from '../../config'; import useInfiniteScroll from '../../hooks/useInfiniteScroll'; import useLang from '../../hooks/useLang'; import useKeyboardListNavigation from '../../hooks/useKeyboardListNavigation'; import useInputFocusOnOpen from '../../hooks/useInputFocusOnOpen'; import { isUserId } from '../../global/helpers'; import Loading from '../ui/Loading'; import Modal from '../ui/Modal'; import InputText from '../ui/InputText'; import Button from '../ui/Button'; import InfiniteScroll from '../ui/InfiniteScroll'; import ListItem from '../ui/ListItem'; import GroupChatInfo from './GroupChatInfo'; import PrivateChatInfo from './PrivateChatInfo'; import './ChatOrUserPicker.scss'; export type OwnProps = { currentUserId?: string; chatOrUserIds: string[]; isOpen: boolean; searchPlaceholder: string; search: string; loadMore?: NoneToVoidFunction; onSearchChange: (search: string) => void; onSelectChatOrUser: (chatOrUserId: string) => void; onClose: NoneToVoidFunction; onCloseAnimationEnd?: NoneToVoidFunction; }; const ChatOrUserPicker: FC = ({ isOpen, currentUserId, chatOrUserIds, search, searchPlaceholder, loadMore, onSearchChange, onSelectChatOrUser, onClose, onCloseAnimationEnd, }) => { const lang = useLang(); const [viewportIds, getMore] = useInfiniteScroll(loadMore, chatOrUserIds, Boolean(search)); // eslint-disable-next-line no-null/no-null const searchRef = useRef(null); const resetSearch = useCallback(() => { onSearchChange(''); }, [onSearchChange]); useInputFocusOnOpen(searchRef, isOpen, resetSearch); // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); const handleSearchChange = useCallback((e: React.ChangeEvent) => { onSearchChange(e.currentTarget.value); }, [onSearchChange]); const handleKeyDown = useKeyboardListNavigation(containerRef, isOpen, (index) => { if (viewportIds && viewportIds.length > 0) { onSelectChatOrUser(viewportIds[index === -1 ? 0 : index]); } }, '.ListItem-button', true); const modalHeader = (
); const viewportOffset = chatOrUserIds!.indexOf(viewportIds![0]); return ( {viewportIds?.length ? ( {viewportIds.map((id, i) => ( onSelectChatOrUser(id)} > {isUserId(id) ? ( ) : ( )} ))} ) : viewportIds && !viewportIds.length ? (

{lang('lng_blocked_list_not_found')}

) : ( )}
); }; export default memo(ChatOrUserPicker);