mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-02 14:16:39 +01:00
Update poll reactively
This commit is contained in:
parent
3b6f0f277e
commit
23745d0683
1 changed files with 12 additions and 9 deletions
|
@ -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={{
|
||||
|
|
Loading…
Reference in a new issue