stream-chat-react
Version:
React components to create chat conversations or livestream style chat
19 lines (18 loc) • 1.31 kB
JavaScript
import React from 'react';
import { useStateStore } from '../../../../store';
import { usePollContext, useTranslationContext } from '../../../../context';
const pollStateSelector = (nextValue) => ({
maxVotedOptionIds: nextValue.maxVotedOptionIds,
vote_counts_by_option: nextValue.vote_counts_by_option,
});
export const PollResultOptionVoteCounter = ({ optionId, }) => {
const { t } = useTranslationContext();
const { poll } = usePollContext();
const { maxVotedOptionIds, vote_counts_by_option } = useStateStore(poll.state, pollStateSelector);
return (React.createElement("div", { className: 'str-chat__poll-result-option-vote-counter' },
maxVotedOptionIds.length === 1 && maxVotedOptionIds[0] === optionId && (React.createElement("div", { className: 'str-chat__poll-result-winning-option-icon' })),
React.createElement("span", { className: 'str-chat__poll-result-option-vote-count' }, t('{{count}} votes', { count: vote_counts_by_option[optionId] ?? 0 }))));
};
export const PollOptionWithVotesHeader = ({ option }) => (React.createElement("div", { className: 'str-chat__poll-option__header' },
React.createElement("div", { className: 'str-chat__poll-option__option-text' }, option.text),
React.createElement(PollResultOptionVoteCounter, { optionId: option.id })));