Fix polls for unauthenticated users
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
dde588faa8
commit
f2b91a2231
2 changed files with 5 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||||
|
import SoapboxPropTypes from 'soapbox/utils/soapbox_prop_types';
|
||||||
import ImmutablePureComponent from 'react-immutable-pure-component';
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||||
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
|
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
@ -31,6 +32,7 @@ class Poll extends ImmutablePureComponent {
|
||||||
intl: PropTypes.object.isRequired,
|
intl: PropTypes.object.isRequired,
|
||||||
dispatch: PropTypes.func,
|
dispatch: PropTypes.func,
|
||||||
disabled: PropTypes.bool,
|
disabled: PropTypes.bool,
|
||||||
|
me: SoapboxPropTypes.me,
|
||||||
};
|
};
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
|
@ -138,7 +140,7 @@ class Poll extends ImmutablePureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { poll, intl } = this.props;
|
const { me, poll, intl } = this.props;
|
||||||
|
|
||||||
if (!poll) {
|
if (!poll) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -147,7 +149,7 @@ class Poll extends ImmutablePureComponent {
|
||||||
const timeRemaining = poll.get('expired') ? intl.formatMessage(messages.closed) : <RelativeTimestamp timestamp={poll.get('expires_at')} futureDate />;
|
const timeRemaining = poll.get('expired') ? intl.formatMessage(messages.closed) : <RelativeTimestamp timestamp={poll.get('expires_at')} futureDate />;
|
||||||
const showResults = poll.get('voted') || poll.get('expired');
|
const showResults = poll.get('voted') || poll.get('expired');
|
||||||
const disabled = this.props.disabled || Object.entries(this.state.selected).every(item => !item);
|
const disabled = this.props.disabled || Object.entries(this.state.selected).every(item => !item);
|
||||||
const voted = poll.get('own_votes').size > 0;
|
const voted = me && poll.get('own_votes', []).size > 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames('poll', { voted })}>
|
<div className={classNames('poll', { voted })}>
|
||||||
|
|
|
@ -3,6 +3,7 @@ import Poll from 'soapbox/components/poll';
|
||||||
|
|
||||||
const mapStateToProps = (state, { pollId }) => ({
|
const mapStateToProps = (state, { pollId }) => ({
|
||||||
poll: state.getIn(['polls', pollId]),
|
poll: state.getIn(['polls', pollId]),
|
||||||
|
me: state.get('me'),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(mapStateToProps)(Poll);
|
export default connect(mapStateToProps)(Poll);
|
||||||
|
|
Loading…
Reference in a new issue