mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-09 01:26:24 +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 && (
|
{!spoilerText && sensitive && !!mediaAttachments.length && (
|
||||||
<button
|
<button
|
||||||
class="plain spoiler"
|
class="plain spoiler"
|
||||||
|
@ -873,14 +881,9 @@ function Card({ card }) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Poll({ poll, readOnly }) {
|
function Poll({ poll, readOnly, onUpdate = () => {} }) {
|
||||||
const [pollSnapshot, setPollSnapshot] = useState(poll);
|
|
||||||
const [uiState, setUIState] = useState('default');
|
const [uiState, setUIState] = useState('default');
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setPollSnapshot(poll);
|
|
||||||
}, [poll]);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
expired,
|
expired,
|
||||||
expiresAt,
|
expiresAt,
|
||||||
|
@ -891,7 +894,7 @@ function Poll({ poll, readOnly }) {
|
||||||
voted,
|
voted,
|
||||||
votersCount,
|
votersCount,
|
||||||
votesCount,
|
votesCount,
|
||||||
} = pollSnapshot;
|
} = poll;
|
||||||
|
|
||||||
const expiresAtDate = !!expiresAt && new Date(expiresAt);
|
const expiresAtDate = !!expiresAt && new Date(expiresAt);
|
||||||
|
|
||||||
|
@ -953,7 +956,7 @@ function Poll({ poll, readOnly }) {
|
||||||
choices: votes,
|
choices: votes,
|
||||||
});
|
});
|
||||||
console.log(pollResponse);
|
console.log(pollResponse);
|
||||||
setPollSnapshot(pollResponse);
|
onUpdate(pollResponse);
|
||||||
setUIState('default');
|
setUIState('default');
|
||||||
}}
|
}}
|
||||||
style={{
|
style={{
|
||||||
|
|
Loading…
Reference in a new issue