mirror of
https://github.com/glitch-soc/mastodon
synced 2025-04-24 20:04:51 +00:00
Fix poll refresh button being incorrectly hidden (#34323)
This commit is contained in:
parent
70e14c1ed0
commit
33f3a4c4c8
1 changed files with 7 additions and 16 deletions
|
@ -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' />
|
||||
|
|
Loading…
Add table
Reference in a new issue