import type { FC } from '../../../lib/teact/teact'; import { memo, useCallback } from '../../../lib/teact/teact'; import { getActions, withGlobal } from '../../../global'; import type { ApiTopic } from '../../../api/types'; import { selectTopic } from '../../../global/selectors'; import { REM } from '../../common/helpers/mediaDimensions'; import renderText from '../../common/helpers/renderText'; import useSelectWithEnter from '../../../hooks/useSelectWithEnter'; import TopicIcon from '../../common/TopicIcon'; import ListItem from '../../ui/ListItem'; type OwnProps = { chatId: string; topicId: number; onClick: (id: number) => void; }; type StateProps = { topic?: ApiTopic; }; const TOPIC_ICON_SIZE = 2 * REM; const LeftSearchResultTopic: FC = ({ chatId, topicId, topic, onClick, }) => { const { openQuickPreview } = getActions(); const handleClick = useCallback((e: React.MouseEvent) => { if (e.altKey) { e.preventDefault(); openQuickPreview({ id: chatId, threadId: topicId }); return; } onClick(topicId); }, [chatId, topicId, onClick, openQuickPreview]); const buttonRef = useSelectWithEnter(() => onClick(topicId)); if (!topic) { return undefined; } return (
{renderText(topic.title)}
); }; export default memo(withGlobal( (global, { chatId, topicId }): Complete => { const topic = selectTopic(global, chatId, topicId); return { topic, }; }, )(LeftSearchResultTopic));