Fix poll refresh button being incorrectly hidden (#34323)

This commit is contained in:
Claire 2025-03-31 10:21:02 +02:00 committed by GitHub
parent 70e14c1ed0
commit 33f3a4c4c8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,7 +7,6 @@ import classNames from 'classnames';
import { animated, useSpring } from '@react-spring/web';
import escapeTextContentForBrowser from 'escape-html';
import { debounce } from 'lodash';
import CheckIcon from '@/material-icons/400-24px/check.svg?react';
import { openModal } from 'mastodon/actions/modal';
@ -45,9 +44,7 @@ interface PollProps {
disabled?: boolean;
}
export const Poll: React.FC<PollProps> = (props) => {
const { pollId, status } = props;
export const Poll: React.FC<PollProps> = ({ pollId, disabled, status }) => {
// Third party hooks
const poll = useAppSelector((state) => state.polls[pollId]);
const identity = useIdentity();
@ -97,12 +94,12 @@ export const Poll: React.FC<PollProps> = (props) => {
);
}, [poll]);
const disabled =
props.disabled || Object.values(selected).every((item) => !item);
const voteDisabled =
disabled || Object.values(selected).every((item) => !item);
// Event handlers
const handleVote = useCallback(() => {
if (disabled) {
if (voteDisabled) {
return;
}
@ -120,7 +117,7 @@ export const Poll: React.FC<PollProps> = (props) => {
}),
);
}
}, [disabled, dispatch, identity, pollId, selected, status]);
}, [voteDisabled, dispatch, identity, pollId, selected, status]);
const handleReveal = useCallback(() => {
setRevealed(true);
@ -130,13 +127,7 @@ export const Poll: React.FC<PollProps> = (props) => {
if (disabled) {
return;
}
debounce(
() => {
void dispatch(fetchPoll({ pollId }));
},
1000,
{ leading: true },
);
void dispatch(fetchPoll({ pollId }));
}, [disabled, dispatch, pollId]);
const handleOptionChange = useCallback(
@ -181,7 +172,7 @@ export const Poll: React.FC<PollProps> = (props) => {
{!showResults && (
<button
className='button button-secondary'
disabled={disabled}
disabled={voteDisabled}
onClick={handleVote}
>
<FormattedMessage id='poll.vote' defaultMessage='Vote' />