be-components 2.0.0 → 2.0.2
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/lib/commonjs/Components/Icons.js +50 -0
- package/lib/commonjs/Components/Icons.js.map +1 -1
- package/lib/commonjs/MarketComponents/api/index.js +50 -0
- package/lib/commonjs/MarketComponents/api/index.js.map +1 -1
- package/lib/commonjs/MarketComponents/components/ContestStats.js +293 -0
- package/lib/commonjs/MarketComponents/components/ContestStats.js.map +1 -0
- package/lib/commonjs/MarketComponents/components/EventScoringCard.js +86 -0
- package/lib/commonjs/MarketComponents/components/EventScoringCard.js.map +1 -0
- package/lib/commonjs/MarketComponents/components/TeamEventMarket/index.js +26 -6
- package/lib/commonjs/MarketComponents/components/TeamEventMarket/index.js.map +1 -1
- package/lib/commonjs/Poll/components/CampaignLeaderboard.js +21 -26
- package/lib/commonjs/Poll/components/CampaignLeaderboard.js.map +1 -1
- package/lib/commonjs/Poll/components/CampaignPlay.js +1 -7
- package/lib/commonjs/Poll/components/CampaignPlay.js.map +1 -1
- package/lib/commonjs/Poll/components/CampaignResult.js +1 -19
- package/lib/commonjs/Poll/components/CampaignResult.js.map +1 -1
- package/lib/commonjs/Poll/components/PollCard.js +87 -152
- package/lib/commonjs/Poll/components/PollCard.js.map +1 -1
- package/lib/commonjs/Poll/components/PollQuestionsSection.js +11 -3
- package/lib/commonjs/Poll/components/PollQuestionsSection.js.map +1 -1
- package/lib/commonjs/Poll/index.js +83 -14
- package/lib/commonjs/Poll/index.js.map +1 -1
- package/lib/module/Components/Icons.js +50 -0
- package/lib/module/Components/Icons.js.map +1 -1
- package/lib/module/MarketComponents/api/index.js +50 -0
- package/lib/module/MarketComponents/api/index.js.map +1 -1
- package/lib/module/MarketComponents/components/ContestStats.js +284 -0
- package/lib/module/MarketComponents/components/ContestStats.js.map +1 -0
- package/lib/module/MarketComponents/components/EventScoringCard.js +79 -0
- package/lib/module/MarketComponents/components/EventScoringCard.js.map +1 -0
- package/lib/module/MarketComponents/components/TeamEventMarket/index.js +26 -6
- package/lib/module/MarketComponents/components/TeamEventMarket/index.js.map +1 -1
- package/lib/module/Poll/components/CampaignLeaderboard.js +21 -26
- package/lib/module/Poll/components/CampaignLeaderboard.js.map +1 -1
- package/lib/module/Poll/components/CampaignPlay.js +1 -7
- package/lib/module/Poll/components/CampaignPlay.js.map +1 -1
- package/lib/module/Poll/components/CampaignResult.js +1 -20
- package/lib/module/Poll/components/CampaignResult.js.map +1 -1
- package/lib/module/Poll/components/PollCard.js +89 -154
- package/lib/module/Poll/components/PollCard.js.map +1 -1
- package/lib/module/Poll/components/PollQuestionsSection.js +11 -3
- package/lib/module/Poll/components/PollQuestionsSection.js.map +1 -1
- package/lib/module/Poll/index.js +85 -16
- package/lib/module/Poll/index.js.map +1 -1
- package/lib/typescript/src/Components/Icons.d.ts +1 -0
- package/lib/typescript/src/Components/Icons.d.ts.map +1 -1
- package/lib/typescript/src/MarketComponents/api/index.d.ts +4 -1
- package/lib/typescript/src/MarketComponents/api/index.d.ts.map +1 -1
- package/lib/typescript/src/MarketComponents/components/ContestStats.d.ts +8 -0
- package/lib/typescript/src/MarketComponents/components/ContestStats.d.ts.map +1 -0
- package/lib/typescript/src/MarketComponents/components/EventScoringCard.d.ts +8 -0
- package/lib/typescript/src/MarketComponents/components/EventScoringCard.d.ts.map +1 -0
- package/lib/typescript/src/MarketComponents/components/TeamEventMarket/index.d.ts.map +1 -1
- package/lib/typescript/src/MarketComponents/index.d.ts.map +1 -1
- package/lib/typescript/src/Poll/components/CampaignLeaderboard.d.ts.map +1 -1
- package/lib/typescript/src/Poll/components/CampaignPlay.d.ts.map +1 -1
- package/lib/typescript/src/Poll/components/CampaignResult.d.ts.map +1 -1
- package/lib/typescript/src/Poll/components/PollCard.d.ts +7 -6
- package/lib/typescript/src/Poll/components/PollCard.d.ts.map +1 -1
- package/lib/typescript/src/Poll/components/PollQuestionsSection.d.ts +1 -1
- package/lib/typescript/src/Poll/components/PollQuestionsSection.d.ts.map +1 -1
- package/lib/typescript/src/Poll/index.d.ts +3 -1
- package/lib/typescript/src/Poll/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Components/Icons.tsx +24 -0
- package/src/MarketComponents/api/index.ts +42 -1
- package/src/MarketComponents/components/ContestStats.tsx +194 -0
- package/src/MarketComponents/components/EventScoringCard.tsx +53 -0
- package/src/MarketComponents/components/TeamEventMarket/index.tsx +27 -4
- package/src/Poll/components/CampaignLeaderboard.tsx +7 -9
- package/src/Poll/components/CampaignPlay.tsx +2 -5
- package/src/Poll/components/CampaignResult.tsx +1 -20
- package/src/Poll/components/PollCard.tsx +75 -122
- package/src/Poll/components/PollQuestionsSection.tsx +6 -4
- package/src/Poll/index.tsx +64 -13
- package/src/types.d.ts +13 -0
|
@@ -1,92 +1,76 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FlatList, Image, ScrollView, TouchableOpacity, View } from 'react-native';
|
|
2
2
|
import React, { useEffect, useState } from 'react';
|
|
3
3
|
import PollOptionCard from './PollOptionCard';
|
|
4
4
|
import ResponseTimer from './ResponseTimer';
|
|
5
5
|
import type { PollOptionProps, PollProps, PollResponseProps, PollSummaryProps } from '../../types';
|
|
6
|
-
import { PollApi
|
|
6
|
+
import { PollApi } from '../api';
|
|
7
7
|
import { Button, Icons, Text } from '../../Components';
|
|
8
8
|
import Colors from '../../constants/colors';
|
|
9
9
|
import { view_styles } from '../../constants/styles';
|
|
10
10
|
|
|
11
11
|
type PollCardProps = {
|
|
12
|
-
|
|
12
|
+
poll_id:string,
|
|
13
|
+
poll_response?:PollResponseProps,
|
|
14
|
+
action_loading?:boolean,
|
|
13
15
|
question_number?:number,
|
|
14
|
-
onCancel:() => void,
|
|
15
16
|
view?:string,
|
|
16
|
-
onResponse:(response:PollResponseProps) => void,
|
|
17
17
|
total_questions?:number,
|
|
18
|
+
onResponse:(response:PollResponseProps) => void,
|
|
18
19
|
onShowAuthenticate: () => void,
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
onCancel:() => void,
|
|
21
|
+
onSkip: () => void
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
const PollCard = ({ poll, question_number, total_questions, onSkip, onCancel, onSeeResults, onResponse }: PollCardProps) => {
|
|
26
|
-
const [ loading, setLoading ] = useState(false);
|
|
27
|
-
const [ submit_loading, setSubmitLoading ] = useState(false);
|
|
24
|
+
const PollCard = ({ poll_id, poll_response, action_loading, onSkip, onCancel, onResponse }: PollCardProps) => {
|
|
28
25
|
const [ poll_width, setPollWidth ] = useState(0);
|
|
29
|
-
const [ option_selected, setOptionSelected ] = useState<undefined|PollOptionProps>(undefined);
|
|
30
26
|
const [ poll_data, setPollData ] = useState<{
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
poll?:PollProps,
|
|
28
|
+
loading:boolean,
|
|
29
|
+
selected_option?:PollOptionProps,
|
|
30
|
+
poll_summaries:PollSummaryProps[],
|
|
34
31
|
poll_options:PollOptionProps[],
|
|
35
|
-
poll_summaries:PollSummaryProps[]
|
|
36
32
|
}>({
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
poll_options:[]
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
const correct_option = poll_options.find(po => po.result_ind == 'win')
|
|
46
|
-
const selected_option = poll_options.find(po => po.poll_option_id == poll_response?.poll_option_id)
|
|
47
|
-
|
|
48
|
-
const last_question = question_number && total_questions && question_number == total_questions ? true : false
|
|
49
|
-
|
|
33
|
+
loading:false,
|
|
34
|
+
poll_summaries:[],
|
|
35
|
+
poll_options:[]
|
|
36
|
+
});
|
|
37
|
+
const { loading, poll, poll_summaries, poll_options, selected_option } = poll_data;
|
|
38
|
+
const correct_option = poll_options.find(o => o.result_ind == 'win');
|
|
39
|
+
const responses = poll_summaries.reduce((a,b) => a + b.count, 0)
|
|
50
40
|
useEffect(() => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
41
|
+
getPollFromServer(poll_id)
|
|
42
|
+
},[poll_id])
|
|
43
|
+
|
|
55
44
|
const getPollFromServer = async(poll_id:string) => {
|
|
56
|
-
|
|
57
|
-
let poll_response = await PollResponseApi.getResponseByPollId(poll_id)
|
|
45
|
+
setPollData({ ...poll_data, loading: true });
|
|
58
46
|
const pos_resp = await PollApi.getPollById(poll_id)
|
|
59
47
|
setPollData({
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
48
|
+
...poll_data,
|
|
49
|
+
loading:false,
|
|
50
|
+
poll:pos_resp.poll,
|
|
63
51
|
poll_options:pos_resp.poll_options,
|
|
64
52
|
poll_summaries: pos_resp.poll_summaries
|
|
65
53
|
})
|
|
66
|
-
setLoading(false);
|
|
67
54
|
}
|
|
68
55
|
|
|
69
56
|
const handleCancel = () => {
|
|
70
|
-
|
|
71
|
-
|
|
57
|
+
setPollData({ ...poll_data, selected_option:undefined })
|
|
72
58
|
onCancel()
|
|
73
59
|
}
|
|
74
60
|
|
|
75
61
|
const handleSkip = () => {
|
|
76
62
|
//if(!is_authenticated){ return onShowAuthenticate() }
|
|
77
|
-
setPollData(DEFAULT_POLL_STATE)
|
|
78
|
-
setOptionSelected(undefined)
|
|
79
|
-
if(last_question && onSeeResults){ return onSeeResults() }
|
|
63
|
+
//setPollData(DEFAULT_POLL_STATE)
|
|
64
|
+
//setOptionSelected(undefined)
|
|
65
|
+
//if(last_question && onSeeResults){ return onSeeResults() }
|
|
80
66
|
onSkip()
|
|
81
67
|
|
|
82
68
|
}
|
|
83
69
|
|
|
84
70
|
const handleSubmitResponse = async() => {
|
|
85
71
|
//if(!is_authenticated){ return onShowAuthenticate() }
|
|
86
|
-
if(
|
|
87
|
-
|
|
88
|
-
if(responded || poll_response){ return }
|
|
89
|
-
let option = poll_options.find(po => po.poll_option_id == option_selected.poll_option_id)
|
|
72
|
+
if(action_loading || poll_response || !selected_option || !poll){ return }
|
|
73
|
+
let option = poll_options.find(po => po.poll_option_id == selected_option.poll_option_id)
|
|
90
74
|
if(!option){ return }
|
|
91
75
|
//We are good to log the response!
|
|
92
76
|
let draft_response:PollResponseProps = {
|
|
@@ -103,34 +87,17 @@ const PollCard = ({ poll, question_number, total_questions, onSkip, onCancel, on
|
|
|
103
87
|
last_update_datetime: ''
|
|
104
88
|
}
|
|
105
89
|
if(option.option_type == 'input'){
|
|
106
|
-
draft_response.input_value =
|
|
107
|
-
}
|
|
108
|
-
try {
|
|
109
|
-
setSubmitLoading(true)
|
|
110
|
-
let poll_response = await PollResponseApi.createPollResponse(draft_response)
|
|
111
|
-
onResponse(poll_response)
|
|
112
|
-
setPollData({
|
|
113
|
-
...poll_data,
|
|
114
|
-
server_checked: true,
|
|
115
|
-
responded: poll_response?true:false,
|
|
116
|
-
poll_response
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
setOptionSelected(undefined)
|
|
120
|
-
setSubmitLoading(false)
|
|
121
|
-
} catch (e) {
|
|
122
|
-
setSubmitLoading(false)
|
|
123
|
-
setOptionSelected(undefined)
|
|
90
|
+
draft_response.input_value = selected_option.option_value
|
|
124
91
|
}
|
|
92
|
+
onResponse(draft_response);
|
|
125
93
|
}
|
|
126
94
|
|
|
127
95
|
const handleTimesUp = async() => {
|
|
128
|
-
if(
|
|
96
|
+
if(selected_option){
|
|
129
97
|
return handleSubmitResponse()
|
|
130
98
|
}
|
|
131
99
|
if(!poll || poll.status != 'active'){ return }
|
|
132
|
-
if(
|
|
133
|
-
if(responded){ return }
|
|
100
|
+
if(poll_response){ return }
|
|
134
101
|
const draft_response:PollResponseProps = {
|
|
135
102
|
poll_id:poll.poll_id,
|
|
136
103
|
poll_option_id:'0',
|
|
@@ -145,21 +112,14 @@ const PollCard = ({ poll, question_number, total_questions, onSkip, onCancel, on
|
|
|
145
112
|
create_datetime: '',
|
|
146
113
|
last_update_datetime: ''
|
|
147
114
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
onResponse(poll_response);
|
|
151
|
-
setSubmitLoading(false)
|
|
152
|
-
setPollData({
|
|
153
|
-
...poll_data,
|
|
154
|
-
server_checked: true,
|
|
155
|
-
responded: poll_response ? true : false,
|
|
156
|
-
poll_response
|
|
157
|
-
})
|
|
115
|
+
onResponse(draft_response)
|
|
116
|
+
|
|
158
117
|
}
|
|
159
118
|
|
|
160
119
|
const renderPollOptions = (data: { item:PollOptionProps, index:number }) => {
|
|
120
|
+
if(!poll){ return <></ >}
|
|
161
121
|
const poll_summary = poll_summaries.find(ps => ps.poll_option_id == data.item.poll_option_id);
|
|
162
|
-
const draft_selected =
|
|
122
|
+
const draft_selected = selected_option?.poll_option_id == data.item.poll_option_id ? true : false;
|
|
163
123
|
return (
|
|
164
124
|
<View style={{ margin:5, flex:1 }}>
|
|
165
125
|
<PollOptionCard
|
|
@@ -167,28 +127,35 @@ const PollCard = ({ poll, question_number, total_questions, onSkip, onCancel, on
|
|
|
167
127
|
draft_selected={draft_selected}
|
|
168
128
|
poll_response={poll_response}
|
|
169
129
|
poll_option={data.item}
|
|
170
|
-
show_summary={(
|
|
130
|
+
show_summary={(poll_response) && poll.show_responses ? true : false}
|
|
171
131
|
onSelect={(poll_option) => {
|
|
172
|
-
if(
|
|
132
|
+
if(poll_response){ return }
|
|
173
133
|
if(poll?.status !== 'active'){ return }
|
|
174
|
-
if(draft_selected){
|
|
175
|
-
|
|
176
|
-
|
|
134
|
+
if(draft_selected){
|
|
135
|
+
setPollData({ ...poll_data, selected_option: undefined })
|
|
136
|
+
} else {
|
|
137
|
+
setPollData({ ...poll_data, selected_option: poll_option })
|
|
138
|
+
}
|
|
139
|
+
}}
|
|
177
140
|
/>
|
|
178
141
|
</View>
|
|
179
142
|
)
|
|
180
143
|
}
|
|
181
144
|
|
|
182
|
-
if(!poll){
|
|
183
|
-
|
|
184
|
-
}
|
|
145
|
+
if(!poll){ return <></> }
|
|
146
|
+
|
|
185
147
|
return (
|
|
186
|
-
<View nativeID='poll' style={{ ...view_styles.section }} onLayout={(ev) => {
|
|
148
|
+
<View nativeID='poll' style={{ ...view_styles.section, minHeight:500 }} onLayout={(ev) => {
|
|
187
149
|
const { width } = ev.nativeEvent.layout
|
|
188
150
|
setPollWidth(width)
|
|
189
151
|
}}>
|
|
152
|
+
<View style={{ ...view_styles.section_header, backgroundColor:Colors.shades.shade100 }}>
|
|
153
|
+
<View style={{ flex:1 }}>
|
|
154
|
+
<Text theme='header_2'>Question {2}</Text>
|
|
155
|
+
<Text style={{ marginTop:5 }} theme='header'>{poll.poll_question}</Text>
|
|
156
|
+
</View>
|
|
157
|
+
</View>
|
|
190
158
|
<ScrollView style={{ flex:1 }}>
|
|
191
|
-
{server_checked && !responded ?
|
|
192
159
|
<View nativeID='question_image'>
|
|
193
160
|
{poll?.poll_image?.url ?
|
|
194
161
|
<Image
|
|
@@ -197,19 +164,9 @@ const PollCard = ({ poll, question_number, total_questions, onSkip, onCancel, on
|
|
|
197
164
|
/>
|
|
198
165
|
:<></>}
|
|
199
166
|
</View>
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
<View nativeID='question_progress' style={{ marginBottom:10, flexDirection:'row' }}>
|
|
204
|
-
<Text style={{ flex:1 }} size={12} color={Colors.brand.midnight} weight='semibold'>Question {question_number}{total_questions?` of ${total_questions}`:''}</Text>
|
|
205
|
-
</View>
|
|
206
|
-
:<></>}
|
|
207
|
-
<View nativeID='question' style={{ marginBottom:10 }}>
|
|
208
|
-
<Text size={16} color={Colors.brand.midnight} weight='bold'>{poll.poll_question}</Text>
|
|
209
|
-
</View>
|
|
210
|
-
</View>
|
|
211
|
-
{ poll.status == 'active' && server_checked && !responded ?
|
|
212
|
-
<View nativeID='question_respond_options' style={{ flex:1 }}>
|
|
167
|
+
|
|
168
|
+
{ poll.status == 'active' && !poll_response ?
|
|
169
|
+
<View nativeID='question_respond_options'>
|
|
213
170
|
<FlatList
|
|
214
171
|
data={poll_options.sort((a,b) => a.priority - b.priority)}
|
|
215
172
|
renderItem={renderPollOptions}
|
|
@@ -217,7 +174,7 @@ const PollCard = ({ poll, question_number, total_questions, onSkip, onCancel, on
|
|
|
217
174
|
keyExtractor={(item) => item.poll_option_id.toString()}
|
|
218
175
|
/>
|
|
219
176
|
</View>
|
|
220
|
-
:
|
|
177
|
+
:
|
|
221
178
|
<View nativeID='question_answer' style={{ flex:1 }}>
|
|
222
179
|
{selected_option ?
|
|
223
180
|
<View nativeID='selected_option' style={{ marginBottom:10, padding:10 }}>
|
|
@@ -230,7 +187,7 @@ const PollCard = ({ poll, question_number, total_questions, onSkip, onCancel, on
|
|
|
230
187
|
poll_option={selected_option}
|
|
231
188
|
/>
|
|
232
189
|
</View>
|
|
233
|
-
: (!
|
|
190
|
+
: (!poll_response || poll_response?.timed_out) ?
|
|
234
191
|
<View style={{ marginBottom:10, padding:10 }}>
|
|
235
192
|
<Text style={{ marginBottom:5 }} size={14} color={Colors.brand.slate} weight='semibold'>MY SELECTED ANSWER</Text>
|
|
236
193
|
<View style={{ flexDirection:'row', alignItems:'center', padding:10, borderRadius:22, borderWidth:1, borderColor:Colors.utility.error }}>
|
|
@@ -243,9 +200,9 @@ const PollCard = ({ poll, question_number, total_questions, onSkip, onCancel, on
|
|
|
243
200
|
<View nativeID='selected_option' style={{ marginBottom:10, padding:10 }}>
|
|
244
201
|
<Text style={{ marginBottom:5 }} size={14} color={Colors.brand.slate} weight='semibold'>CORRECT ANSWER</Text>
|
|
245
202
|
<PollOptionCard
|
|
246
|
-
show_summary={
|
|
203
|
+
show_summary={true}
|
|
247
204
|
show_result={true}
|
|
248
|
-
onSelect={() => console.log('
|
|
205
|
+
onSelect={() => console.log('')}
|
|
249
206
|
poll_option={correct_option}
|
|
250
207
|
/>
|
|
251
208
|
</View>
|
|
@@ -263,7 +220,7 @@ const PollCard = ({ poll, question_number, total_questions, onSkip, onCancel, on
|
|
|
263
220
|
<View style={{ flexDirection:'row', alignItems:'center', marginBottom:5 }}>
|
|
264
221
|
<Text style={{ flex:1 }} size={14} color={Colors.brand.slate} weight='semibold'>PUBLIC RESULTS</Text>
|
|
265
222
|
<View style={{ borderRadius:22, padding:10, backgroundColor:Colors.accents.accent100 }}>
|
|
266
|
-
<Text size={14} color={Colors.brand.midnight} weight='regular'>{
|
|
223
|
+
<Text size={14} color={Colors.brand.midnight} weight='regular'>{responses} Responses</Text>
|
|
267
224
|
</View>
|
|
268
225
|
</View>
|
|
269
226
|
{!poll.show_responses ?
|
|
@@ -277,23 +234,19 @@ const PollCard = ({ poll, question_number, total_questions, onSkip, onCancel, on
|
|
|
277
234
|
</View>
|
|
278
235
|
:<></>}
|
|
279
236
|
</View>
|
|
280
|
-
:
|
|
281
|
-
<View style={{ padding:20 }}>
|
|
282
|
-
<ActivityIndicator color={Colors.brand.midnight} size='large' style={{ alignSelf:'center' }}/>
|
|
283
|
-
</View>
|
|
284
237
|
}
|
|
285
238
|
</ScrollView>
|
|
286
239
|
{!loading ?
|
|
287
|
-
<View nativeID='question_actions' style={{
|
|
288
|
-
{!poll.seconds_allowed ||
|
|
240
|
+
<View nativeID='question_actions' style={{ ...view_styles.section_footer, alignItems:undefined }}>
|
|
241
|
+
{!poll.seconds_allowed || poll_response ?
|
|
289
242
|
<TouchableOpacity
|
|
290
|
-
style={{ marginRight:10, justifyContent:'center',
|
|
243
|
+
style={{ marginRight:10, justifyContent:'center', paddingRight:20, paddingLeft:20, backgroundColor:Colors.utility.warning, borderRadius:22, borderWidth:1, borderColor:Colors.utility.warning }}
|
|
291
244
|
onPress={() => handleCancel()}
|
|
292
245
|
>
|
|
293
246
|
<Icons.ListIcon size={18} color={Colors.shades.white} />
|
|
294
247
|
</TouchableOpacity>
|
|
295
248
|
:<></>}
|
|
296
|
-
{poll.status == 'active' && poll.seconds_allowed &&
|
|
249
|
+
{poll.status == 'active' && poll.seconds_allowed && !poll_response ?
|
|
297
250
|
<View style={{ marginRight:5 }}>
|
|
298
251
|
<ResponseTimer
|
|
299
252
|
poll_id={poll.poll_id}
|
|
@@ -305,7 +258,7 @@ const PollCard = ({ poll, question_number, total_questions, onSkip, onCancel, on
|
|
|
305
258
|
<Button
|
|
306
259
|
style={{flex:1, marginRight:5}}
|
|
307
260
|
title_color={Colors.brand.electric}
|
|
308
|
-
title={
|
|
261
|
+
title={poll_response?'Next':'Skip'}
|
|
309
262
|
borderColor={Colors.brand.electric}
|
|
310
263
|
backgroundColor={Colors.shades.white}
|
|
311
264
|
borderRadius={22}
|
|
@@ -314,13 +267,13 @@ const PollCard = ({ poll, question_number, total_questions, onSkip, onCancel, on
|
|
|
314
267
|
onPress={() => handleSkip()}
|
|
315
268
|
/>
|
|
316
269
|
}
|
|
317
|
-
{
|
|
270
|
+
{!poll_response ?
|
|
318
271
|
<Button
|
|
319
272
|
style={{flex:2}}
|
|
320
273
|
title_color={Colors.shades.white}
|
|
321
|
-
disabled={
|
|
322
|
-
title={
|
|
323
|
-
backgroundColor={
|
|
274
|
+
disabled={selected_option&&!action_loading?false:true}
|
|
275
|
+
title={selected_option?`Submit!`:poll.status == 'active' ? 'Select Answer' : 'Not Active'}
|
|
276
|
+
backgroundColor={selected_option&&!action_loading?Colors.utility.success:Colors.brand.slate}
|
|
324
277
|
borderRadius={22}
|
|
325
278
|
onPress={() => handleSubmitResponse()}
|
|
326
279
|
/>
|
|
@@ -13,7 +13,7 @@ type PollQuestionsSectionProps = {
|
|
|
13
13
|
onSelectPoll:(p:PollProps) => void
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
const PollQuestionsSection = ({ poll_campaign, polls, onSelectPoll }:PollQuestionsSectionProps) => {
|
|
16
|
+
const PollQuestionsSection = ({ poll_campaign, polls, poll_responses, onSelectPoll }:PollQuestionsSectionProps) => {
|
|
17
17
|
const [ section_data, setSectionData ] = useState<{
|
|
18
18
|
loading:boolean,
|
|
19
19
|
expanded:boolean,
|
|
@@ -25,15 +25,17 @@ const PollQuestionsSection = ({ poll_campaign, polls, onSelectPoll }:PollQuestio
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
const renderPolls = (data:{item:PollProps, index:number}) => {
|
|
28
|
+
const my_response = poll_responses.find(r => r.poll_id == data.item.poll_id)
|
|
29
|
+
const response_option = data.item.poll_options?.find(po => po.poll_option_id == my_response?.poll_option_id);
|
|
28
30
|
return (
|
|
29
|
-
<View>
|
|
31
|
+
<View style={{ borderBottomWidth:1, borderBottomColor:Colors.shades.shade600 }}>
|
|
30
32
|
<PollSelectCard
|
|
31
33
|
poll={data.item}
|
|
32
34
|
disabled={false}
|
|
33
35
|
selected={false}
|
|
34
36
|
poll_campaign={poll_campaign}
|
|
35
|
-
show_response={false}
|
|
36
|
-
response_option={
|
|
37
|
+
show_response={my_response ? true : false}
|
|
38
|
+
response_option={response_option}
|
|
37
39
|
onSelect={(p) => onSelectPoll(p)}
|
|
38
40
|
/>
|
|
39
41
|
</View>
|
package/src/Poll/index.tsx
CHANGED
|
@@ -1,27 +1,29 @@
|
|
|
1
1
|
import React, { useEffect, useState } from 'react';
|
|
2
|
-
import { PollApi, PollCampaignApi } from './api';
|
|
2
|
+
import { PollApi, PollCampaignApi, PollResponseApi } from './api';
|
|
3
3
|
import { View, ScrollView, ActivityIndicator } from 'react-native';
|
|
4
4
|
import type { PollCampaignGoalProps, PollCampaignProps, PollProps, PollResponseProps } from '../types';
|
|
5
5
|
import Colors from '../constants/colors';
|
|
6
6
|
import CampaignHeader from './components/CampaignHeader';
|
|
7
7
|
import CampaignProgressBar from './components/CampaignProgressBar';
|
|
8
8
|
import PollQuestionsSection from './components/PollQuestionsSection';
|
|
9
|
-
import { Spring
|
|
9
|
+
import { Spring } from '../Components';
|
|
10
10
|
//import PollCard from './components/PollCard';
|
|
11
11
|
import CampaignResult from './components/CampaignResult';
|
|
12
12
|
import CampaignLeaderboard from './components/CampaignLeaderboard';
|
|
13
|
-
|
|
13
|
+
import PollCard from './components/PollCard';
|
|
14
|
+
import type { BEEventProps } from '../Observer/api/types';
|
|
14
15
|
|
|
15
16
|
type PollCampaignModuleProps = {
|
|
16
17
|
poll_campaign_id:string,
|
|
17
18
|
poll_id?:string,
|
|
18
19
|
player_id?:string,
|
|
19
20
|
height:number,
|
|
21
|
+
onEvent?:(be_event:BEEventProps) => void,
|
|
20
22
|
onRequestAuthenticate: (auth_strategy_id?:string, company_id?:string) => void,
|
|
21
23
|
onSharePollCampaign: (poll_campaign:PollCampaignProps) => void,
|
|
22
24
|
onComplete:() => void
|
|
23
25
|
}
|
|
24
|
-
const PollCampaign = ({ height, poll_campaign_id, player_id }: PollCampaignModuleProps ) => {
|
|
26
|
+
const PollCampaign = ({ height, poll_campaign_id, player_id, onRequestAuthenticate }: PollCampaignModuleProps ) => {
|
|
25
27
|
const [ module_data, setModuleData ] = useState<{
|
|
26
28
|
loading: boolean,
|
|
27
29
|
active_poll_id?:string,
|
|
@@ -34,26 +36,37 @@ const PollCampaign = ({ height, poll_campaign_id, player_id }: PollCampaignModul
|
|
|
34
36
|
poll_campaign_goals:[]
|
|
35
37
|
});
|
|
36
38
|
const [ full_leaderboard, setFullLeaderboard ] = useState(false);
|
|
37
|
-
const [ my_data ] = useState<{
|
|
39
|
+
const [ my_data, setMyData ] = useState<{
|
|
40
|
+
action_loading:boolean,
|
|
38
41
|
poll_responses:PollResponseProps[]
|
|
39
42
|
}>({
|
|
43
|
+
action_loading: false,
|
|
40
44
|
poll_responses: []
|
|
41
45
|
});
|
|
46
|
+
const { poll_responses, action_loading } = my_data
|
|
42
47
|
|
|
43
48
|
const { poll_campaign, polls, active_poll_id } = module_data;
|
|
44
|
-
const
|
|
45
|
-
|
|
49
|
+
const active_response = poll_responses.find(r => r.poll_id == active_poll_id);
|
|
50
|
+
|
|
51
|
+
const active_polls = polls.filter(p => p.status != 'inactive').sort((a,b) => a.priority - b.priority)
|
|
46
52
|
|
|
47
53
|
useEffect(() => {
|
|
48
54
|
PollCampaignApi.setEnvironment();
|
|
49
55
|
getDataFromServer();
|
|
56
|
+
if(player_id){}
|
|
50
57
|
},[poll_campaign_id, player_id])
|
|
51
58
|
|
|
52
59
|
const getDataFromServer = async() => {
|
|
53
60
|
setModuleData({ ...module_data, loading:true });
|
|
54
61
|
const pc = await PollCampaignApi.getPollCampaignById(poll_campaign_id);
|
|
55
62
|
const ps_resp = await PollApi.getPollsByCampaignId(poll_campaign_id);
|
|
56
|
-
|
|
63
|
+
if(player_id){
|
|
64
|
+
let my_responses = await PollResponseApi.getMyCampaignResponses(poll_campaign_id);
|
|
65
|
+
setMyData({
|
|
66
|
+
...my_data,
|
|
67
|
+
poll_responses: my_responses
|
|
68
|
+
})
|
|
69
|
+
}
|
|
57
70
|
setModuleData({
|
|
58
71
|
...module_data,
|
|
59
72
|
poll_campaign: pc,
|
|
@@ -63,6 +76,33 @@ const PollCampaign = ({ height, poll_campaign_id, player_id }: PollCampaignModul
|
|
|
63
76
|
})
|
|
64
77
|
}
|
|
65
78
|
|
|
79
|
+
const handleSubmitResponse = async(pr:PollResponseProps) => {
|
|
80
|
+
if(!player_id){ return onRequestAuthenticate(poll_campaign?.auth_strategy_id) }
|
|
81
|
+
try {
|
|
82
|
+
if(action_loading){ return }
|
|
83
|
+
setMyData({ ...my_data, action_loading: true })
|
|
84
|
+
let new_pr = await PollResponseApi.createPollResponse(pr);
|
|
85
|
+
setMyData({
|
|
86
|
+
...my_data,
|
|
87
|
+
poll_responses: poll_responses.filter(pr => pr.poll_response_id != new_pr.poll_response_id).concat(new_pr)
|
|
88
|
+
})
|
|
89
|
+
} catch (e) {
|
|
90
|
+
alert('Unable to process!')
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const handleNext = async() => {
|
|
95
|
+
if(!active_poll_id){ return }
|
|
96
|
+
let active_index = active_polls.findIndex(p => p.poll_id == active_poll_id);
|
|
97
|
+
let new_poll = active_polls.find((p,i) => i > active_index && p.status == 'active');
|
|
98
|
+
if(!new_poll){
|
|
99
|
+
setModuleData({ ...module_data, active_poll_id: undefined })
|
|
100
|
+
setFullLeaderboard(true);
|
|
101
|
+
return
|
|
102
|
+
}
|
|
103
|
+
setModuleData({ ...module_data, active_poll_id: new_poll.poll_id })
|
|
104
|
+
}
|
|
105
|
+
|
|
66
106
|
if(!poll_campaign){
|
|
67
107
|
return (
|
|
68
108
|
<View style={{ flex:1 }}>
|
|
@@ -85,7 +125,7 @@ const PollCampaign = ({ height, poll_campaign_id, player_id }: PollCampaignModul
|
|
|
85
125
|
<View style={{ backgroundColor:Colors.shades.shade100 }}>
|
|
86
126
|
<CampaignProgressBar
|
|
87
127
|
poll_campaign={poll_campaign}
|
|
88
|
-
polls={
|
|
128
|
+
polls={active_polls}
|
|
89
129
|
active_poll='0'
|
|
90
130
|
onPollSelect={(p) => console.log(p)}
|
|
91
131
|
poll_responses={poll_responses}
|
|
@@ -100,13 +140,16 @@ const PollCampaign = ({ height, poll_campaign_id, player_id }: PollCampaignModul
|
|
|
100
140
|
<View nativeID='poll_questions'>
|
|
101
141
|
<PollQuestionsSection
|
|
102
142
|
poll_campaign={poll_campaign}
|
|
103
|
-
polls={
|
|
143
|
+
polls={active_polls}
|
|
104
144
|
poll_responses={poll_responses}
|
|
105
|
-
onSelectPoll={(p) =>
|
|
145
|
+
onSelectPoll={(p) => {
|
|
146
|
+
if(p.status == 'paused'){ return alert('This question is currently paused. Please open when it becomes active') }
|
|
147
|
+
setModuleData({ ...module_data, active_poll_id: p.poll_id })
|
|
148
|
+
}}
|
|
106
149
|
/>
|
|
107
150
|
</View>
|
|
108
151
|
</ScrollView>
|
|
109
|
-
{
|
|
152
|
+
{active_poll_id ?
|
|
110
153
|
<View style={{ position:'absolute', top:0, left:0, right:0, bottom:0, justifyContent:'flex-end', backgroundColor:Colors.shades.black_faded }}>
|
|
111
154
|
<Spring
|
|
112
155
|
slide='vertical'
|
|
@@ -114,7 +157,15 @@ const PollCampaign = ({ height, poll_campaign_id, player_id }: PollCampaignModul
|
|
|
114
157
|
from={500}
|
|
115
158
|
style={{ maxHeight:height }}
|
|
116
159
|
>
|
|
117
|
-
<
|
|
160
|
+
<PollCard
|
|
161
|
+
poll_id={active_poll_id}
|
|
162
|
+
action_loading={action_loading}
|
|
163
|
+
poll_response={active_response}
|
|
164
|
+
onSkip={() => handleNext()}
|
|
165
|
+
onCancel={() => setModuleData({ ...module_data, active_poll_id: undefined })}
|
|
166
|
+
onResponse={(response) => handleSubmitResponse(response)}
|
|
167
|
+
onShowAuthenticate={() => console.log('authenticate!!')}
|
|
168
|
+
/>
|
|
118
169
|
</Spring>
|
|
119
170
|
</View>
|
|
120
171
|
:<></>}
|
package/src/types.d.ts
CHANGED
|
@@ -146,6 +146,19 @@ export interface EventProps {
|
|
|
146
146
|
last_update_datetime: any
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
+
export interface ContestStatProps {
|
|
150
|
+
contest_stat_id:string,
|
|
151
|
+
contest_id:string,
|
|
152
|
+
contest_type:string,
|
|
153
|
+
participant_id:string,
|
|
154
|
+
participant_type:string,
|
|
155
|
+
stat:string,
|
|
156
|
+
stat_label:string,
|
|
157
|
+
status: string,
|
|
158
|
+
value:number,
|
|
159
|
+
create_datetime:any,
|
|
160
|
+
last_update_datetime:any
|
|
161
|
+
}
|
|
149
162
|
|
|
150
163
|
export interface AthleteProps {
|
|
151
164
|
athlete_id:string,
|