@100mslive/react-native-room-kit 1.1.1 → 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.
- package/README.md +1 -1
- package/lib/commonjs/HMSRoomSetup.js +15 -5
- package/lib/commonjs/HMSRoomSetup.js.map +1 -1
- package/lib/commonjs/Icons/Check/assets/check-in-circle.png +0 -0
- package/lib/commonjs/Icons/Check/assets/check-in-circle@2x.png +0 -0
- package/lib/commonjs/Icons/Check/assets/check-in-circle@3x.png +0 -0
- package/lib/commonjs/Icons/Check/index.js +2 -1
- package/lib/commonjs/Icons/Check/index.js.map +1 -1
- package/lib/commonjs/Icons/CheckBox/index.js +8 -1
- package/lib/commonjs/Icons/CheckBox/index.js.map +1 -1
- package/lib/commonjs/Icons/Clock/assets/clock-vector.png +0 -0
- package/lib/commonjs/Icons/Clock/assets/clock-vector@2x.png +0 -0
- package/lib/commonjs/Icons/Clock/assets/clock-vector@3x.png +0 -0
- package/lib/commonjs/Icons/Clock/assets/clock.png +0 -0
- package/lib/commonjs/Icons/Clock/assets/clock@2x.png +0 -0
- package/lib/commonjs/Icons/Clock/assets/clock@3x.png +0 -0
- package/lib/commonjs/Icons/Clock/index.js +7 -2
- package/lib/commonjs/Icons/Clock/index.js.map +1 -1
- package/lib/commonjs/components/CreatePoll.js +100 -53
- package/lib/commonjs/components/CreatePoll.js.map +1 -1
- package/lib/commonjs/components/GridView.js +4 -8
- package/lib/commonjs/components/GridView.js.map +1 -1
- package/lib/commonjs/components/HLSView.js +15 -1
- package/lib/commonjs/components/HLSView.js.map +1 -1
- package/lib/commonjs/components/HMSPollsQuizzesNotification.js +2 -2
- package/lib/commonjs/components/HMSPollsQuizzesNotification.js.map +1 -1
- package/lib/commonjs/components/LeaderboardEntry.js +135 -0
- package/lib/commonjs/components/LeaderboardEntry.js.map +1 -0
- package/lib/commonjs/components/PollAndQuizQuestionResponseCard.js +80 -32
- package/lib/commonjs/components/PollAndQuizQuestionResponseCard.js.map +1 -1
- package/lib/commonjs/components/PollAndQuizQuestionResponseCards.js +53 -0
- package/lib/commonjs/components/PollAndQuizQuestionResponseCards.js.map +1 -0
- package/lib/commonjs/components/PollAndQuizSheetScreen.js +69 -0
- package/lib/commonjs/components/PollAndQuizSheetScreen.js.map +1 -0
- package/lib/commonjs/components/PollAndQuizVoting.js +145 -17
- package/lib/commonjs/components/PollAndQuizVoting.js.map +1 -1
- package/lib/commonjs/components/PollQuestion.js +70 -14
- package/lib/commonjs/components/PollQuestion.js.map +1 -1
- package/lib/commonjs/components/PollQuestions.js +126 -12
- package/lib/commonjs/components/PollQuestions.js.map +1 -1
- package/lib/commonjs/components/PollsAndQuizBottomSheet.js +9 -11
- package/lib/commonjs/components/PollsAndQuizBottomSheet.js.map +1 -1
- package/lib/commonjs/components/PollsAndQuizzesCard.js +1 -1
- package/lib/commonjs/components/PollsAndQuizzesCard.js.map +1 -1
- package/lib/commonjs/components/PollsAndQuizzesModalContent.js +26 -120
- package/lib/commonjs/components/PollsAndQuizzesModalContent.js.map +1 -1
- package/lib/commonjs/components/PollsConfigAndList.js +81 -4
- package/lib/commonjs/components/PollsConfigAndList.js.map +1 -1
- package/lib/commonjs/components/PreviousPollsAndQuizzesList.js +7 -15
- package/lib/commonjs/components/PreviousPollsAndQuizzesList.js.map +1 -1
- package/lib/commonjs/components/QuizEndOptionsView.js +63 -0
- package/lib/commonjs/components/QuizEndOptionsView.js.map +1 -0
- package/lib/commonjs/components/QuizLeaderboardEntriesScreen.js +284 -0
- package/lib/commonjs/components/QuizLeaderboardEntriesScreen.js.map +1 -0
- package/lib/commonjs/components/QuizLeaderboardScreen.js +279 -0
- package/lib/commonjs/components/QuizLeaderboardScreen.js.map +1 -0
- package/lib/commonjs/components/QuizLeaderboardSummary.js +195 -0
- package/lib/commonjs/components/QuizLeaderboardSummary.js.map +1 -0
- package/lib/commonjs/components/RadioInput.js +9 -2
- package/lib/commonjs/components/RadioInput.js.map +1 -1
- package/lib/commonjs/components/RoomSettingsModalContent.js +1 -1
- package/lib/commonjs/components/RoomSettingsModalContent.js.map +1 -1
- package/lib/commonjs/components/TilesContainer.js +3 -4
- package/lib/commonjs/components/TilesContainer.js.map +1 -1
- package/lib/commonjs/components/VoterParticipationSummary.js +46 -0
- package/lib/commonjs/components/VoterParticipationSummary.js.map +1 -0
- package/lib/commonjs/hooks-util.js +1 -1
- package/lib/commonjs/hooks-util.js.map +1 -1
- package/lib/commonjs/redux/actionTypes.js +9 -1
- package/lib/commonjs/redux/actionTypes.js.map +1 -1
- package/lib/commonjs/redux/actions/index.js +38 -5
- package/lib/commonjs/redux/actions/index.js.map +1 -1
- package/lib/commonjs/redux/reducers/polls.js +95 -8
- package/lib/commonjs/redux/reducers/polls.js.map +1 -1
- package/lib/commonjs/utils/functions.js +48 -3
- package/lib/commonjs/utils/functions.js.map +1 -1
- package/lib/commonjs/utils/hooks.js +107 -2
- package/lib/commonjs/utils/hooks.js.map +1 -1
- package/lib/module/HMSRoomSetup.js +16 -6
- package/lib/module/HMSRoomSetup.js.map +1 -1
- package/lib/module/Icons/Check/assets/check-in-circle.png +0 -0
- package/lib/module/Icons/Check/assets/check-in-circle@2x.png +0 -0
- package/lib/module/Icons/Check/assets/check-in-circle@3x.png +0 -0
- package/lib/module/Icons/Check/index.js +2 -1
- package/lib/module/Icons/Check/index.js.map +1 -1
- package/lib/module/Icons/CheckBox/index.js +9 -2
- package/lib/module/Icons/CheckBox/index.js.map +1 -1
- package/lib/module/Icons/Clock/assets/clock-vector.png +0 -0
- package/lib/module/Icons/Clock/assets/clock-vector@2x.png +0 -0
- package/lib/module/Icons/Clock/assets/clock-vector@3x.png +0 -0
- package/lib/module/Icons/Clock/assets/clock.png +0 -0
- package/lib/module/Icons/Clock/assets/clock@2x.png +0 -0
- package/lib/module/Icons/Clock/assets/clock@3x.png +0 -0
- package/lib/module/Icons/Clock/index.js +7 -2
- package/lib/module/Icons/Clock/index.js.map +1 -1
- package/lib/module/components/CreatePoll.js +102 -56
- package/lib/module/components/CreatePoll.js.map +1 -1
- package/lib/module/components/GridView.js +5 -9
- package/lib/module/components/GridView.js.map +1 -1
- package/lib/module/components/HLSView.js +17 -3
- package/lib/module/components/HLSView.js.map +1 -1
- package/lib/module/components/HMSPollsQuizzesNotification.js +3 -3
- package/lib/module/components/HMSPollsQuizzesNotification.js.map +1 -1
- package/lib/module/components/LeaderboardEntry.js +126 -0
- package/lib/module/components/LeaderboardEntry.js.map +1 -0
- package/lib/module/components/PollAndQuizQuestionResponseCard.js +81 -33
- package/lib/module/components/PollAndQuizQuestionResponseCard.js.map +1 -1
- package/lib/module/components/PollAndQuizQuestionResponseCards.js +44 -0
- package/lib/module/components/PollAndQuizQuestionResponseCards.js.map +1 -0
- package/lib/module/components/PollAndQuizSheetScreen.js +60 -0
- package/lib/module/components/PollAndQuizSheetScreen.js.map +1 -0
- package/lib/module/components/PollAndQuizVoting.js +148 -20
- package/lib/module/components/PollAndQuizVoting.js.map +1 -1
- package/lib/module/components/PollQuestion.js +73 -17
- package/lib/module/components/PollQuestion.js.map +1 -1
- package/lib/module/components/PollQuestions.js +129 -15
- package/lib/module/components/PollQuestions.js.map +1 -1
- package/lib/module/components/PollsAndQuizBottomSheet.js +11 -13
- package/lib/module/components/PollsAndQuizBottomSheet.js.map +1 -1
- package/lib/module/components/PollsAndQuizzesCard.js +2 -2
- package/lib/module/components/PollsAndQuizzesCard.js.map +1 -1
- package/lib/module/components/PollsAndQuizzesModalContent.js +28 -122
- package/lib/module/components/PollsAndQuizzesModalContent.js.map +1 -1
- package/lib/module/components/PollsConfigAndList.js +82 -5
- package/lib/module/components/PollsConfigAndList.js.map +1 -1
- package/lib/module/components/PreviousPollsAndQuizzesList.js +7 -15
- package/lib/module/components/PreviousPollsAndQuizzesList.js.map +1 -1
- package/lib/module/components/QuizEndOptionsView.js +54 -0
- package/lib/module/components/QuizEndOptionsView.js.map +1 -0
- package/lib/module/components/QuizLeaderboardEntriesScreen.js +275 -0
- package/lib/module/components/QuizLeaderboardEntriesScreen.js.map +1 -0
- package/lib/module/components/QuizLeaderboardScreen.js +270 -0
- package/lib/module/components/QuizLeaderboardScreen.js.map +1 -0
- package/lib/module/components/QuizLeaderboardSummary.js +186 -0
- package/lib/module/components/QuizLeaderboardSummary.js.map +1 -0
- package/lib/module/components/RadioInput.js +10 -3
- package/lib/module/components/RadioInput.js.map +1 -1
- package/lib/module/components/RoomSettingsModalContent.js +1 -1
- package/lib/module/components/RoomSettingsModalContent.js.map +1 -1
- package/lib/module/components/TilesContainer.js +5 -6
- package/lib/module/components/TilesContainer.js.map +1 -1
- package/lib/module/components/VoterParticipationSummary.js +37 -0
- package/lib/module/components/VoterParticipationSummary.js.map +1 -0
- package/lib/module/hooks-util.js +2 -4
- package/lib/module/hooks-util.js.map +1 -1
- package/lib/module/redux/actionTypes.js +9 -1
- package/lib/module/redux/actionTypes.js.map +1 -1
- package/lib/module/redux/actions/index.js +29 -3
- package/lib/module/redux/actions/index.js.map +1 -1
- package/lib/module/redux/reducers/polls.js +96 -9
- package/lib/module/redux/reducers/polls.js.map +1 -1
- package/lib/module/utils/functions.js +43 -3
- package/lib/module/utils/functions.js.map +1 -1
- package/lib/module/utils/hooks.js +105 -2
- package/lib/module/utils/hooks.js.map +1 -1
- package/lib/typescript/HMSRoomSetup.d.ts.map +1 -1
- package/lib/typescript/Icons/Check/index.d.ts +1 -0
- package/lib/typescript/Icons/Check/index.d.ts.map +1 -1
- package/lib/typescript/Icons/CheckBox/index.d.ts +1 -0
- package/lib/typescript/Icons/CheckBox/index.d.ts.map +1 -1
- package/lib/typescript/Icons/Clock/index.d.ts +1 -0
- package/lib/typescript/Icons/Clock/index.d.ts.map +1 -1
- package/lib/typescript/components/CreatePoll.d.ts.map +1 -1
- package/lib/typescript/components/GridView.d.ts.map +1 -1
- package/lib/typescript/components/HLSView.d.ts.map +1 -1
- package/lib/typescript/components/LeaderboardEntry.d.ts +11 -0
- package/lib/typescript/components/LeaderboardEntry.d.ts.map +1 -0
- package/lib/typescript/components/PollAndQuizQuestionResponseCard.d.ts.map +1 -1
- package/lib/typescript/components/PollAndQuizQuestionResponseCards.d.ts +9 -0
- package/lib/typescript/components/PollAndQuizQuestionResponseCards.d.ts.map +1 -0
- package/lib/typescript/components/PollAndQuizSheetScreen.d.ts +8 -0
- package/lib/typescript/components/PollAndQuizSheetScreen.d.ts.map +1 -0
- package/lib/typescript/components/PollAndQuizVoting.d.ts +2 -0
- package/lib/typescript/components/PollAndQuizVoting.d.ts.map +1 -1
- package/lib/typescript/components/PollQuestion.d.ts +1 -0
- package/lib/typescript/components/PollQuestion.d.ts.map +1 -1
- package/lib/typescript/components/PollQuestions.d.ts +2 -0
- package/lib/typescript/components/PollQuestions.d.ts.map +1 -1
- package/lib/typescript/components/PollsAndQuizBottomSheet.d.ts.map +1 -1
- package/lib/typescript/components/PollsAndQuizzesModalContent.d.ts +0 -1
- package/lib/typescript/components/PollsAndQuizzesModalContent.d.ts.map +1 -1
- package/lib/typescript/components/PollsConfigAndList.d.ts +1 -0
- package/lib/typescript/components/PollsConfigAndList.d.ts.map +1 -1
- package/lib/typescript/components/PreviousPollsAndQuizzesList.d.ts.map +1 -1
- package/lib/typescript/components/QuizEndOptionsView.d.ts +10 -0
- package/lib/typescript/components/QuizEndOptionsView.d.ts.map +1 -0
- package/lib/typescript/components/QuizLeaderboardEntriesScreen.d.ts +8 -0
- package/lib/typescript/components/QuizLeaderboardEntriesScreen.d.ts.map +1 -0
- package/lib/typescript/components/QuizLeaderboardScreen.d.ts +8 -0
- package/lib/typescript/components/QuizLeaderboardScreen.d.ts.map +1 -0
- package/lib/typescript/components/QuizLeaderboardSummary.d.ts +9 -0
- package/lib/typescript/components/QuizLeaderboardSummary.d.ts.map +1 -0
- package/lib/typescript/components/RadioInput.d.ts +1 -0
- package/lib/typescript/components/RadioInput.d.ts.map +1 -1
- package/lib/typescript/components/VoterParticipationSummary.d.ts +7 -0
- package/lib/typescript/components/VoterParticipationSummary.d.ts.map +1 -0
- package/lib/typescript/hooks-util.d.ts.map +1 -1
- package/lib/typescript/redux/actionTypes.d.ts +45 -9
- package/lib/typescript/redux/actionTypes.d.ts.map +1 -1
- package/lib/typescript/redux/actions/index.d.ts +8 -2
- package/lib/typescript/redux/actions/index.d.ts.map +1 -1
- package/lib/typescript/redux/index.d.ts +2 -1
- package/lib/typescript/redux/index.d.ts.map +1 -1
- package/lib/typescript/redux/reducers/index.d.ts +2 -1
- package/lib/typescript/redux/reducers/index.d.ts.map +1 -1
- package/lib/typescript/redux/reducers/polls.d.ts +3 -2
- package/lib/typescript/redux/reducers/polls.d.ts.map +1 -1
- package/lib/typescript/utils/functions.d.ts +6 -2
- package/lib/typescript/utils/functions.d.ts.map +1 -1
- package/lib/typescript/utils/hooks.d.ts +6 -0
- package/lib/typescript/utils/hooks.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/HMSRoomSetup.tsx +25 -6
- package/src/Icons/Check/assets/check-in-circle.png +0 -0
- package/src/Icons/Check/assets/check-in-circle@2x.png +0 -0
- package/src/Icons/Check/assets/check-in-circle@3x.png +0 -0
- package/src/Icons/Check/index.tsx +9 -2
- package/src/Icons/CheckBox/index.tsx +16 -2
- package/src/Icons/Clock/assets/clock-vector.png +0 -0
- package/src/Icons/Clock/assets/clock-vector@2x.png +0 -0
- package/src/Icons/Clock/assets/clock-vector@3x.png +0 -0
- package/src/Icons/Clock/assets/clock.png +0 -0
- package/src/Icons/Clock/assets/clock@2x.png +0 -0
- package/src/Icons/Clock/assets/clock@3x.png +0 -0
- package/src/Icons/Clock/index.tsx +16 -3
- package/src/components/CreatePoll.tsx +150 -72
- package/src/components/GridView.tsx +4 -14
- package/src/components/HLSView.tsx +27 -1
- package/src/components/HMSPollsQuizzesNotification.tsx +3 -3
- package/src/components/LeaderboardEntry.tsx +172 -0
- package/src/components/PollAndQuizQuestionResponseCard.tsx +151 -48
- package/src/components/PollAndQuizQuestionResponseCards.tsx +62 -0
- package/src/components/PollAndQuizSheetScreen.tsx +85 -0
- package/src/components/PollAndQuizVoting.tsx +206 -28
- package/src/components/PollQuestion.tsx +140 -25
- package/src/components/PollQuestions.tsx +214 -74
- package/src/components/PollsAndQuizBottomSheet.tsx +20 -42
- package/src/components/PollsAndQuizzesCard.tsx +2 -2
- package/src/components/PollsAndQuizzesModalContent.tsx +40 -163
- package/src/components/PollsConfigAndList.tsx +107 -11
- package/src/components/PreviousPollsAndQuizzesList.tsx +33 -40
- package/src/components/QuizEndOptionsView.tsx +71 -0
- package/src/components/QuizLeaderboardEntriesScreen.tsx +323 -0
- package/src/components/QuizLeaderboardScreen.tsx +342 -0
- package/src/components/QuizLeaderboardSummary.tsx +207 -0
- package/src/components/RadioInput.tsx +14 -2
- package/src/components/RoomSettingsModalContent.tsx +1 -1
- package/src/components/TilesContainer.tsx +4 -4
- package/src/components/VoterParticipationSummary.tsx +67 -0
- package/src/hooks-util.ts +1 -3
- package/src/redux/actionTypes.ts +56 -6
- package/src/redux/actions/index.ts +56 -6
- package/src/redux/reducers/polls.ts +139 -11
- package/src/utils/functions.ts +90 -6
- package/src/utils/hooks.ts +190 -3
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { HMSPollQuestionType } from '@100mslive/react-native-hms';
|
|
2
|
-
import type {
|
|
1
|
+
import { HMSPollQuestionType, HMSPollType } 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,
|
|
@@ -12,21 +15,25 @@ import type {
|
|
|
12
15
|
PollsActionType,
|
|
13
16
|
} from '../actionTypes';
|
|
14
17
|
|
|
15
|
-
function getDefaultQuestionObj() {
|
|
18
|
+
function getDefaultQuestionObj(): PollQuestionUI {
|
|
16
19
|
return {
|
|
17
20
|
title: '',
|
|
18
21
|
responseEditable: false,
|
|
19
22
|
saved: false,
|
|
20
23
|
skippable: false,
|
|
24
|
+
pointWeightage: '10',
|
|
21
25
|
type: HMSPollQuestionType.singleChoice,
|
|
22
|
-
options: [
|
|
26
|
+
options: [
|
|
27
|
+
[false, ''],
|
|
28
|
+
[false, ''],
|
|
29
|
+
],
|
|
23
30
|
};
|
|
24
31
|
}
|
|
25
32
|
|
|
26
33
|
type IntialStateType = {
|
|
27
34
|
pollName: string;
|
|
28
35
|
pollConfig: PollConfig;
|
|
29
|
-
|
|
36
|
+
navigationStack: CreatePollStages[];
|
|
30
37
|
questions: PollQuestionUI[];
|
|
31
38
|
deleteConfirmationVisible: boolean;
|
|
32
39
|
selectedPollQuestionIndex: number | null;
|
|
@@ -35,15 +42,17 @@ type IntialStateType = {
|
|
|
35
42
|
cuedPollIds: HMSPoll['pollId'][]; // In case of HLSViewer, pollIds should be aligned with onCue event
|
|
36
43
|
polls: Record<string, HMSPoll>;
|
|
37
44
|
pollsResponses: Record<string, Record<number, number | number[]>>;
|
|
45
|
+
leaderboards: Record<string, PollLeaderboardResponse>;
|
|
38
46
|
};
|
|
39
47
|
|
|
40
48
|
const INITIAL_STATE: IntialStateType = {
|
|
41
49
|
pollName: '',
|
|
42
50
|
pollConfig: {
|
|
51
|
+
type: HMSPollType.poll,
|
|
43
52
|
voteCountHidden: false,
|
|
44
53
|
resultsAnonymous: false,
|
|
45
54
|
},
|
|
46
|
-
|
|
55
|
+
navigationStack: [CreatePollStages.POLL_CONFIG],
|
|
47
56
|
questions: [getDefaultQuestionObj()],
|
|
48
57
|
deleteConfirmationVisible: false,
|
|
49
58
|
selectedPollQuestionIndex: null,
|
|
@@ -52,6 +61,7 @@ const INITIAL_STATE: IntialStateType = {
|
|
|
52
61
|
cuedPollIds: [],
|
|
53
62
|
polls: {},
|
|
54
63
|
pollsResponses: {},
|
|
64
|
+
leaderboards: {},
|
|
55
65
|
};
|
|
56
66
|
|
|
57
67
|
const hmsStatesReducer = (
|
|
@@ -76,13 +86,36 @@ const hmsStatesReducer = (
|
|
|
76
86
|
...state.pollConfig,
|
|
77
87
|
...action.pollConfig,
|
|
78
88
|
},
|
|
89
|
+
questions:
|
|
90
|
+
'type' in action.pollConfig
|
|
91
|
+
? state.questions.map((ques) => ({ ...ques, saved: false }))
|
|
92
|
+
: state.questions,
|
|
79
93
|
selectedPollQuestionIndex: null,
|
|
80
94
|
};
|
|
81
|
-
case PollsStateActionTypes.
|
|
95
|
+
case PollsStateActionTypes.PUSH_TO_NAVIGATION_STACK:
|
|
82
96
|
return {
|
|
83
97
|
...state,
|
|
84
|
-
|
|
85
|
-
|
|
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,
|
|
86
119
|
};
|
|
87
120
|
case PollsStateActionTypes.ADD_POLL_QUESTION:
|
|
88
121
|
return {
|
|
@@ -144,6 +177,18 @@ const hmsStatesReducer = (
|
|
|
144
177
|
: question
|
|
145
178
|
),
|
|
146
179
|
};
|
|
180
|
+
case PollsStateActionTypes.SET_POINT_WEIGHTAGE:
|
|
181
|
+
return {
|
|
182
|
+
...state,
|
|
183
|
+
questions: state.questions.map((question, idx) =>
|
|
184
|
+
idx === action.questionIndex
|
|
185
|
+
? {
|
|
186
|
+
...question,
|
|
187
|
+
pointWeightage: action.pointWeightage,
|
|
188
|
+
}
|
|
189
|
+
: question
|
|
190
|
+
),
|
|
191
|
+
};
|
|
147
192
|
case PollsStateActionTypes.ADD_QUESTION_OPTION:
|
|
148
193
|
return {
|
|
149
194
|
...state,
|
|
@@ -151,7 +196,7 @@ const hmsStatesReducer = (
|
|
|
151
196
|
idx === action.questionIndex
|
|
152
197
|
? {
|
|
153
198
|
...question,
|
|
154
|
-
options: [...(question.options || []), ''],
|
|
199
|
+
options: [...(question.options || []), [false, '']],
|
|
155
200
|
}
|
|
156
201
|
: question
|
|
157
202
|
),
|
|
@@ -180,12 +225,41 @@ const hmsStatesReducer = (
|
|
|
180
225
|
options:
|
|
181
226
|
question.options &&
|
|
182
227
|
question.options.map((option, idx) =>
|
|
183
|
-
idx === action.optionIndex
|
|
228
|
+
idx === action.optionIndex
|
|
229
|
+
? [option[0], action.option]
|
|
230
|
+
: option
|
|
184
231
|
),
|
|
185
232
|
}
|
|
186
233
|
: question
|
|
187
234
|
),
|
|
188
235
|
};
|
|
236
|
+
case PollsStateActionTypes.SET_QUESTION_CORRECT_OPTION:
|
|
237
|
+
return {
|
|
238
|
+
...state,
|
|
239
|
+
questions: state.questions.map((question, idx) =>
|
|
240
|
+
idx === action.questionIndex
|
|
241
|
+
? {
|
|
242
|
+
...question,
|
|
243
|
+
options:
|
|
244
|
+
question.options &&
|
|
245
|
+
question.options.map((option, idx) => {
|
|
246
|
+
if (
|
|
247
|
+
action.correctOption === false ||
|
|
248
|
+
question.type === HMSPollQuestionType.multipleChoice
|
|
249
|
+
) {
|
|
250
|
+
return idx === action.optionIndex
|
|
251
|
+
? [action.correctOption, option[1]]
|
|
252
|
+
: option;
|
|
253
|
+
}
|
|
254
|
+
return [
|
|
255
|
+
idx === action.optionIndex ? true : false,
|
|
256
|
+
option[1],
|
|
257
|
+
];
|
|
258
|
+
}),
|
|
259
|
+
}
|
|
260
|
+
: question
|
|
261
|
+
),
|
|
262
|
+
};
|
|
189
263
|
case PollsStateActionTypes.SET_QUESTION_SKIPPABLE:
|
|
190
264
|
return {
|
|
191
265
|
...state,
|
|
@@ -236,6 +310,51 @@ const hmsStatesReducer = (
|
|
|
236
310
|
selectedPollId: action.pollId,
|
|
237
311
|
};
|
|
238
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
|
+
|
|
239
358
|
return {
|
|
240
359
|
...state,
|
|
241
360
|
polls: {
|
|
@@ -310,6 +429,15 @@ const hmsStatesReducer = (
|
|
|
310
429
|
cuedPollIds: [...state.cuedPollIds, action.pollId],
|
|
311
430
|
};
|
|
312
431
|
}
|
|
432
|
+
case PollsStateActionTypes.ADD_LEADERBOARD: {
|
|
433
|
+
return {
|
|
434
|
+
...state,
|
|
435
|
+
leaderboards: {
|
|
436
|
+
...state.leaderboards,
|
|
437
|
+
[action.pollId]: action.leaderboard,
|
|
438
|
+
},
|
|
439
|
+
};
|
|
440
|
+
}
|
|
313
441
|
case PollsStateActionTypes.CLEAR_POLL_FORM_STATE: {
|
|
314
442
|
return {
|
|
315
443
|
...INITIAL_STATE,
|
package/src/utils/functions.ts
CHANGED
|
@@ -12,9 +12,15 @@ import {
|
|
|
12
12
|
HMSTrackSource,
|
|
13
13
|
HMSVideoTrack,
|
|
14
14
|
HMSRole,
|
|
15
|
-
|
|
15
|
+
HMSPollQuestionType,
|
|
16
|
+
} from '@100mslive/react-native-hms';
|
|
17
|
+
import type {
|
|
18
|
+
HMSPoll,
|
|
19
|
+
HMSPollQuestionAnswer,
|
|
20
|
+
HMSPollQuestionResponse,
|
|
21
|
+
HMSPollQuestion,
|
|
22
|
+
HMSPollQuestionOption,
|
|
16
23
|
} from '@100mslive/react-native-hms';
|
|
17
|
-
import type { HMSPoll } from '@100mslive/react-native-hms';
|
|
18
24
|
|
|
19
25
|
import type { PeerTrackNode } from './types';
|
|
20
26
|
|
|
@@ -479,9 +485,87 @@ export const visiblePollsSelector = (
|
|
|
479
485
|
isHLSViewer: boolean,
|
|
480
486
|
hlsCuedPollIds: HMSPoll['pollId'][]
|
|
481
487
|
) => {
|
|
482
|
-
return polls.filter(
|
|
483
|
-
(poll)
|
|
484
|
-
poll.type !== HMSPollType.quiz &&
|
|
485
|
-
(isHLSViewer ? hlsCuedPollIds.includes(poll.pollId) : true) // Hiding quizzes from UI
|
|
488
|
+
return polls.filter((poll) =>
|
|
489
|
+
isHLSViewer ? hlsCuedPollIds.includes(poll.pollId) : true
|
|
486
490
|
);
|
|
487
491
|
};
|
|
492
|
+
|
|
493
|
+
export function checkIsSelected(
|
|
494
|
+
pollQuestion: HMSPollQuestion,
|
|
495
|
+
option: HMSPollQuestionOption,
|
|
496
|
+
selectedOptions: number | number[] | null
|
|
497
|
+
) {
|
|
498
|
+
return pollQuestion.myResponses.length > 0
|
|
499
|
+
? pollQuestion.type === HMSPollQuestionType.singleChoice
|
|
500
|
+
? !!pollQuestion.myResponses.find((r) => r.option === option.index)
|
|
501
|
+
: !!pollQuestion.myResponses.find((r) =>
|
|
502
|
+
r.options ? r.options.includes(option.index) : false
|
|
503
|
+
)
|
|
504
|
+
: Array.isArray(selectedOptions)
|
|
505
|
+
? selectedOptions.includes(option.index)
|
|
506
|
+
: selectedOptions === option.index;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
export function checkIsCorrectAnswer(
|
|
510
|
+
questionType: HMSPollQuestionType,
|
|
511
|
+
myResponses: HMSPollQuestionResponse[] | undefined,
|
|
512
|
+
answer: HMSPollQuestionAnswer | undefined
|
|
513
|
+
) {
|
|
514
|
+
if (!myResponses || myResponses.length < 0 || !answer) {
|
|
515
|
+
return false;
|
|
516
|
+
}
|
|
517
|
+
const correctAnswer =
|
|
518
|
+
questionType === HMSPollQuestionType.multipleChoice
|
|
519
|
+
? answer.options
|
|
520
|
+
: answer.option;
|
|
521
|
+
|
|
522
|
+
if (correctAnswer === undefined) {
|
|
523
|
+
return false;
|
|
524
|
+
}
|
|
525
|
+
if (Array.isArray(correctAnswer)) {
|
|
526
|
+
return myResponses.every(
|
|
527
|
+
(r) =>
|
|
528
|
+
r.options &&
|
|
529
|
+
r.options.length === correctAnswer.length &&
|
|
530
|
+
r.options.every((o) => correctAnswer.includes(o))
|
|
531
|
+
);
|
|
532
|
+
}
|
|
533
|
+
return myResponses.every((r) => r.option === correctAnswer);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
export function checkIsCorrectOption(
|
|
537
|
+
questionType: HMSPollQuestionType,
|
|
538
|
+
option: HMSPollQuestionOption,
|
|
539
|
+
answer: HMSPollQuestionAnswer | undefined
|
|
540
|
+
) {
|
|
541
|
+
if (!answer) {
|
|
542
|
+
return false;
|
|
543
|
+
}
|
|
544
|
+
const correctAnswer =
|
|
545
|
+
questionType === HMSPollQuestionType.multipleChoice
|
|
546
|
+
? answer.options
|
|
547
|
+
: answer.option;
|
|
548
|
+
|
|
549
|
+
if (correctAnswer === undefined) {
|
|
550
|
+
return false;
|
|
551
|
+
}
|
|
552
|
+
if (Array.isArray(correctAnswer)) {
|
|
553
|
+
return correctAnswer.includes(option.index);
|
|
554
|
+
}
|
|
555
|
+
return option.index === correctAnswer;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
export function getLabelFromPollQuestionType(
|
|
559
|
+
type: HMSPollQuestionType
|
|
560
|
+
): string {
|
|
561
|
+
switch (type) {
|
|
562
|
+
case HMSPollQuestionType.singleChoice:
|
|
563
|
+
return 'Single Choice';
|
|
564
|
+
case HMSPollQuestionType.multipleChoice:
|
|
565
|
+
return 'Multiple Choice';
|
|
566
|
+
case HMSPollQuestionType.longAnswer:
|
|
567
|
+
return 'Long Answer';
|
|
568
|
+
case HMSPollQuestionType.shortAnswer:
|
|
569
|
+
return 'Short Answer';
|
|
570
|
+
}
|
|
571
|
+
}
|
package/src/utils/hooks.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
1
|
+
import { useEffect, useMemo } from 'react';
|
|
2
2
|
import { useDispatch, useSelector } from 'react-redux';
|
|
3
3
|
import {
|
|
4
4
|
HMSLocalAudioStats,
|
|
@@ -13,10 +13,12 @@ import {
|
|
|
13
13
|
HMSTrackSource,
|
|
14
14
|
HMSUpdateListenerActions,
|
|
15
15
|
} from '@100mslive/react-native-hms';
|
|
16
|
+
import type { HMSPoll } from '@100mslive/react-native-hms';
|
|
16
17
|
|
|
17
|
-
import type { RootState } from '../redux';
|
|
18
|
-
import { setRTCStats } from '../redux/actions';
|
|
19
18
|
import { ModalTypes } from './types';
|
|
19
|
+
import type { RootState } from '../redux';
|
|
20
|
+
import { addLeaderboard, setRTCStats } from '../redux/actions';
|
|
21
|
+
import { useHMSInstance } from '../hooks-util';
|
|
20
22
|
|
|
21
23
|
export const useRTCStatsListeners = () => {
|
|
22
24
|
const dispatch = useDispatch();
|
|
@@ -102,3 +104,188 @@ export const useRTCStatsListeners = () => {
|
|
|
102
104
|
}
|
|
103
105
|
}, [hmsInstance, addListeners]);
|
|
104
106
|
};
|
|
107
|
+
|
|
108
|
+
export const useFetchLeaderboardResponse = (
|
|
109
|
+
pollId: HMSPoll['pollId'] | undefined
|
|
110
|
+
) => {
|
|
111
|
+
const dispatch = useDispatch();
|
|
112
|
+
const hmsInstance = useHMSInstance();
|
|
113
|
+
|
|
114
|
+
const hasPollWritePermission = useSelector((state: RootState) => {
|
|
115
|
+
const permissions = state.hmsStates.localPeer?.role?.permissions;
|
|
116
|
+
return permissions?.pollWrite;
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const leaderboardData = useSelector((state: RootState) => {
|
|
120
|
+
if (!pollId) return null;
|
|
121
|
+
return state.polls.leaderboards[pollId] || null;
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const leaderboardDataExist = !!leaderboardData;
|
|
125
|
+
|
|
126
|
+
useEffect(() => {
|
|
127
|
+
if (!!leaderboardData) return;
|
|
128
|
+
|
|
129
|
+
let mounted = true;
|
|
130
|
+
|
|
131
|
+
async function fetchLeaderboard() {
|
|
132
|
+
if (pollId) {
|
|
133
|
+
const response = await hmsInstance.interactivityCenter.fetchLeaderboard(
|
|
134
|
+
pollId,
|
|
135
|
+
5,
|
|
136
|
+
1, // Indexing starts from 1
|
|
137
|
+
!hasPollWritePermission // fetchCurrentUser only if user has only pollRead permission
|
|
138
|
+
);
|
|
139
|
+
if (mounted) {
|
|
140
|
+
dispatch(addLeaderboard(pollId, response));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
fetchLeaderboard();
|
|
145
|
+
|
|
146
|
+
return () => {
|
|
147
|
+
mounted = false;
|
|
148
|
+
};
|
|
149
|
+
}, [pollId, leaderboardDataExist, hasPollWritePermission]);
|
|
150
|
+
|
|
151
|
+
return leaderboardData;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export const useLeaderboardSummaryData = (
|
|
155
|
+
pollId: HMSPoll['pollId'] | undefined
|
|
156
|
+
): { label: string; value: any }[][] | null => {
|
|
157
|
+
const localPeerUserId = useSelector(
|
|
158
|
+
(state: RootState) => state.hmsStates.localPeer?.customerUserID
|
|
159
|
+
);
|
|
160
|
+
const localPeerPollInitiator = useSelector((state: RootState) => {
|
|
161
|
+
if (!pollId) return null;
|
|
162
|
+
const pollInitiatorUserID =
|
|
163
|
+
state.polls.polls[pollId]?.createdBy?.customerUserID;
|
|
164
|
+
return (
|
|
165
|
+
localPeerUserId &&
|
|
166
|
+
pollInitiatorUserID &&
|
|
167
|
+
localPeerUserId === pollInitiatorUserID
|
|
168
|
+
);
|
|
169
|
+
});
|
|
170
|
+
const canCreateOrEndPoll = useSelector((state: RootState) => {
|
|
171
|
+
const permissions = state.hmsStates.localPeer?.role?.permissions;
|
|
172
|
+
return permissions?.pollWrite;
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
const leaderboardData = useSelector((state: RootState) => {
|
|
176
|
+
if (!pollId) return null;
|
|
177
|
+
return state.polls.leaderboards[pollId] || null;
|
|
178
|
+
});
|
|
179
|
+
const pollQuestionsLength = useSelector((state: RootState) => {
|
|
180
|
+
if (!pollId) return null;
|
|
181
|
+
return state.polls.polls[pollId]?.questions?.length;
|
|
182
|
+
});
|
|
183
|
+
const leaderboardSummary = leaderboardData?.summary;
|
|
184
|
+
|
|
185
|
+
const pollInitiatorSummaryData = useMemo(() => {
|
|
186
|
+
if (!localPeerPollInitiator) {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
return [
|
|
190
|
+
[
|
|
191
|
+
{
|
|
192
|
+
label: 'ANSWERED',
|
|
193
|
+
value:
|
|
194
|
+
leaderboardSummary &&
|
|
195
|
+
typeof leaderboardSummary.respondedPeersCount === 'number' &&
|
|
196
|
+
typeof leaderboardSummary.totalPeersCount === 'number'
|
|
197
|
+
? `${Math.round((leaderboardSummary.respondedPeersCount / leaderboardSummary.totalPeersCount) * 100)}% (${leaderboardSummary.respondedPeersCount}/${leaderboardSummary.totalPeersCount})`
|
|
198
|
+
: '-',
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
label: 'CORRECT ANSWERS',
|
|
202
|
+
value:
|
|
203
|
+
leaderboardSummary &&
|
|
204
|
+
typeof leaderboardSummary.respondedCorrectlyPeersCount ===
|
|
205
|
+
'number' &&
|
|
206
|
+
typeof leaderboardSummary.totalPeersCount === 'number'
|
|
207
|
+
? `${Math.round((leaderboardSummary.respondedCorrectlyPeersCount / leaderboardSummary?.totalPeersCount) * 100)}% (${leaderboardSummary.respondedCorrectlyPeersCount}/${leaderboardSummary.totalPeersCount})`
|
|
208
|
+
: '-',
|
|
209
|
+
},
|
|
210
|
+
],
|
|
211
|
+
[
|
|
212
|
+
{
|
|
213
|
+
label: 'AVG. TIME TAKEN',
|
|
214
|
+
value:
|
|
215
|
+
leaderboardSummary &&
|
|
216
|
+
typeof leaderboardSummary.averageTime === 'number'
|
|
217
|
+
? `${(leaderboardSummary.averageTime / 1000).toFixed(2)}s`
|
|
218
|
+
: '-', // averageTime is in milliseconds
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
label: 'AVG. SCORE',
|
|
222
|
+
value:
|
|
223
|
+
leaderboardSummary &&
|
|
224
|
+
typeof leaderboardSummary.averageScore === 'number'
|
|
225
|
+
? leaderboardSummary.averageScore.toFixed(2)
|
|
226
|
+
: '-',
|
|
227
|
+
},
|
|
228
|
+
],
|
|
229
|
+
];
|
|
230
|
+
}, [leaderboardSummary, localPeerPollInitiator]);
|
|
231
|
+
|
|
232
|
+
const localLeaderboardEntry =
|
|
233
|
+
localPeerUserId && leaderboardData && Array.isArray(leaderboardData.entries)
|
|
234
|
+
? leaderboardData.entries.find(
|
|
235
|
+
(entry) => entry.peer?.customerUserId === localPeerUserId
|
|
236
|
+
)
|
|
237
|
+
: null;
|
|
238
|
+
|
|
239
|
+
const voterSummaryData = useMemo(() => {
|
|
240
|
+
if (!localLeaderboardEntry || canCreateOrEndPoll) {
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
return [
|
|
244
|
+
[
|
|
245
|
+
{
|
|
246
|
+
label: 'YOUR RANK',
|
|
247
|
+
value:
|
|
248
|
+
localLeaderboardEntry &&
|
|
249
|
+
typeof localLeaderboardEntry.totalResponses === 'number' &&
|
|
250
|
+
leaderboardSummary &&
|
|
251
|
+
typeof leaderboardSummary.totalPeersCount === 'number'
|
|
252
|
+
? `${localLeaderboardEntry.position}/${leaderboardSummary.totalPeersCount}`
|
|
253
|
+
: '-',
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
label: 'CORRECT ANSWERS',
|
|
257
|
+
value:
|
|
258
|
+
localLeaderboardEntry &&
|
|
259
|
+
typeof localLeaderboardEntry.correctResponses === 'number' &&
|
|
260
|
+
typeof pollQuestionsLength === 'number'
|
|
261
|
+
? `${Math.round((localLeaderboardEntry.correctResponses / pollQuestionsLength) * 100)}% (${localLeaderboardEntry.correctResponses}/${pollQuestionsLength})`
|
|
262
|
+
: '-',
|
|
263
|
+
},
|
|
264
|
+
],
|
|
265
|
+
[
|
|
266
|
+
{
|
|
267
|
+
label: 'TIME TAKEN',
|
|
268
|
+
value:
|
|
269
|
+
localLeaderboardEntry &&
|
|
270
|
+
typeof localLeaderboardEntry.duration === 'number'
|
|
271
|
+
? `${(localLeaderboardEntry.duration / 1000).toFixed(2)}s`
|
|
272
|
+
: '-',
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
label: 'YOUR POINTS',
|
|
276
|
+
value:
|
|
277
|
+
localLeaderboardEntry &&
|
|
278
|
+
typeof localLeaderboardEntry.score === 'number'
|
|
279
|
+
? localLeaderboardEntry.score
|
|
280
|
+
: '-',
|
|
281
|
+
},
|
|
282
|
+
],
|
|
283
|
+
];
|
|
284
|
+
}, [localLeaderboardEntry, leaderboardSummary?.totalPeersCount]);
|
|
285
|
+
|
|
286
|
+
return localPeerPollInitiator
|
|
287
|
+
? pollInitiatorSummaryData
|
|
288
|
+
: voterSummaryData
|
|
289
|
+
? voterSummaryData
|
|
290
|
+
: null;
|
|
291
|
+
};
|