import ImmutablePureComponent from 'react-immutable-pure-component';
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
import classNames from 'classnames';
-import { vote, fetchPoll } from 'mastodon/actions/polls';
import Motion from 'mastodon/features/ui/util/optional_motion';
import spring from 'react-motion/lib/spring';
import escapeTextContentForBrowser from 'escape-html';
static propTypes = {
poll: ImmutablePropTypes.map,
intl: PropTypes.object.isRequired,
- dispatch: PropTypes.func,
disabled: PropTypes.bool,
+ refresh: PropTypes.func,
+ onVote: PropTypes.func,
};
state = {
return;
}
- this.props.dispatch(vote(this.props.poll.get('id'), Object.keys(this.state.selected)));
+ this.props.onVote(Object.keys(this.state.selected));
};
handleRefresh = () => {
return;
}
- this.props.dispatch(fetchPoll(this.props.poll.get('id')));
+ this.props.refresh();
};
renderOption (option, optionIndex, showResults) {
return (
<li key={option.get('title')}>
- {showResults && (
- <Motion defaultStyle={{ width: 0 }} style={{ width: spring(percent, { stiffness: 180, damping: 12 }) }}>
- {({ width }) =>
- <span className={classNames('poll__chart', { leading })} style={{ width: `${width}%` }} />
- }
- </Motion>
- )}
-
- <label className={classNames('poll__text', { selectable: !showResults })}>
+ <label className={classNames('poll__option', { selectable: !showResults })}>
<input
name='vote-options'
type={poll.get('multiple') ? 'checkbox' : 'radio'}
/>
)}
{showResults && <span className='poll__number'>
- {!!voted && <Icon id='check' className='poll__vote__mark' title={intl.formatMessage(messages.voted)} />}
{Math.round(percent)}%
</span>}
- <span dangerouslySetInnerHTML={{ __html: titleEmojified }} />
+ <span
+ className='poll__option__text translate'
+ dangerouslySetInnerHTML={{ __html: titleEmojified }}
+ />
+
+ {!!voted && <span className='poll__voted'>
+ <Icon id='check' className='poll__voted__mark' title={intl.formatMessage(messages.voted)} />
+ </span>}
</label>
+
+ {showResults && (
+ <Motion defaultStyle={{ width: 0 }} style={{ width: spring(percent, { stiffness: 180, damping: 12 }) }}>
+ {({ width }) =>
+ <span className={classNames('poll__chart', { leading })} style={{ width: `${width}%` }} />
+ }
+ </Motion>
+ )}
</li>
);
}