import React, { Dispatch, SetStateAction, useEffect, useState } from 'react'; import { HMSPoll } from '@100mslive/react-sdk'; // @ts-ignore import { QuestionCard } from './QuestionCard'; // @ts-ignore import { getIndexToShow } from '../../../common/utils'; export const TimedView = ({ poll, localPeerResponses, updateSavedResponses, }: { poll: HMSPoll; localPeerResponses?: Record; updateSavedResponses: Dispatch>>; }) => { const [currentIndex, setCurrentIndex] = useState(getIndexToShow(localPeerResponses)); const activeQuestion = poll.questions?.find(question => question.index === currentIndex); const attemptedAll = (poll.questions?.length || 0) < currentIndex; // Handles increments so only one question is shown at a time in quiz useEffect(() => { setCurrentIndex(getIndexToShow(localPeerResponses)); }, [localPeerResponses]); if ((!activeQuestion && !attemptedAll) || !poll.questions?.length) { return null; } return ( <> {poll.questions.map(question => { return attemptedAll || activeQuestion?.index === question.index ? ( ) : null; })} ); };