import React, { FC, memo } from '../../lib/teact/teact'; import { withGlobal } from '../../lib/teact/teactn'; import { ApiMessage, ApiChat } from '../../api/types'; import { selectChat, selectChatMessage } from '../../modules/selectors'; import { buildCollectionByKey } from '../../util/iteratees'; import { getMessagePoll } from '../../modules/helpers'; import useLang from '../../hooks/useLang'; import PollAnswerResults from './PollAnswerResults'; import Loading from '../ui/Loading'; import './PollResults.scss'; type StateProps = { chat?: ApiChat; message?: ApiMessage; lastSyncTime?: number; }; const PollResults: FC = ({ chat, message, lastSyncTime, }) => { const lang = useLang(); if (!message || !chat) { return ; } const { summary, results } = getMessagePoll(message)!; if (!results.results) { return undefined; } const resultsByOption = buildCollectionByKey(results.results, 'option'); return (

{summary.question}

{lastSyncTime && summary.answers.map((answer) => ( ))} {!lastSyncTime && }
); }; export default memo(withGlobal( (global): StateProps => { const { pollResults: { chatId, messageId }, lastSyncTime, } = global; if (!chatId || !messageId) { return {}; } const chat = selectChat(global, chatId); const message = selectChatMessage(global, chatId, messageId); return { chat, message, lastSyncTime, }; }, )(PollResults));