@100mslive/react-native-room-kit 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. package/lib/commonjs/HMSRoomSetup.js +13 -1
  2. package/lib/commonjs/HMSRoomSetup.js.map +1 -1
  3. package/lib/commonjs/Icons/Clock/assets/clock-vector.png +0 -0
  4. package/lib/commonjs/Icons/Clock/assets/clock-vector@2x.png +0 -0
  5. package/lib/commonjs/Icons/Clock/assets/clock-vector@3x.png +0 -0
  6. package/lib/commonjs/Icons/Clock/assets/clock.png +0 -0
  7. package/lib/commonjs/Icons/Clock/assets/clock@2x.png +0 -0
  8. package/lib/commonjs/Icons/Clock/assets/clock@3x.png +0 -0
  9. package/lib/commonjs/Icons/Clock/index.js +7 -2
  10. package/lib/commonjs/Icons/Clock/index.js.map +1 -1
  11. package/lib/commonjs/components/CreatePoll.js +3 -2
  12. package/lib/commonjs/components/CreatePoll.js.map +1 -1
  13. package/lib/commonjs/components/HLSView.js +15 -1
  14. package/lib/commonjs/components/HLSView.js.map +1 -1
  15. package/lib/commonjs/components/HMSPollsQuizzesNotification.js +1 -1
  16. package/lib/commonjs/components/HMSPollsQuizzesNotification.js.map +1 -1
  17. package/lib/commonjs/components/LeaderboardEntry.js +135 -0
  18. package/lib/commonjs/components/LeaderboardEntry.js.map +1 -0
  19. package/lib/commonjs/components/PollAndQuizSheetScreen.js +69 -0
  20. package/lib/commonjs/components/PollAndQuizSheetScreen.js.map +1 -0
  21. package/lib/commonjs/components/PollAndQuizVoting.js +133 -4
  22. package/lib/commonjs/components/PollAndQuizVoting.js.map +1 -1
  23. package/lib/commonjs/components/PollQuestions.js +104 -4
  24. package/lib/commonjs/components/PollQuestions.js.map +1 -1
  25. package/lib/commonjs/components/PollsAndQuizBottomSheet.js +9 -11
  26. package/lib/commonjs/components/PollsAndQuizBottomSheet.js.map +1 -1
  27. package/lib/commonjs/components/PollsAndQuizzesCard.js +1 -1
  28. package/lib/commonjs/components/PollsAndQuizzesCard.js.map +1 -1
  29. package/lib/commonjs/components/PollsAndQuizzesModalContent.js +26 -120
  30. package/lib/commonjs/components/PollsAndQuizzesModalContent.js.map +1 -1
  31. package/lib/commonjs/components/PollsConfigAndList.js +81 -4
  32. package/lib/commonjs/components/PollsConfigAndList.js.map +1 -1
  33. package/lib/commonjs/components/PreviousPollsAndQuizzesList.js +7 -15
  34. package/lib/commonjs/components/PreviousPollsAndQuizzesList.js.map +1 -1
  35. package/lib/commonjs/components/QuizLeaderboardEntriesScreen.js +284 -0
  36. package/lib/commonjs/components/QuizLeaderboardEntriesScreen.js.map +1 -0
  37. package/lib/commonjs/components/QuizLeaderboardScreen.js +279 -0
  38. package/lib/commonjs/components/QuizLeaderboardScreen.js.map +1 -0
  39. package/lib/commonjs/components/QuizLeaderboardSummary.js +195 -0
  40. package/lib/commonjs/components/QuizLeaderboardSummary.js.map +1 -0
  41. package/lib/commonjs/components/VoterParticipationSummary.js +46 -0
  42. package/lib/commonjs/components/VoterParticipationSummary.js.map +1 -0
  43. package/lib/commonjs/redux/actionTypes.js +7 -1
  44. package/lib/commonjs/redux/actionTypes.js.map +1 -1
  45. package/lib/commonjs/redux/actions/index.js +25 -5
  46. package/lib/commonjs/redux/actions/index.js.map +1 -1
  47. package/lib/commonjs/redux/reducers/polls.js +65 -5
  48. package/lib/commonjs/redux/reducers/polls.js.map +1 -1
  49. package/lib/commonjs/utils/hooks.js +107 -2
  50. package/lib/commonjs/utils/hooks.js.map +1 -1
  51. package/lib/module/HMSRoomSetup.js +13 -1
  52. package/lib/module/HMSRoomSetup.js.map +1 -1
  53. package/lib/module/Icons/Clock/assets/clock-vector.png +0 -0
  54. package/lib/module/Icons/Clock/assets/clock-vector@2x.png +0 -0
  55. package/lib/module/Icons/Clock/assets/clock-vector@3x.png +0 -0
  56. package/lib/module/Icons/Clock/assets/clock.png +0 -0
  57. package/lib/module/Icons/Clock/assets/clock@2x.png +0 -0
  58. package/lib/module/Icons/Clock/assets/clock@3x.png +0 -0
  59. package/lib/module/Icons/Clock/index.js +7 -2
  60. package/lib/module/Icons/Clock/index.js.map +1 -1
  61. package/lib/module/components/CreatePoll.js +4 -3
  62. package/lib/module/components/CreatePoll.js.map +1 -1
  63. package/lib/module/components/HLSView.js +17 -3
  64. package/lib/module/components/HLSView.js.map +1 -1
  65. package/lib/module/components/HMSPollsQuizzesNotification.js +2 -2
  66. package/lib/module/components/HMSPollsQuizzesNotification.js.map +1 -1
  67. package/lib/module/components/LeaderboardEntry.js +126 -0
  68. package/lib/module/components/LeaderboardEntry.js.map +1 -0
  69. package/lib/module/components/PollAndQuizSheetScreen.js +60 -0
  70. package/lib/module/components/PollAndQuizSheetScreen.js.map +1 -0
  71. package/lib/module/components/PollAndQuizVoting.js +135 -6
  72. package/lib/module/components/PollAndQuizVoting.js.map +1 -1
  73. package/lib/module/components/PollQuestions.js +107 -7
  74. package/lib/module/components/PollQuestions.js.map +1 -1
  75. package/lib/module/components/PollsAndQuizBottomSheet.js +11 -13
  76. package/lib/module/components/PollsAndQuizBottomSheet.js.map +1 -1
  77. package/lib/module/components/PollsAndQuizzesCard.js +2 -2
  78. package/lib/module/components/PollsAndQuizzesCard.js.map +1 -1
  79. package/lib/module/components/PollsAndQuizzesModalContent.js +28 -122
  80. package/lib/module/components/PollsAndQuizzesModalContent.js.map +1 -1
  81. package/lib/module/components/PollsConfigAndList.js +82 -5
  82. package/lib/module/components/PollsConfigAndList.js.map +1 -1
  83. package/lib/module/components/PreviousPollsAndQuizzesList.js +7 -15
  84. package/lib/module/components/PreviousPollsAndQuizzesList.js.map +1 -1
  85. package/lib/module/components/QuizLeaderboardEntriesScreen.js +275 -0
  86. package/lib/module/components/QuizLeaderboardEntriesScreen.js.map +1 -0
  87. package/lib/module/components/QuizLeaderboardScreen.js +270 -0
  88. package/lib/module/components/QuizLeaderboardScreen.js.map +1 -0
  89. package/lib/module/components/QuizLeaderboardSummary.js +186 -0
  90. package/lib/module/components/QuizLeaderboardSummary.js.map +1 -0
  91. package/lib/module/components/VoterParticipationSummary.js +37 -0
  92. package/lib/module/components/VoterParticipationSummary.js.map +1 -0
  93. package/lib/module/redux/actionTypes.js +7 -1
  94. package/lib/module/redux/actionTypes.js.map +1 -1
  95. package/lib/module/redux/actions/index.js +18 -3
  96. package/lib/module/redux/actions/index.js.map +1 -1
  97. package/lib/module/redux/reducers/polls.js +65 -5
  98. package/lib/module/redux/reducers/polls.js.map +1 -1
  99. package/lib/module/utils/hooks.js +105 -2
  100. package/lib/module/utils/hooks.js.map +1 -1
  101. package/lib/typescript/HMSRoomSetup.d.ts.map +1 -1
  102. package/lib/typescript/Icons/Clock/index.d.ts +1 -0
  103. package/lib/typescript/Icons/Clock/index.d.ts.map +1 -1
  104. package/lib/typescript/components/CreatePoll.d.ts.map +1 -1
  105. package/lib/typescript/components/HLSView.d.ts.map +1 -1
  106. package/lib/typescript/components/LeaderboardEntry.d.ts +11 -0
  107. package/lib/typescript/components/LeaderboardEntry.d.ts.map +1 -0
  108. package/lib/typescript/components/PollAndQuizSheetScreen.d.ts +8 -0
  109. package/lib/typescript/components/PollAndQuizSheetScreen.d.ts.map +1 -0
  110. package/lib/typescript/components/PollAndQuizVoting.d.ts +2 -0
  111. package/lib/typescript/components/PollAndQuizVoting.d.ts.map +1 -1
  112. package/lib/typescript/components/PollQuestions.d.ts +2 -0
  113. package/lib/typescript/components/PollQuestions.d.ts.map +1 -1
  114. package/lib/typescript/components/PollsAndQuizBottomSheet.d.ts.map +1 -1
  115. package/lib/typescript/components/PollsAndQuizzesModalContent.d.ts +0 -1
  116. package/lib/typescript/components/PollsAndQuizzesModalContent.d.ts.map +1 -1
  117. package/lib/typescript/components/PollsConfigAndList.d.ts +1 -0
  118. package/lib/typescript/components/PollsConfigAndList.d.ts.map +1 -1
  119. package/lib/typescript/components/PreviousPollsAndQuizzesList.d.ts.map +1 -1
  120. package/lib/typescript/components/QuizLeaderboardEntriesScreen.d.ts +8 -0
  121. package/lib/typescript/components/QuizLeaderboardEntriesScreen.d.ts.map +1 -0
  122. package/lib/typescript/components/QuizLeaderboardScreen.d.ts +8 -0
  123. package/lib/typescript/components/QuizLeaderboardScreen.d.ts.map +1 -0
  124. package/lib/typescript/components/QuizLeaderboardSummary.d.ts +9 -0
  125. package/lib/typescript/components/QuizLeaderboardSummary.d.ts.map +1 -0
  126. package/lib/typescript/components/VoterParticipationSummary.d.ts +7 -0
  127. package/lib/typescript/components/VoterParticipationSummary.d.ts.map +1 -0
  128. package/lib/typescript/redux/actionTypes.d.ts +29 -8
  129. package/lib/typescript/redux/actionTypes.d.ts.map +1 -1
  130. package/lib/typescript/redux/actions/index.d.ts +6 -2
  131. package/lib/typescript/redux/actions/index.d.ts.map +1 -1
  132. package/lib/typescript/redux/index.d.ts +2 -1
  133. package/lib/typescript/redux/index.d.ts.map +1 -1
  134. package/lib/typescript/redux/reducers/index.d.ts +2 -1
  135. package/lib/typescript/redux/reducers/index.d.ts.map +1 -1
  136. package/lib/typescript/redux/reducers/polls.d.ts +3 -2
  137. package/lib/typescript/redux/reducers/polls.d.ts.map +1 -1
  138. package/lib/typescript/utils/hooks.d.ts +6 -0
  139. package/lib/typescript/utils/hooks.d.ts.map +1 -1
  140. package/package.json +3 -3
  141. package/src/HMSRoomSetup.tsx +19 -1
  142. package/src/Icons/Clock/assets/clock-vector.png +0 -0
  143. package/src/Icons/Clock/assets/clock-vector@2x.png +0 -0
  144. package/src/Icons/Clock/assets/clock-vector@3x.png +0 -0
  145. package/src/Icons/Clock/assets/clock.png +0 -0
  146. package/src/Icons/Clock/assets/clock@2x.png +0 -0
  147. package/src/Icons/Clock/assets/clock@3x.png +0 -0
  148. package/src/Icons/Clock/index.tsx +16 -3
  149. package/src/components/CreatePoll.tsx +7 -2
  150. package/src/components/HLSView.tsx +27 -1
  151. package/src/components/HMSPollsQuizzesNotification.tsx +2 -2
  152. package/src/components/LeaderboardEntry.tsx +172 -0
  153. package/src/components/PollAndQuizSheetScreen.tsx +85 -0
  154. package/src/components/PollAndQuizVoting.tsx +181 -7
  155. package/src/components/PollQuestions.tsx +171 -49
  156. package/src/components/PollsAndQuizBottomSheet.tsx +20 -42
  157. package/src/components/PollsAndQuizzesCard.tsx +2 -2
  158. package/src/components/PollsAndQuizzesModalContent.tsx +40 -163
  159. package/src/components/PollsConfigAndList.tsx +107 -11
  160. package/src/components/PreviousPollsAndQuizzesList.tsx +33 -40
  161. package/src/components/QuizLeaderboardEntriesScreen.tsx +323 -0
  162. package/src/components/QuizLeaderboardScreen.tsx +342 -0
  163. package/src/components/QuizLeaderboardSummary.tsx +207 -0
  164. package/src/components/VoterParticipationSummary.tsx +67 -0
  165. package/src/redux/actionTypes.ts +35 -5
  166. package/src/redux/actions/index.ts +34 -6
  167. package/src/redux/reducers/polls.ts +84 -6
  168. package/src/utils/hooks.ts +190 -3
@@ -0,0 +1,207 @@
1
+ import * as React from 'react';
2
+ import { Text, StyleSheet, View } from 'react-native';
3
+
4
+ import { useHMSRoomStyleSheet } from '../hooks-util';
5
+
6
+ export interface QuizLeaderboardSummaryProps {
7
+ data: { label: string; value: any }[][];
8
+ }
9
+
10
+ export const QuizLeaderboardSummary: React.FC<QuizLeaderboardSummaryProps> = ({
11
+ data,
12
+ }) => {
13
+ const hmsRoomStyles = useHMSRoomStyleSheet((theme, typography) => ({
14
+ regularHighText: {
15
+ color: theme.palette.on_surface_high,
16
+ fontFamily: `${typography.font_family}-Regular`,
17
+ },
18
+ regularMediumText: {
19
+ color: theme.palette.on_surface_medium,
20
+ fontFamily: `${typography.font_family}-Regular`,
21
+ },
22
+ semiBoldMediumText: {
23
+ color: theme.palette.on_surface_medium,
24
+ fontFamily: `${typography.font_family}-SemiBold`,
25
+ },
26
+ semiBoldHighText: {
27
+ color: theme.palette.on_surface_high,
28
+ fontFamily: `${typography.font_family}-SemiBold`,
29
+ },
30
+ headerText: {
31
+ color: theme.palette.on_surface_high,
32
+ fontFamily: `${typography.font_family}-SemiBold`,
33
+ },
34
+ container: {
35
+ backgroundColor: theme.palette.surface_dim,
36
+ },
37
+ summaryContainer: {
38
+ backgroundColor: theme.palette.surface_default,
39
+ },
40
+ entriesCard: {
41
+ backgroundColor: theme.palette.surface_default,
42
+ },
43
+ divider: {
44
+ backgroundColor: theme.palette.border_bright,
45
+ },
46
+ }));
47
+
48
+ return (
49
+ <View style={{}}>
50
+ <Text
51
+ style={[
52
+ styles.normalText,
53
+ styles.marginBottom16,
54
+ hmsRoomStyles.semiBoldHighText,
55
+ ]}
56
+ >
57
+ Participation Summary
58
+ </Text>
59
+
60
+ <View style={styles.marginBottom16}>
61
+ {data.map((summaryMap, index) => (
62
+ <View key={index} style={{ marginBottom: 8, flexDirection: 'row' }}>
63
+ {summaryMap.map((summary, index) => (
64
+ <React.Fragment key={summary.label}>
65
+ {index > 0 ? <View style={{ width: 8 }} /> : null}
66
+
67
+ <View
68
+ style={[
69
+ styles.summaryWrapper,
70
+ hmsRoomStyles.summaryContainer,
71
+ ]}
72
+ >
73
+ <Text
74
+ style={[
75
+ styles.tinyText,
76
+ styles.marginBottom8,
77
+ hmsRoomStyles.semiBoldMediumText,
78
+ ]}
79
+ >
80
+ {summary.label}
81
+ </Text>
82
+
83
+ <Text
84
+ style={[styles.normalText, hmsRoomStyles.semiBoldHighText]}
85
+ >
86
+ {summary.value}
87
+ </Text>
88
+ </View>
89
+ </React.Fragment>
90
+ ))}
91
+ </View>
92
+ ))}
93
+ </View>
94
+ </View>
95
+ );
96
+ };
97
+
98
+ const styles = StyleSheet.create({
99
+ tinyText: {
100
+ fontSize: 10,
101
+ lineHeight: 16,
102
+ letterSpacing: 1.5,
103
+ },
104
+ smallerText: {
105
+ fontSize: 12,
106
+ lineHeight: 16,
107
+ },
108
+ smallText: {
109
+ fontSize: 14,
110
+ lineHeight: 20,
111
+ },
112
+ normalText: {
113
+ fontSize: 16,
114
+ lineHeight: 24,
115
+ },
116
+ marginBottom8: {
117
+ marginBottom: 8,
118
+ },
119
+ marginBottom16: {
120
+ marginBottom: 16,
121
+ },
122
+ contentContainer: {
123
+ paddingHorizontal: 24,
124
+ },
125
+ scrollViewContentContainer: {
126
+ flexGrow: 1,
127
+ paddingVertical: 24,
128
+ },
129
+ summaryWrapper: {
130
+ flexBasis: '50%',
131
+ flexGrow: 1,
132
+ flexShrink: 1,
133
+ padding: 16,
134
+ borderRadius: 12,
135
+ },
136
+ position: {
137
+ width: 24,
138
+ height: 24,
139
+ borderRadius: 12,
140
+ textAlign: 'center',
141
+ textAlignVertical: 'center',
142
+ marginRight: 12,
143
+ },
144
+ firstPosition: {
145
+ backgroundColor: '#D69516', // '#FFD700'
146
+ },
147
+ secondPosition: {
148
+ backgroundColor: '#3E3E3E', // '#C0C0C0'
149
+ },
150
+ thirdPosition: {
151
+ backgroundColor: '#583B0F', // '#CD7F32'
152
+ },
153
+ iconWrapper: {
154
+ flexDirection: 'row',
155
+ alignItems: 'center',
156
+ marginLeft: 12,
157
+ },
158
+ // Utilities
159
+ fullView: {
160
+ flex: 1,
161
+ },
162
+ // Header
163
+ header: {
164
+ flexDirection: 'row',
165
+ alignItems: 'center',
166
+ justifyContent: 'space-between',
167
+ marginTop: 24,
168
+ marginHorizontal: 24,
169
+ },
170
+ headerControls: {
171
+ flexDirection: 'row',
172
+ alignItems: 'center',
173
+ flexShrink: 1,
174
+ },
175
+ headerText: {
176
+ fontSize: 20,
177
+ lineHeight: 24,
178
+ letterSpacing: 0.15,
179
+ marginRight: 12,
180
+ },
181
+ closeIconHitSlop: {
182
+ bottom: 16,
183
+ left: 16,
184
+ right: 16,
185
+ top: 16,
186
+ },
187
+ backIcon: {
188
+ marginRight: 8,
189
+ },
190
+ // Divider
191
+ halfDivider: {
192
+ marginHorizontal: 24,
193
+ marginVertical: 0,
194
+ marginTop: 24,
195
+ width: undefined,
196
+ },
197
+ divider: { height: 1, width: '100%' },
198
+ viewAllBtn: {
199
+ flexDirection: 'row',
200
+ alignItems: 'center',
201
+ justifyContent: 'flex-end',
202
+ paddingVertical: 12,
203
+ paddingHorizontal: 16,
204
+ },
205
+ leaderboardEntry: { marginBottom: 16, marginHorizontal: 16 },
206
+ entriesCard: { paddingTop: 12, borderRadius: 8 },
207
+ });
@@ -0,0 +1,67 @@
1
+ import * as React from 'react';
2
+ import type { HMSPoll } from '@100mslive/react-native-hms';
3
+ import { useSelector } from 'react-redux';
4
+
5
+ import type { RootState } from '../redux';
6
+ import { QuizLeaderboardSummary } from './QuizLeaderboardSummary';
7
+ import { useFetchLeaderboardResponse } from '../utils/hooks';
8
+
9
+ export interface VoterParticipationSummaryProps {
10
+ pollId: HMSPoll['pollId'];
11
+ }
12
+
13
+ export const VoterParticipationSummary: React.FC<
14
+ VoterParticipationSummaryProps
15
+ > = ({ pollId }) => {
16
+ const localPeerUserId = useSelector(
17
+ (state: RootState) => state.hmsStates.localPeer?.customerUserID
18
+ );
19
+ const leaderboardData = useFetchLeaderboardResponse(pollId);
20
+ const totalQuestions = useSelector(
21
+ (state: RootState) => state.polls.polls[pollId]?.questions?.length
22
+ );
23
+
24
+ const localLeaderboardEntry =
25
+ localPeerUserId && leaderboardData && Array.isArray(leaderboardData.entries)
26
+ ? leaderboardData.entries.find(
27
+ (entry) => entry.peer?.customerUserId === localPeerUserId
28
+ )
29
+ : null;
30
+
31
+ const data = React.useMemo(() => {
32
+ return [
33
+ [
34
+ {
35
+ label: 'ANSWERED',
36
+ value:
37
+ localLeaderboardEntry &&
38
+ typeof localLeaderboardEntry.totalResponses === 'number' &&
39
+ typeof totalQuestions === 'number'
40
+ ? `${Math.round((localLeaderboardEntry.totalResponses / totalQuestions) * 100)}% (${localLeaderboardEntry.totalResponses}/${totalQuestions})`
41
+ : '-',
42
+ },
43
+ {
44
+ label: 'CORRECT ANSWERS',
45
+ value:
46
+ localLeaderboardEntry &&
47
+ typeof localLeaderboardEntry.correctResponses === 'number' &&
48
+ typeof totalQuestions === 'number'
49
+ ? `${Math.round((localLeaderboardEntry.correctResponses / totalQuestions) * 100)}% (${localLeaderboardEntry.correctResponses}/${totalQuestions})`
50
+ : '-',
51
+ },
52
+ ],
53
+ [
54
+ {
55
+ label: 'TIME TAKEN',
56
+ value:
57
+ localLeaderboardEntry &&
58
+ typeof localLeaderboardEntry.duration === 'number'
59
+ ? `${(localLeaderboardEntry.duration / 1000).toFixed(2)}s`
60
+ : '-',
61
+ },
62
+ ],
63
+ ];
64
+ }, [localLeaderboardEntry]);
65
+
66
+ return <QuizLeaderboardSummary data={data} />;
67
+ };
@@ -3,6 +3,7 @@ import type {
3
3
  HMSPollQuestion,
4
4
  HMSPollQuestionType,
5
5
  HMSPollType,
6
+ PollLeaderboardResponse,
6
7
  } from '@100mslive/react-native-hms';
7
8
 
8
9
  const createRequests = (base: String) => {
@@ -195,6 +196,8 @@ export enum CreatePollStages {
195
196
  POLL_CONFIG,
196
197
  POLL_QUESTION_CONFIG,
197
198
  POLL_VOTING,
199
+ QUIZ_LEADERBOARD,
200
+ QUIZ_LEADERBOARD_ENTRIES,
198
201
  }
199
202
 
200
203
  export type PollConfig = {
@@ -217,7 +220,10 @@ export type PollsActionType =
217
220
  | SetDeleteConfirmationVisible
218
221
  | SetPollNameAction
219
222
  | SetPollConfigAction
220
- | SetPollStageAction
223
+ | PushToNavigationStackAction
224
+ | ResetNavigationStackAction
225
+ | PopFromNavigationStackAction
226
+ | ReplaceTopOfNavigationStackAction
221
227
  | AddPollQuestionAction
222
228
  | DeletePollQuestionAction
223
229
  | SetSelectedQuestionIndexAction
@@ -241,6 +247,7 @@ export type PollsActionType =
241
247
  | AddPollQuestionResponseAction
242
248
  | RemovePollQuestionResponseAction
243
249
  | AddCuedPollIdAction
250
+ | AddLeaderboardAction
244
251
  | { type: HmsStateActionTypes.CLEAR_STATES };
245
252
 
246
253
  export type ClearPollFormStateAction = {
@@ -262,9 +269,22 @@ export type SetPollConfigAction = {
262
269
  pollConfig: Partial<PollConfig>;
263
270
  };
264
271
 
265
- export type SetPollStageAction = {
266
- type: PollsStateActionTypes.SET_POLL_STAGE;
267
- pollStage: CreatePollStages;
272
+ export type PushToNavigationStackAction = {
273
+ type: PollsStateActionTypes.PUSH_TO_NAVIGATION_STACK;
274
+ screen: CreatePollStages;
275
+ };
276
+
277
+ export type ResetNavigationStackAction = {
278
+ type: PollsStateActionTypes.RESET_NAVIGATION_STACK;
279
+ };
280
+
281
+ export type PopFromNavigationStackAction = {
282
+ type: PollsStateActionTypes.POP_FROM_NAVIGATION_STACK;
283
+ };
284
+
285
+ export type ReplaceTopOfNavigationStackAction = {
286
+ type: PollsStateActionTypes.REPLACE_TOP_OF_NAVIGATION_STACK;
287
+ screen: CreatePollStages;
268
288
  };
269
289
 
270
290
  export type AddPollQuestionAction = {
@@ -391,12 +411,21 @@ export type AddCuedPollIdAction = {
391
411
  pollId: HMSPoll['pollId'];
392
412
  };
393
413
 
414
+ export type AddLeaderboardAction = {
415
+ type: PollsStateActionTypes.ADD_LEADERBOARD;
416
+ pollId: HMSPoll['pollId'];
417
+ leaderboard: PollLeaderboardResponse;
418
+ };
419
+
394
420
  export enum PollsStateActionTypes {
395
421
  CLEAR_POLL_FORM_STATE = 'CLEAR_POLL_FORM_STATE',
396
422
  SET_DELETE_CONFIRMATION_VISIBLE = 'SET_DELETE_CONFIRMATION_VISIBLE',
397
423
  SET_POLL_NAME = 'SET_POLL_NAME',
398
424
  SET_POLL_CONFIG = 'SET_POLL_CONFIG',
399
- SET_POLL_STAGE = 'SET_POLL_STAGE',
425
+ PUSH_TO_NAVIGATION_STACK = 'PUSH_TO_NAVIGATION_STACK',
426
+ RESET_NAVIGATION_STACK = 'RESET_NAVIGATION_STACK',
427
+ POP_FROM_NAVIGATION_STACK = 'POP_FROM_NAVIGATION_STACK',
428
+ REPLACE_TOP_OF_NAVIGATION_STACK = 'REPLACE_TOP_OF_NAVIGATION_STACK',
400
429
  ADD_POLL_QUESTION = 'ADD_POLL_QUESTION',
401
430
  DELETE_POLL_QUESTION = 'DELETE_POLL_QUESTION',
402
431
  SET_SELECTED_QUESTION_INDEX = 'SET_SELECTED_QUESTION_INDEX',
@@ -419,4 +448,5 @@ export enum PollsStateActionTypes {
419
448
  REMOVE_POLL_QUESTION_RESPONSE = 'REMOVE_POLL_QUESTION_RESPONSE',
420
449
  ADD_POLL_QUESTION_RESPONSE = 'ADD_POLL_QUESTION_RESPONSE',
421
450
  ADD_CUED_POLL_ID = 'ADD_CUED_POLL_ID',
451
+ ADD_LEADERBOARD = 'ADD_LEADERBOARD',
422
452
  }
@@ -32,7 +32,6 @@ import type {
32
32
  AddPollQuestionAction,
33
33
  SetPollConfigAction,
34
34
  SetPollNameAction,
35
- SetPollStageAction,
36
35
  DeletePollQuestionAction,
37
36
  SetDeleteConfirmationVisible,
38
37
  SetSelectedQuestionIndexAction,
@@ -54,6 +53,11 @@ import type {
54
53
  RemovePollQuestionResponseAction,
55
54
  SetQuestionPointWeightageAction,
56
55
  SetQuestionCorrectOptionAction,
56
+ PushToNavigationStackAction,
57
+ PopFromNavigationStackAction,
58
+ ReplaceTopOfNavigationStackAction,
59
+ AddLeaderboardAction,
60
+ ResetNavigationStackAction,
57
61
  } from '../actionTypes';
58
62
  import { MeetingState } from '../../types';
59
63
  import type { ChatState, Notification, PinnedMessage } from '../../types';
@@ -491,11 +495,26 @@ export const setPollConfig = (
491
495
  pollConfig,
492
496
  });
493
497
 
494
- export const setPollStage = (
495
- pollStage: SetPollStageAction['pollStage']
496
- ): SetPollStageAction => ({
497
- type: PollsStateActionTypes.SET_POLL_STAGE,
498
- pollStage,
498
+ export const pushToNavigationStack = (
499
+ screen: PushToNavigationStackAction['screen']
500
+ ): PushToNavigationStackAction => ({
501
+ type: PollsStateActionTypes.PUSH_TO_NAVIGATION_STACK,
502
+ screen,
503
+ });
504
+
505
+ export const resetNavigationStack = (): ResetNavigationStackAction => ({
506
+ type: PollsStateActionTypes.RESET_NAVIGATION_STACK,
507
+ });
508
+
509
+ export const popFromNavigationStack = (): PopFromNavigationStackAction => ({
510
+ type: PollsStateActionTypes.POP_FROM_NAVIGATION_STACK,
511
+ });
512
+
513
+ export const replaceTopOfNavigationStack = (
514
+ screen: ReplaceTopOfNavigationStackAction['screen']
515
+ ): ReplaceTopOfNavigationStackAction => ({
516
+ type: PollsStateActionTypes.REPLACE_TOP_OF_NAVIGATION_STACK,
517
+ screen,
499
518
  });
500
519
 
501
520
  export const addPollQuestion = (): AddPollQuestionAction => ({
@@ -672,3 +691,12 @@ export const addCuedPollId = (pollId: string) => ({
672
691
  type: PollsStateActionTypes.ADD_CUED_POLL_ID,
673
692
  pollId,
674
693
  });
694
+
695
+ export const addLeaderboard = (
696
+ pollId: AddLeaderboardAction['pollId'],
697
+ leaderboard: AddLeaderboardAction['leaderboard']
698
+ ): AddLeaderboardAction => ({
699
+ type: PollsStateActionTypes.ADD_LEADERBOARD,
700
+ pollId,
701
+ leaderboard,
702
+ });
@@ -1,5 +1,8 @@
1
1
  import { HMSPollQuestionType, HMSPollType } from '@100mslive/react-native-hms';
2
- import type { HMSPoll } from '@100mslive/react-native-hms';
2
+ import type {
3
+ HMSPoll,
4
+ PollLeaderboardResponse,
5
+ } from '@100mslive/react-native-hms';
3
6
 
4
7
  import {
5
8
  PollsStateActionTypes,
@@ -30,7 +33,7 @@ function getDefaultQuestionObj(): PollQuestionUI {
30
33
  type IntialStateType = {
31
34
  pollName: string;
32
35
  pollConfig: PollConfig;
33
- stage: CreatePollStages;
36
+ navigationStack: CreatePollStages[];
34
37
  questions: PollQuestionUI[];
35
38
  deleteConfirmationVisible: boolean;
36
39
  selectedPollQuestionIndex: number | null;
@@ -39,6 +42,7 @@ type IntialStateType = {
39
42
  cuedPollIds: HMSPoll['pollId'][]; // In case of HLSViewer, pollIds should be aligned with onCue event
40
43
  polls: Record<string, HMSPoll>;
41
44
  pollsResponses: Record<string, Record<number, number | number[]>>;
45
+ leaderboards: Record<string, PollLeaderboardResponse>;
42
46
  };
43
47
 
44
48
  const INITIAL_STATE: IntialStateType = {
@@ -48,7 +52,7 @@ const INITIAL_STATE: IntialStateType = {
48
52
  voteCountHidden: false,
49
53
  resultsAnonymous: false,
50
54
  },
51
- stage: CreatePollStages.POLL_CONFIG,
55
+ navigationStack: [CreatePollStages.POLL_CONFIG],
52
56
  questions: [getDefaultQuestionObj()],
53
57
  deleteConfirmationVisible: false,
54
58
  selectedPollQuestionIndex: null,
@@ -57,6 +61,7 @@ const INITIAL_STATE: IntialStateType = {
57
61
  cuedPollIds: [],
58
62
  polls: {},
59
63
  pollsResponses: {},
64
+ leaderboards: {},
60
65
  };
61
66
 
62
67
  const hmsStatesReducer = (
@@ -87,11 +92,30 @@ const hmsStatesReducer = (
87
92
  : state.questions,
88
93
  selectedPollQuestionIndex: null,
89
94
  };
90
- case PollsStateActionTypes.SET_POLL_STAGE:
95
+ case PollsStateActionTypes.PUSH_TO_NAVIGATION_STACK:
91
96
  return {
92
97
  ...state,
93
- stage: action.pollStage,
94
- selectedPollQuestionIndex: null,
98
+ navigationStack: [...state.navigationStack, action.screen],
99
+ };
100
+ case PollsStateActionTypes.RESET_NAVIGATION_STACK:
101
+ return {
102
+ ...state,
103
+ navigationStack: INITIAL_STATE.navigationStack,
104
+ };
105
+ case PollsStateActionTypes.POP_FROM_NAVIGATION_STACK: {
106
+ const updatedNavigationStack = [...state.navigationStack];
107
+ updatedNavigationStack.pop();
108
+ return {
109
+ ...state,
110
+ navigationStack: updatedNavigationStack,
111
+ };
112
+ }
113
+ case PollsStateActionTypes.REPLACE_TOP_OF_NAVIGATION_STACK:
114
+ const updatedNavigationStack = [...state.navigationStack];
115
+ updatedNavigationStack[updatedNavigationStack.length - 1] = action.screen;
116
+ return {
117
+ ...state,
118
+ navigationStack: updatedNavigationStack,
95
119
  };
96
120
  case PollsStateActionTypes.ADD_POLL_QUESTION:
97
121
  return {
@@ -286,6 +310,51 @@ const hmsStatesReducer = (
286
310
  selectedPollId: action.pollId,
287
311
  };
288
312
  case PollsStateActionTypes.ADD_POLL:
313
+ const prevPoll = state.polls[action.poll.pollId];
314
+
315
+ // Hack: Restore previous state of poll if current poll has missing myResponses and voteCount
316
+ if (
317
+ prevPoll &&
318
+ Array.isArray(prevPoll.questions) &&
319
+ prevPoll.questions.length > 0
320
+ ) {
321
+ action.poll.questions?.forEach((question) => {
322
+ const prevQuestion = prevPoll.questions?.find(
323
+ (prevQuestion) => prevQuestion.index === question.index
324
+ );
325
+
326
+ //#region Restore previous responses on question if current question has no responses
327
+ const prevResponsesOnQuestion = prevQuestion?.myResponses;
328
+ if (
329
+ Array.isArray(prevResponsesOnQuestion) &&
330
+ prevResponsesOnQuestion.length > 0 &&
331
+ (!question.myResponses || question.myResponses.length <= 0)
332
+ ) {
333
+ question.myResponses = prevResponsesOnQuestion;
334
+ }
335
+ //#endregion
336
+
337
+ //#region Restore previous voteCount on question options if current question options has no voteCount
338
+ const prevOptions = prevQuestion?.options;
339
+
340
+ question.options?.forEach((option) => {
341
+ const prevOption = prevOptions?.find(
342
+ (prevOption) => prevOption.index === option.index
343
+ );
344
+
345
+ // Edge Case: User changes response on question, due to which new vountCount becomes 0, and we are treating as invalid value
346
+ if (
347
+ option.voteCount <= 0 &&
348
+ prevOption &&
349
+ prevOption?.voteCount > 0
350
+ ) {
351
+ option.voteCount = prevOption.voteCount;
352
+ }
353
+ });
354
+ //#endregion
355
+ });
356
+ }
357
+
289
358
  return {
290
359
  ...state,
291
360
  polls: {
@@ -360,6 +429,15 @@ const hmsStatesReducer = (
360
429
  cuedPollIds: [...state.cuedPollIds, action.pollId],
361
430
  };
362
431
  }
432
+ case PollsStateActionTypes.ADD_LEADERBOARD: {
433
+ return {
434
+ ...state,
435
+ leaderboards: {
436
+ ...state.leaderboards,
437
+ [action.pollId]: action.leaderboard,
438
+ },
439
+ };
440
+ }
363
441
  case PollsStateActionTypes.CLEAR_POLL_FORM_STATE: {
364
442
  return {
365
443
  ...INITIAL_STATE,