From a28e62d1d10e5acb9480ddecf7ef1e6aa57c33ce Mon Sep 17 00:00:00 2001 From: KaustubhKumar05 Date: Tue, 21 May 2024 11:24:33 +0530 Subject: [PATCH] fix: update store on response --- .../HMSInteractivityCenter.ts | 1 + .../Prebuilt/components/Polls/Voting/Voting.tsx | 16 ++++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/hms-video-store/src/session-store/interactivity-center/HMSInteractivityCenter.ts b/packages/hms-video-store/src/session-store/interactivity-center/HMSInteractivityCenter.ts index fc4c35c1f9..20caa323ba 100644 --- a/packages/hms-video-store/src/session-store/interactivity-center/HMSInteractivityCenter.ts +++ b/packages/hms-video-store/src/session-store/interactivity-center/HMSInteractivityCenter.ts @@ -194,6 +194,7 @@ export class InteractivityCenter implements HMSInteractivityCenter { } }); this.store.setPoll(pollCopy); + this.listener?.onPollsUpdate(HMSPollsUpdate.POLL_STATS_UPDATED, [pollCopy]); } async getPolls(): Promise { const launchedPollsList = await this.transport.signal.getPollsList({ count: 50, state: 'started' }); diff --git a/packages/roomkit-react/src/Prebuilt/components/Polls/Voting/Voting.tsx b/packages/roomkit-react/src/Prebuilt/components/Polls/Voting/Voting.tsx index 7e6830318a..7fd2af3f8f 100644 --- a/packages/roomkit-react/src/Prebuilt/components/Polls/Voting/Voting.tsx +++ b/packages/roomkit-react/src/Prebuilt/components/Polls/Voting/Voting.tsx @@ -39,17 +39,21 @@ export const Voting = ({ id, toggleVoting }: { id: string; toggleVoting: () => v if (poll && actions.interactivityCenter && !fetchedInitialResponses.current) { await actions.interactivityCenter.getPollResponses(poll, true); fetchedInitialResponses.current = true; - const pollResponses: Record = {}; - poll.questions?.forEach(question => { - pollResponses[question.index] = question.responses?.[0]; - }); - console.log('zzz updating', { pollResponses }); - setSavedPollResponses(pollResponses); } }; getResponses(); }, [poll, actions.interactivityCenter, setSavedPollResponses]); + useEffect(() => { + if (poll?.questions) { + const pollResponses: Record = {}; + poll.questions?.forEach(question => { + pollResponses[question.index] = question.responses?.[0]; + }); + setSavedPollResponses(pollResponses); + } + }, [poll?.questions, setSavedPollResponses]); + if (!poll) { return null; }