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