Skip to content

Commit

Permalink
fix: handle multiple quiz/polls
Browse files Browse the repository at this point in the history
  • Loading branch information
KaustubhKumar05 committed May 21, 2024
1 parent 523f6c0 commit a621d15
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/roomkit-react/src/Prebuilt/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export const getPeerResponses = (questions, peerid, userid) => {
return questions.map(question =>
question.responses?.filter(
response =>
((response && response.peer?.peerid === peerid) || response.peer?.userid === userid) && !response.skipped,
response && (response.peer?.peerid === peerid || response.peer?.userid === userid) && !response.skipped,
),
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const Voting = ({ id, toggleVoting }: { id: string; toggleVoting: () => v
// To reset whenever a different poll is opened
useEffect(() => {
fetchedInitialResponses.current = false;
setSavedPollResponses('');
}, [id, setSavedPollResponses]);

useEffect(() => {
Expand All @@ -60,14 +61,15 @@ export const Voting = ({ id, toggleVoting }: { id: string; toggleVoting: () => v
useEffect(() => {
if (poll?.questions) {
const localPeerResponses = getPeerResponses(poll.questions, localPeerId);

// @ts-ignore
localPeerResponses.forEach(response => {
if (response) updateSavedResponses(response.questionIndex, response.option, response.options);
localPeerResponses?.forEach(response => {
if (response) {
updateSavedResponses(response[0]?.questionIndex, response[0]?.option, response[0]?.options);
}
});
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [localPeerId, poll?.questions]);
}, [localPeerId, poll?.questions, id]);

if (!poll) {
return null;
Expand Down

0 comments on commit a621d15

Please sign in to comment.