diff --git a/src/components/status.jsx b/src/components/status.jsx index 7001db05..28f75ced 100644 --- a/src/components/status.jsx +++ b/src/components/status.jsx @@ -359,7 +359,15 @@ function Status({ }), }} /> - {!!poll && <Poll poll={poll} readOnly={readOnly} />} + {!!poll && ( + <Poll + poll={poll} + readOnly={readOnly} + onUpdate={(newPoll) => { + states.statuses.get(id).poll = newPoll; + }} + /> + )} {!spoilerText && sensitive && !!mediaAttachments.length && ( <button class="plain spoiler" @@ -873,14 +881,9 @@ function Card({ card }) { } } -function Poll({ poll, readOnly }) { - const [pollSnapshot, setPollSnapshot] = useState(poll); +function Poll({ poll, readOnly, onUpdate = () => {} }) { const [uiState, setUIState] = useState('default'); - useEffect(() => { - setPollSnapshot(poll); - }, [poll]); - const { expired, expiresAt, @@ -891,7 +894,7 @@ function Poll({ poll, readOnly }) { voted, votersCount, votesCount, - } = pollSnapshot; + } = poll; const expiresAtDate = !!expiresAt && new Date(expiresAt); @@ -953,7 +956,7 @@ function Poll({ poll, readOnly }) { choices: votes, }); console.log(pollResponse); - setPollSnapshot(pollResponse); + onUpdate(pollResponse); setUIState('default'); }} style={{