2022-06-12 07:14:46 -07:00
|
|
|
import classNames from 'classnames';
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import { Poll as PollEntity, PollOption as PollOptionEntity } from 'soapbox/types/entities';
|
|
|
|
|
|
|
|
interface IPollPreview {
|
|
|
|
poll: PollEntity,
|
|
|
|
}
|
|
|
|
|
|
|
|
const PollPreview: React.FC<IPollPreview> = ({ poll }) => {
|
|
|
|
const renderOption = (option: PollOptionEntity, index: number) => {
|
|
|
|
const showResults = poll.voted || poll.expired;
|
|
|
|
|
|
|
|
return (
|
2022-06-16 04:56:16 -07:00
|
|
|
<li key={index}>
|
|
|
|
<label className={classNames('poll__text', { selectable: !showResults })}>
|
|
|
|
<input
|
|
|
|
name='vote-options'
|
|
|
|
type={poll.multiple ? 'checkbox' : 'radio'}
|
|
|
|
disabled
|
|
|
|
/>
|
|
|
|
|
|
|
|
<span className={classNames('poll__input', { checkbox: poll.multiple })} />
|
|
|
|
|
|
|
|
<span dangerouslySetInnerHTML={{ __html: option.title_emojified }} />
|
|
|
|
</label>
|
|
|
|
</li>
|
2022-06-12 07:14:46 -07:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!poll) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2022-06-16 04:56:16 -07:00
|
|
|
<div className='poll'>
|
|
|
|
<ul>
|
|
|
|
{poll.options.map((option, i) => renderOption(option, i))}
|
|
|
|
</ul>
|
|
|
|
</div>
|
2022-06-12 07:14:46 -07:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default PollPreview;
|