From f2b91a22318e2b66d4071b3cc0f2d094fbe9d16f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Sun, 24 Oct 2021 14:03:42 +0200 Subject: [PATCH] Fix polls for unauthenticated users MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- app/soapbox/components/poll.js | 6 ++++-- app/soapbox/containers/poll_container.js | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/soapbox/components/poll.js b/app/soapbox/components/poll.js index 866182ca4..3c89e253b 100644 --- a/app/soapbox/components/poll.js +++ b/app/soapbox/components/poll.js @@ -1,6 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import ImmutablePropTypes from 'react-immutable-proptypes'; +import SoapboxPropTypes from 'soapbox/utils/soapbox_prop_types'; import ImmutablePureComponent from 'react-immutable-pure-component'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; import classNames from 'classnames'; @@ -31,6 +32,7 @@ class Poll extends ImmutablePureComponent { intl: PropTypes.object.isRequired, dispatch: PropTypes.func, disabled: PropTypes.bool, + me: SoapboxPropTypes.me, }; state = { @@ -138,7 +140,7 @@ class Poll extends ImmutablePureComponent { } render() { - const { poll, intl } = this.props; + const { me, poll, intl } = this.props; if (!poll) { return null; @@ -147,7 +149,7 @@ class Poll extends ImmutablePureComponent { const timeRemaining = poll.get('expired') ? intl.formatMessage(messages.closed) : ; const showResults = poll.get('voted') || poll.get('expired'); 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 (
diff --git a/app/soapbox/containers/poll_container.js b/app/soapbox/containers/poll_container.js index a4a0a6247..dc35964f5 100644 --- a/app/soapbox/containers/poll_container.js +++ b/app/soapbox/containers/poll_container.js @@ -3,6 +3,7 @@ import Poll from 'soapbox/components/poll'; const mapStateToProps = (state, { pollId }) => ({ poll: state.getIn(['polls', pollId]), + me: state.get('me'), }); export default connect(mapStateToProps)(Poll);