@100mslive/roomkit-react 0.2.2-alpha.5 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -73,11 +73,6 @@ export const QuestionCard = ({
73
73
  },
74
74
  ]);
75
75
  startTime.current = Date.now();
76
-
77
- if (isQuiz && index !== totalQuestions) {
78
- setSingleOptionAnswer(undefined);
79
- setMultipleOptionAnswer(new Set());
80
- }
81
76
  }, [
82
77
  isValidVote,
83
78
  actions.interactivityCenter,
@@ -118,8 +113,8 @@ export const QuestionCard = ({
118
113
  gap: '$4',
119
114
  }}
120
115
  >
121
- {respondedToQuiz && isCorrectAnswer && pollEnded ? <CheckCircleIcon height={20} width={20} /> : null}
122
- {respondedToQuiz && !isCorrectAnswer && pollEnded ? <CrossCircleIcon height={20} width={20} /> : null}
116
+ {respondedToQuiz && isCorrectAnswer && pollEnded ? <CheckCircleIcon height={16} width={16} /> : null}
117
+ {respondedToQuiz && !isCorrectAnswer && pollEnded ? <CrossCircleIcon height={16} width={16} /> : null}
123
118
  QUESTION {index} OF {totalQuestions}: {type.toUpperCase()}
124
119
  </Text>
125
120
  </Flex>
@@ -152,7 +147,6 @@ export const QuestionCard = ({
152
147
  showVoteCount={showVoteCount}
153
148
  localPeerResponse={localPeerResponse}
154
149
  isStopped={pollState === 'stopped'}
155
- answer={singleOptionAnswer}
156
150
  />
157
151
  ) : null}
158
152
 
@@ -3,7 +3,7 @@ import { Box } from '../../../../Layout';
3
3
  import { Text } from '../../../../Text';
4
4
 
5
5
  export const StatisticBox = ({ title, value = 0 }: { title: string; value: string | number | undefined }) => {
6
- if (!value) {
6
+ if (!value && !(typeof value === 'number')) {
7
7
  return <></>;
8
8
  }
9
9
  return (
@@ -1,33 +1,44 @@
1
1
  import React, { useState } from 'react';
2
- import { HMSPoll } from '@100mslive/react-sdk';
2
+ import { HMSPoll, selectLocalPeerID, useHMSStore } from '@100mslive/react-sdk';
3
3
  // @ts-ignore
4
4
  import { QuestionCard } from './QuestionCard';
5
+ // @ts-ignore
6
+ import { getLastAttemptedIndex } from '../../../common/utils';
5
7
 
6
8
  export const TimedView = ({ poll }: { poll: HMSPoll }) => {
7
- // Backend question index starts at 1
8
- const [currentIndex, setCurrentIndex] = useState(1);
9
+ const localPeerId = useHMSStore(selectLocalPeerID);
10
+ const lastAttemptedIndex = getLastAttemptedIndex(poll.questions, localPeerId, '');
11
+ const [currentIndex, setCurrentIndex] = useState(lastAttemptedIndex);
9
12
  const activeQuestion = poll.questions?.find(question => question.index === currentIndex);
13
+ const attemptedAll = poll.questions?.length === lastAttemptedIndex - 1;
10
14
 
11
- if (!activeQuestion) {
15
+ if (!activeQuestion || !poll.questions?.length) {
12
16
  return null;
13
17
  }
14
18
 
15
19
  return (
16
- <QuestionCard
17
- pollID={poll.id}
18
- isQuiz={poll.type === 'quiz'}
19
- startedBy={poll.startedBy}
20
- pollState={poll.state}
21
- index={activeQuestion.index}
22
- text={activeQuestion.text}
23
- type={activeQuestion.type}
24
- result={activeQuestion?.result}
25
- totalQuestions={poll.questions?.length || 0}
26
- options={activeQuestion.options}
27
- responses={activeQuestion.responses}
28
- answer={activeQuestion.answer}
29
- setCurrentIndex={setCurrentIndex}
30
- rolesThatCanViewResponses={poll.rolesThatCanViewResponses}
31
- />
20
+ <>
21
+ {poll.questions.map(question => {
22
+ return attemptedAll || activeQuestion.index === question.index ? (
23
+ <QuestionCard
24
+ key={question.index}
25
+ pollID={poll.id}
26
+ isQuiz={poll.type === 'quiz'}
27
+ startedBy={poll.startedBy}
28
+ pollState={poll.state}
29
+ index={question.index}
30
+ text={question.text}
31
+ type={question.type}
32
+ result={question?.result}
33
+ totalQuestions={poll.questions?.length || 0}
34
+ options={question.options}
35
+ responses={question.responses}
36
+ answer={question.answer}
37
+ setCurrentIndex={setCurrentIndex}
38
+ rolesThatCanViewResponses={poll.rolesThatCanViewResponses}
39
+ />
40
+ ) : null;
41
+ })}
42
+ </>
32
43
  );
33
44
  };
@@ -68,7 +68,7 @@ export const Voting = ({ id, toggleVoting }: { id: string; toggleVoting: () => v
68
68
  </Box>
69
69
  </Flex>
70
70
 
71
- <Flex direction="column" css={{ p: '$8 $10', overflowY: 'auto' }}>
71
+ <Flex direction="column" css={{ p: '$8 $10', flex: '1 1 0', overflowY: 'auto' }}>
72
72
  {poll.state === 'started' ? (
73
73
  <Text css={{ color: '$on_surface_medium', fontWeight: '$semiBold' }}>
74
74
  {pollCreatorName || 'Participant'} started a {poll.type}
@@ -76,22 +76,21 @@ export const Voting = ({ id, toggleVoting }: { id: string; toggleVoting: () => v
76
76
  ) : null}
77
77
 
78
78
  {showSingleView ? <TimedView poll={poll} /> : <StandardView poll={poll} />}
79
-
79
+ </Flex>
80
+ <Flex
81
+ css={{ w: '100%', justifyContent: 'end', alignItems: 'center', p: '$8', borderTop: '1px solid $border_bright' }}
82
+ >
80
83
  {poll.state === 'started' && canEndActivity && (
81
84
  <Button
82
85
  variant="danger"
83
- css={{ fontWeight: '$semiBold', w: 'max-content', ml: 'auto', mt: '$8' }}
86
+ css={{ fontWeight: '$semiBold', w: 'max-content' }}
84
87
  onClick={() => actions.interactivityCenter.stopPoll(id)}
85
88
  >
86
89
  End {poll.type}
87
90
  </Button>
88
91
  )}
89
-
90
92
  {canViewLeaderboard ? (
91
- <Button
92
- css={{ fontWeight: '$semiBold', w: 'max-content', ml: 'auto', mt: '$8' }}
93
- onClick={() => setPollView(POLL_VIEWS.RESULTS)}
94
- >
93
+ <Button css={{ fontWeight: '$semiBold', w: 'max-content' }} onClick={() => setPollView(POLL_VIEWS.RESULTS)}>
95
94
  View Leaderboard
96
95
  </Button>
97
96
  ) : null}
@@ -52,7 +52,7 @@ export const MultipleChoiceOptions = ({
52
52
 
53
53
  {isStopped && correctOptionIndexes?.includes(option.index) ? (
54
54
  <Flex css={{ color: '$on_surface_high' }}>
55
- <CheckCircleIcon />
55
+ <CheckCircleIcon height={20} width={20} />
56
56
  </Flex>
57
57
  ) : null}
58
58
 
@@ -83,7 +83,7 @@ export const MultipleChoiceOptionInputs = ({ isQuiz, options, selectAnswer, hand
83
83
  <Flex direction="column" css={{ gap: '$md', w: '100%', mb: '$md' }}>
84
84
  {options.map((option, index) => {
85
85
  return (
86
- <Flex align="center" key={index} css={{ w: '100%', gap: '$5' }}>
86
+ <Flex align="center" key={index} css={{ w: '100%', gap: '$4' }}>
87
87
  {isQuiz && (
88
88
  <Checkbox.Root
89
89
  onCheckedChange={checked => selectAnswer(checked, index)}
@@ -17,14 +17,13 @@ export const SingleChoiceOptions = ({
17
17
  isStopped,
18
18
  isQuiz,
19
19
  localPeerResponse,
20
- answer,
21
20
  }) => {
22
21
  return (
23
- <RadioGroup.Root value={answer || null} onValueChange={value => setAnswer(value)}>
22
+ <RadioGroup.Root value={localPeerResponse?.option} onValueChange={value => setAnswer(value)}>
24
23
  <Flex direction="column" css={{ gap: '$md', w: '100%', mb: '$md' }}>
25
24
  {options.map(option => {
26
25
  return (
27
- <Flex align="start" key={`${questionIndex}-${option.index}`} css={{ w: '100%', gap: '$5' }}>
26
+ <Flex align="start" key={`${questionIndex}-${option.index}`} css={{ w: '100%', gap: '$4' }}>
28
27
  {!isStopped || !isQuiz ? (
29
28
  <RadioGroup.Item
30
29
  css={{
@@ -59,7 +58,7 @@ export const SingleChoiceOptions = ({
59
58
 
60
59
  {isStopped && correctOptionIndex === option.index && isQuiz ? (
61
60
  <Flex css={{ color: '$on_surface_high' }}>
62
- <CheckCircleIcon />
61
+ <CheckCircleIcon height={20} width={20} />
63
62
  </Flex>
64
63
  ) : null}
65
64
 
@@ -95,7 +94,7 @@ export const SingleChoiceOptionInputs = ({ isQuiz, options, selectAnswer, handle
95
94
  <Flex direction="column" css={{ gap: '$md', w: '100%', mb: '$md' }}>
96
95
  {options.map((option, index) => {
97
96
  return (
98
- <Flex align="center" key={`option-${index}`} css={{ w: '100%', gap: '$5' }}>
97
+ <Flex align="center" key={`option-${index}`} css={{ w: '100%', gap: '$4' }}>
99
98
  {isQuiz && (
100
99
  <RadioGroup.Item
101
100
  css={{