be-components 0.7.6 → 0.7.8
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/Poll/api/index.js +63 -18
- package/lib/commonjs/Poll/api/index.js.map +1 -1
- package/lib/commonjs/Poll/components/CampaignPlay.js +7 -4
- package/lib/commonjs/Poll/components/CampaignPlay.js.map +1 -1
- package/lib/commonjs/Poll/components/CampaignProgressBar.js +1 -0
- package/lib/commonjs/Poll/components/CampaignProgressBar.js.map +1 -1
- package/lib/commonjs/Poll/components/CampaignResult.js +2 -2
- package/lib/commonjs/Poll/components/CampaignResult.js.map +1 -1
- package/lib/commonjs/Poll/components/ResponseTimer.js.map +1 -1
- package/lib/commonjs/Poll/flashmarket/ResultCard.js +419 -0
- package/lib/commonjs/Poll/flashmarket/ResultCard.js.map +1 -0
- package/lib/commonjs/Poll/flashmarket/index.js +355 -68
- package/lib/commonjs/Poll/flashmarket/index.js.map +1 -1
- package/lib/commonjs/Poll/index.js +8 -5
- package/lib/commonjs/Poll/index.js.map +1 -1
- package/lib/module/Poll/api/index.js +63 -18
- package/lib/module/Poll/api/index.js.map +1 -1
- package/lib/module/Poll/components/CampaignPlay.js +7 -4
- package/lib/module/Poll/components/CampaignPlay.js.map +1 -1
- package/lib/module/Poll/components/CampaignProgressBar.js +1 -0
- package/lib/module/Poll/components/CampaignProgressBar.js.map +1 -1
- package/lib/module/Poll/components/CampaignResult.js +2 -2
- package/lib/module/Poll/components/CampaignResult.js.map +1 -1
- package/lib/module/Poll/components/ResponseTimer.js.map +1 -1
- package/lib/module/Poll/flashmarket/ResultCard.js +410 -0
- package/lib/module/Poll/flashmarket/ResultCard.js.map +1 -0
- package/lib/module/Poll/flashmarket/index.js +357 -70
- package/lib/module/Poll/flashmarket/index.js.map +1 -1
- package/lib/module/Poll/index.js +8 -5
- package/lib/module/Poll/index.js.map +1 -1
- package/lib/typescript/src/Poll/api/index.d.ts +7 -2
- package/lib/typescript/src/Poll/api/index.d.ts.map +1 -1
- package/lib/typescript/src/Poll/components/CampaignPlay.d.ts +1 -1
- package/lib/typescript/src/Poll/components/CampaignPlay.d.ts.map +1 -1
- package/lib/typescript/src/Poll/components/CampaignProgressBar.d.ts.map +1 -1
- package/lib/typescript/src/Poll/components/ResponseTimer.d.ts.map +1 -1
- package/lib/typescript/src/Poll/flashmarket/ResultCard.d.ts +12 -0
- package/lib/typescript/src/Poll/flashmarket/ResultCard.d.ts.map +1 -0
- package/lib/typescript/src/Poll/flashmarket/index.d.ts +5 -3
- package/lib/typescript/src/Poll/flashmarket/index.d.ts.map +1 -1
- package/lib/typescript/src/Poll/index.d.ts +5 -4
- package/lib/typescript/src/Poll/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Poll/api/index.ts +54 -16
- package/src/Poll/components/CampaignPlay.tsx +8 -5
- package/src/Poll/components/CampaignProgressBar.tsx +1 -2
- package/src/Poll/components/CampaignResult.tsx +2 -2
- package/src/Poll/components/ResponseTimer.tsx +1 -0
- package/src/Poll/flashmarket/ResultCard.tsx +194 -0
- package/src/Poll/flashmarket/index.tsx +309 -96
- package/src/Poll/index.tsx +11 -8
|
@@ -2,64 +2,112 @@ import React, { useEffect, useState } from 'react';
|
|
|
2
2
|
import { ActivityIndicator, View, Image, TouchableOpacity } from "react-native";
|
|
3
3
|
import type { PollCampaignProps, PollOptionProps, PollProps, PollResponseProps, PollSummaryProps } from '../../types';
|
|
4
4
|
import Colors from '../../constants/colors';
|
|
5
|
-
import {
|
|
6
|
-
import { PollApi, PollCampaignApi, PollResponseApi, PollResponseHelpers } from '../api';
|
|
5
|
+
import { Button, Icons, Text, TextInput } from '../../Components';
|
|
6
|
+
import { PollApi, PollCampaignApi, PollCampaignHelpers, PollResponseApi, PollResponseHelpers } from '../api';
|
|
7
7
|
import { view_styles } from '../../constants/styles';
|
|
8
8
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
9
|
+
import CampaignProgressBar from '../components/CampaignProgressBar';
|
|
10
|
+
import ResponseTimer from '../components/ResponseTimer';
|
|
11
|
+
import ResultCard from './ResultCard';
|
|
9
12
|
|
|
10
13
|
|
|
11
14
|
type FlashMarketProps = {
|
|
12
|
-
|
|
15
|
+
poll_campaign_id:string,
|
|
16
|
+
poll_id?:string,
|
|
17
|
+
hide_progress_bar?:boolean,
|
|
13
18
|
next_allowed?:boolean,
|
|
14
19
|
player_id?:string,
|
|
15
|
-
onRequestAuthenticate:() => void
|
|
20
|
+
onRequestAuthenticate:(auth_strategy_id?:string, company_id?:string) => void
|
|
16
21
|
}
|
|
17
22
|
|
|
18
23
|
const MAX_IMAGE_SIZE = 125
|
|
19
24
|
const MAX_OPTION_WIDTH = 200
|
|
20
25
|
|
|
21
|
-
const FlashMarket = ({ poll_id, player_id, onRequestAuthenticate }:FlashMarketProps) => {
|
|
26
|
+
const FlashMarket = ({ hide_progress_bar, poll_campaign_id, poll_id, player_id, onRequestAuthenticate }:FlashMarketProps) => {
|
|
22
27
|
const [ flash_size, setFlashSize ] = useState({ height:0, width:0 });
|
|
23
|
-
const [
|
|
24
|
-
{
|
|
28
|
+
const [ poll_data, setPollData ] = useState<{
|
|
25
29
|
loading:boolean,
|
|
26
|
-
poll_campaign?:PollCampaignProps,
|
|
27
30
|
poll?:PollProps,
|
|
28
31
|
poll_options:PollOptionProps[],
|
|
29
32
|
poll_summaries: PollSummaryProps[],
|
|
30
33
|
poll_response?:PollResponseProps,
|
|
31
|
-
show_complete:boolean
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
loading:false,
|
|
34
|
+
show_complete: boolean
|
|
35
|
+
}>({
|
|
36
|
+
loading: false,
|
|
35
37
|
poll_options: [],
|
|
38
|
+
show_complete:false,
|
|
36
39
|
poll_summaries: [],
|
|
37
|
-
show_complete: false
|
|
38
40
|
})
|
|
41
|
+
const { loading, poll, poll_options, poll_summaries, poll_response } = poll_data;
|
|
39
42
|
|
|
40
|
-
const
|
|
43
|
+
const [ data, setData ] = useState<
|
|
44
|
+
{
|
|
45
|
+
loaded:boolean,
|
|
46
|
+
poll_campaign?:PollCampaignProps,
|
|
47
|
+
active_poll_index?:number,
|
|
48
|
+
show_leaders:boolean,
|
|
49
|
+
polls:PollProps[],
|
|
50
|
+
poll_responses:PollResponseProps[]
|
|
51
|
+
}
|
|
52
|
+
>({
|
|
53
|
+
loaded:false,
|
|
54
|
+
polls:[],
|
|
55
|
+
show_leaders: false,
|
|
56
|
+
poll_responses: []
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
const { loaded, poll_campaign, polls, active_poll_index, poll_responses, show_leaders } = data;
|
|
41
60
|
|
|
42
61
|
let visible_options = poll_options
|
|
43
62
|
if(poll_response && poll_response.status == 'pending'){ visible_options = poll_options.filter(po => po.poll_option_id == poll_response.poll_option_id) }
|
|
44
|
-
|
|
45
|
-
let image_size = flash_size.width * 0.
|
|
63
|
+
const selected_option = poll_options.find(po => po.poll_option_id == poll_response?.poll_option_id);
|
|
64
|
+
let image_size = flash_size.width * 0.15
|
|
46
65
|
if(image_size > MAX_IMAGE_SIZE){ image_size = MAX_IMAGE_SIZE }
|
|
47
|
-
let option_width = (flash_size.width
|
|
66
|
+
let option_width = (flash_size.width / 3) - 5
|
|
48
67
|
if(option_width > MAX_OPTION_WIDTH){ option_width = MAX_OPTION_WIDTH }
|
|
49
68
|
|
|
50
69
|
useEffect(( ) => {
|
|
51
|
-
getDataFromServer(
|
|
52
|
-
},[
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
70
|
+
getDataFromServer(poll_campaign_id)
|
|
71
|
+
},[poll_campaign_id, player_id])
|
|
72
|
+
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
|
|
75
|
+
if(!active_poll_index && active_poll_index != 0){ return }
|
|
76
|
+
let active_poll = polls[active_poll_index]
|
|
77
|
+
if(!active_poll){ return }
|
|
78
|
+
getPollFromServer(active_poll.poll_id)
|
|
79
|
+
},[active_poll_index])
|
|
80
|
+
|
|
81
|
+
const getDataFromServer = async(poll_campaign_id:string) => {
|
|
82
|
+
const pc = await PollCampaignApi.getPollCampaignById(poll_campaign_id)
|
|
83
|
+
const ps_response = await PollApi.getPollsByCampaignId(poll_campaign_id)
|
|
84
|
+
let prs:PollResponseProps[] = []
|
|
85
|
+
if(player_id){
|
|
86
|
+
prs = await PollResponseApi.getMyCampaignResponses(poll_campaign_id)
|
|
62
87
|
}
|
|
88
|
+
//if(poll_id){ await getPollFromServer(poll_id) }
|
|
89
|
+
let index = polls.findIndex(p => p.poll_id == poll_id)
|
|
90
|
+
if(pc.campaign_type == 'trivia'){ index = -1 }
|
|
91
|
+
|
|
92
|
+
//const campaign_complete = PollCampaignHelpers.isCampaignComplete(ps_response.polls, prs, pc)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
setData({
|
|
96
|
+
...data,
|
|
97
|
+
loaded:true,
|
|
98
|
+
polls:ps_response.polls.sort((a,b) => a.priority - b.priority),
|
|
99
|
+
poll_campaign: pc,
|
|
100
|
+
//show_leaders: campaign_complete,
|
|
101
|
+
active_poll_index:index >= 0 ? index: undefined,
|
|
102
|
+
poll_responses: prs
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const getPollFromServer = async(poll_id:string) => {
|
|
107
|
+
setPollData({ ...poll_data, loading:true });
|
|
108
|
+
|
|
109
|
+
const p = await PollApi.getPollById(poll_id);
|
|
110
|
+
let my_response:PollResponseProps | undefined = poll_responses.find(pr => pr.poll_id == poll_id)
|
|
63
111
|
|
|
64
112
|
if(!my_response){
|
|
65
113
|
//If no-response - check cache
|
|
@@ -68,25 +116,25 @@ const FlashMarket = ({ poll_id, player_id, onRequestAuthenticate }:FlashMarketPr
|
|
|
68
116
|
my_response = JSON.parse(cached_response);
|
|
69
117
|
}
|
|
70
118
|
}
|
|
71
|
-
|
|
119
|
+
|
|
120
|
+
setPollData({
|
|
121
|
+
...poll_data,
|
|
72
122
|
loading:false,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
poll_response: my_response,
|
|
78
|
-
show_complete: my_response && my_response?.status != 'pending' ? true : false
|
|
123
|
+
poll: p.poll,
|
|
124
|
+
poll_options: p.poll_options,
|
|
125
|
+
poll_summaries: p.poll_summaries,
|
|
126
|
+
poll_response: my_response
|
|
79
127
|
})
|
|
80
128
|
}
|
|
81
129
|
|
|
82
130
|
const handleSelectOption = async(po:PollOptionProps) => {
|
|
83
|
-
if(!poll){ return }
|
|
84
|
-
if(poll_response && poll_response.status != 'pending'){ return
|
|
131
|
+
if(!poll || poll.status != 'active'){ return }
|
|
132
|
+
if(poll_response && poll_response.status != 'pending'){ return setPollData({ ...poll_data, show_complete: true }) }
|
|
85
133
|
let cached_response = await AsyncStorage.getItem(`response:${poll_id}`)
|
|
86
134
|
if(cached_response){
|
|
87
135
|
if(JSON.parse(cached_response).poll_option_id == po.poll_option_id){
|
|
88
136
|
await AsyncStorage.removeItem(`response:${poll_id}`)
|
|
89
|
-
return
|
|
137
|
+
return setPollData({ ...poll_data, poll_response: undefined })
|
|
90
138
|
}
|
|
91
139
|
}
|
|
92
140
|
let stake = poll_response?.stake ?? poll.minimum_stake
|
|
@@ -105,26 +153,67 @@ const FlashMarket = ({ poll_id, player_id, onRequestAuthenticate }:FlashMarketPr
|
|
|
105
153
|
}
|
|
106
154
|
await AsyncStorage.setItem(`response:${poll_id}`, JSON.stringify(draft_response))
|
|
107
155
|
|
|
156
|
+
setPollData({
|
|
157
|
+
...poll_data,
|
|
158
|
+
poll_response: draft_response
|
|
159
|
+
})
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const handleTimesUp = async() => {
|
|
163
|
+
if(!poll || poll.status != 'active'){ return }
|
|
164
|
+
if(!player_id){ return }
|
|
165
|
+
if(poll_response && poll_response.status == 'pending'){ return handleSubmit() }
|
|
166
|
+
|
|
167
|
+
const draft_response:PollResponseProps = {
|
|
168
|
+
poll_id:poll.poll_id,
|
|
169
|
+
poll_option_id:'0',
|
|
170
|
+
stake: poll.minimum_stake,
|
|
171
|
+
market_type: 'FREE',
|
|
172
|
+
poll_response_id: '',
|
|
173
|
+
player_id: '',
|
|
174
|
+
winnings: 0,
|
|
175
|
+
timed_out: true,
|
|
176
|
+
response_body: {},
|
|
177
|
+
status: 'pending',
|
|
178
|
+
create_datetime: '',
|
|
179
|
+
last_update_datetime: ''
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const new_resp = await PollResponseApi.createPollResponse({ ...draft_response })
|
|
183
|
+
const updated_ps = PollResponseHelpers.updateSummariesWithResponse(new_resp, poll_summaries)
|
|
184
|
+
setPollData({
|
|
185
|
+
...poll_data,
|
|
186
|
+
poll_response: new_resp,
|
|
187
|
+
poll_summaries: updated_ps,
|
|
188
|
+
show_complete: true
|
|
189
|
+
})
|
|
108
190
|
setData({
|
|
109
191
|
...data,
|
|
110
|
-
|
|
192
|
+
poll_responses: poll_responses.concat(new_resp)
|
|
111
193
|
})
|
|
194
|
+
|
|
195
|
+
await AsyncStorage.removeItem(`response:${poll_id}`)
|
|
196
|
+
|
|
112
197
|
}
|
|
113
198
|
|
|
114
199
|
const handleSubmit = async() => {
|
|
115
200
|
if(!poll_response){ return }
|
|
116
201
|
if(poll_response.status != 'pending'){ return }
|
|
117
|
-
if(!player_id){ return onRequestAuthenticate() }
|
|
202
|
+
if(!player_id){ return onRequestAuthenticate(poll_campaign?.auth_strategy_id, poll_campaign?.company_id) }
|
|
118
203
|
let stake_number = parseFloat(poll_response.stake as string)
|
|
119
204
|
if(isNaN(stake_number)){ return }
|
|
120
205
|
const new_resp = await PollResponseApi.createPollResponse({ ...poll_response, stake: stake_number })
|
|
121
206
|
const updated_ps = PollResponseHelpers.updateSummariesWithResponse(new_resp, poll_summaries)
|
|
122
|
-
|
|
123
|
-
...
|
|
207
|
+
setPollData({
|
|
208
|
+
...poll_data,
|
|
124
209
|
poll_response: new_resp,
|
|
125
210
|
poll_summaries: updated_ps,
|
|
126
211
|
show_complete: true
|
|
127
212
|
})
|
|
213
|
+
setData({
|
|
214
|
+
...data,
|
|
215
|
+
poll_responses: poll_responses.concat(new_resp)
|
|
216
|
+
})
|
|
128
217
|
await AsyncStorage.removeItem(`response:${poll_id}`)
|
|
129
218
|
}
|
|
130
219
|
|
|
@@ -135,29 +224,31 @@ const FlashMarket = ({ poll_id, player_id, onRequestAuthenticate }:FlashMarketPr
|
|
|
135
224
|
//const correct_summary = poll_summaries.find(ps => ps.poll_option_id == correct_option?.poll_option_id);
|
|
136
225
|
|
|
137
226
|
const renderPollOptions = (data:{item:PollOptionProps, show_summary?:boolean, index:number}) => {
|
|
227
|
+
const poll = polls.find(p => p.poll_id == data.item.poll_id)
|
|
228
|
+
if(!poll){ return <></> }
|
|
138
229
|
const selected = data.item.poll_option_id == poll_response?.poll_option_id ? true : false
|
|
139
230
|
const poll_summary = poll_summaries.find(ps => ps.poll_option_id == data.item.poll_option_id);
|
|
140
|
-
const color = PollResponseHelpers.getOptionColor(data.item, poll_response)
|
|
231
|
+
const color = PollResponseHelpers.getOptionColor(poll, data.item, poll_response)
|
|
141
232
|
return (
|
|
142
|
-
<View>
|
|
233
|
+
<View style={{ width:option_width }}>
|
|
143
234
|
|
|
144
235
|
<TouchableOpacity
|
|
145
236
|
//disabled={poll_response && poll_response.status != 'pending' ? true : false}
|
|
146
|
-
style={{ flexDirection:'row',
|
|
237
|
+
style={{ flexDirection:'row', alignItems:'center', margin:5, borderRadius:22, padding:10, borderWidth:selected?1:0, borderColor:Colors.brand.midnight, backgroundColor:color, ...view_styles.float }}
|
|
147
238
|
onPress={() => handleSelectOption(data.item)}>
|
|
148
239
|
{data.show_summary && poll_summary ?
|
|
149
240
|
<View style={{ position:'absolute', top:0, left:0, bottom:0, borderRadius:22, backgroundColor:color, opacity:0.6, width: option_width * poll_summary.pct }}/>
|
|
150
241
|
:<></>}
|
|
151
242
|
<Text style={{ flex:1 }} size={14} color={Colors.brand.midnight} weight={'bold'} textAlign={data.show_summary?'left':'center'}>{data.item.option_name}</Text>
|
|
152
243
|
{data.show_summary && poll_summary ?
|
|
153
|
-
<Text style={{ marginLeft:10, padding:5, borderRadius:selected?100:0, backgroundColor:selected?Colors.shades.white:undefined
|
|
244
|
+
<Text style={{ marginLeft:10, padding:5, borderRadius:selected?100:0, backgroundColor:selected?Colors.shades.white:undefined }} size={12} color={Colors.brand.midnight} weight='bold' >{(poll_summary.pct*100).toFixed()}%</Text>
|
|
154
245
|
:<></>}
|
|
155
246
|
</TouchableOpacity>
|
|
156
247
|
</View>
|
|
157
248
|
)
|
|
158
249
|
}
|
|
159
250
|
|
|
160
|
-
if(
|
|
251
|
+
if(!loaded || !poll_campaign){
|
|
161
252
|
return (
|
|
162
253
|
<View>
|
|
163
254
|
<ActivityIndicator size={'large'} color={Colors.brand.midnight}/>
|
|
@@ -165,65 +256,187 @@ const FlashMarket = ({ poll_id, player_id, onRequestAuthenticate }:FlashMarketPr
|
|
|
165
256
|
)
|
|
166
257
|
}
|
|
167
258
|
|
|
259
|
+
|
|
260
|
+
const next_allowed = PollResponseHelpers.nextAllowed(polls, poll_responses, poll?.poll_id)
|
|
261
|
+
const campaign_complete = PollCampaignHelpers.isCampaignComplete(polls, poll_responses, poll_campaign)
|
|
262
|
+
|
|
168
263
|
return (
|
|
169
|
-
<View style={{ flex:1 }}>
|
|
170
|
-
<View style={{
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
{
|
|
175
|
-
<View
|
|
176
|
-
<
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
264
|
+
<View style={{ flex:1, backgroundColor:Colors.shades.white }}>
|
|
265
|
+
<View style={{ flex:1 }} onLayout={(ev) => {
|
|
266
|
+
const { height, width } = ev.nativeEvent.layout;
|
|
267
|
+
setFlashSize({ height, width })
|
|
268
|
+
}}>
|
|
269
|
+
{show_leaders ?
|
|
270
|
+
<View>
|
|
271
|
+
<ResultCard
|
|
272
|
+
poll_campaign_id={poll_campaign_id}
|
|
273
|
+
width={flash_size.width}
|
|
274
|
+
polls={polls}
|
|
275
|
+
poll_responses={poll_responses}
|
|
276
|
+
onClose={() => setData({ ...data, show_leaders: false, active_poll_index:0 })}
|
|
180
277
|
/>
|
|
181
278
|
</View>
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
279
|
+
:!poll ?
|
|
280
|
+
<View style={{ flexDirection:'row', alignItems:'center' }}>
|
|
281
|
+
<View style={{ padding:10 }}>
|
|
282
|
+
<Image
|
|
283
|
+
source={{ uri: poll_campaign.campaign_image?.url ?? 'https://res.cloudinary.com/hoabts6mc/image/upload/v1718979933/question_mark_ro0ac5.webp' }}
|
|
284
|
+
style={{ height:image_size, width:image_size }}
|
|
285
|
+
resizeMode='cover'
|
|
286
|
+
/>
|
|
287
|
+
</View>
|
|
288
|
+
<View style={{ flex:1 }}>
|
|
289
|
+
<Text size={18} color={Colors.brand.midnight} weight='bold'>{poll_campaign.name}</Text>
|
|
290
|
+
<Text style={{ marginTop:5 }} size={16} color={Colors.brand.midnight} weight='semibold'>{poll_campaign.total_polls} Questions</Text>
|
|
291
|
+
</View>
|
|
292
|
+
{campaign_complete ?
|
|
293
|
+
<Button
|
|
294
|
+
style={{ margin:5 }}
|
|
295
|
+
title='RESULTS'
|
|
296
|
+
padding={15}
|
|
297
|
+
backgroundColor={Colors.incentive.gold}
|
|
298
|
+
title_color={Colors.shades.white}
|
|
299
|
+
onPress={() => {
|
|
300
|
+
setData({ ...data, show_leaders:true })
|
|
301
|
+
}}
|
|
302
|
+
/>
|
|
303
|
+
:
|
|
304
|
+
<Button
|
|
305
|
+
style={{ margin:5 }}
|
|
306
|
+
title='PLAY'
|
|
307
|
+
padding={15}
|
|
308
|
+
backgroundColor={Colors.brand.electric}
|
|
309
|
+
title_color={Colors.shades.white}
|
|
310
|
+
onPress={() => {
|
|
311
|
+
if(poll_campaign.campaign_type == 'trivia' && !player_id){ return onRequestAuthenticate(poll_campaign.auth_strategy_id, poll_campaign.company_id) }
|
|
312
|
+
setData({ ...data, active_poll_index:0 })
|
|
313
|
+
}}
|
|
314
|
+
/>
|
|
315
|
+
}
|
|
191
316
|
</View>
|
|
317
|
+
:
|
|
318
|
+
<View>
|
|
319
|
+
{!hide_progress_bar && poll ?
|
|
320
|
+
<View style={{ backgroundColor:Colors.shades.shade600 }}>
|
|
321
|
+
<CampaignProgressBar
|
|
322
|
+
poll_campaign={poll_campaign}
|
|
323
|
+
poll_responses={poll_responses}
|
|
324
|
+
polls={polls}
|
|
325
|
+
onPollSelect={(p) => {
|
|
326
|
+
|
|
327
|
+
if(poll.status == 'active' && (!poll_response || poll_response.status == 'pending' && poll.seconds_allowed)){ return }
|
|
328
|
+
let index = polls.findIndex(ps => ps.poll_id == p.poll_id)
|
|
329
|
+
setData({ ...data, active_poll_index:index })
|
|
330
|
+
}}
|
|
331
|
+
active_poll={poll.poll_id}
|
|
332
|
+
/>
|
|
192
333
|
</View>
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
334
|
+
:<></>}
|
|
335
|
+
<View style={{ width: flash_size.width, flexDirection:'row', flexWrap:'wrap' }}>
|
|
336
|
+
<View style={{ flex:1, flexGrow:2, minWidth:350, }}>
|
|
337
|
+
<View style={{ flexDirection:'row', alignItems:'center', padding:10, borderBottomWidth:1, borderBottomColor:Colors.shades.shade600 }}>
|
|
338
|
+
<View style={{ padding:10, justifyContent:'center', alignItems:'center' }}>
|
|
339
|
+
<Image
|
|
340
|
+
source={{ uri: poll.poll_image?.url ?? 'https://res.cloudinary.com/hoabts6mc/image/upload/v1718979933/question_mark_ro0ac5.webp' }}
|
|
341
|
+
style={{ height:image_size, width:image_size }}
|
|
342
|
+
resizeMode='center'
|
|
343
|
+
/>
|
|
344
|
+
{poll.status == 'active' && poll.seconds_allowed && (!poll_response || poll_response.status == 'pending')?
|
|
345
|
+
<View style={{ justifyContent:'center', alignItems:'center'}}>
|
|
346
|
+
<ResponseTimer
|
|
347
|
+
poll_id={poll.poll_id}
|
|
348
|
+
seconds={poll.seconds_allowed}
|
|
349
|
+
onTimesUp={() => handleTimesUp()}
|
|
350
|
+
/>
|
|
351
|
+
</View>
|
|
352
|
+
:
|
|
353
|
+
<View style={{ flexDirection:'row', borderRadius:22, backgroundColor:poll.status == 'active' ? Colors.utility.success : Colors.utility.error, padding:5 }}>
|
|
354
|
+
{poll.status == 'active' ?
|
|
355
|
+
<Icons.InProgressIcon size={18} color={Colors.shades.white} />
|
|
356
|
+
:
|
|
357
|
+
<Icons.LockClosedIcon size={16} color={Colors.shades.white} />
|
|
358
|
+
}
|
|
359
|
+
<Text style={{ marginLeft:4 }} size={14} color={Colors.shades.white}>{poll.status.toUpperCase()}</Text>
|
|
360
|
+
</View>
|
|
361
|
+
}
|
|
362
|
+
</View>
|
|
363
|
+
<View style={{ flex:1 }}>
|
|
364
|
+
{loading ?
|
|
365
|
+
<ActivityIndicator size='large' color={Colors.brand.midnight} style={{ alignSelf:'center' }} />
|
|
366
|
+
:
|
|
367
|
+
<Text size={16} color={Colors.brand.midnight} weight='bold'>{poll.poll_question}</Text>
|
|
368
|
+
}
|
|
369
|
+
</View>
|
|
370
|
+
</View>
|
|
202
371
|
</View>
|
|
203
|
-
|
|
204
|
-
<View style={{
|
|
205
|
-
<View style={{flexDirection:'row',
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
autoFocus
|
|
210
|
-
value={poll_response.stake as string}
|
|
211
|
-
onChangeText={(text) => setData({
|
|
212
|
-
...data,
|
|
213
|
-
poll_response: { ...poll_response, stake:text }
|
|
214
|
-
})}
|
|
215
|
-
/>
|
|
372
|
+
|
|
373
|
+
<View style={{ flexGrow:1, flexDirection:'row' }}>
|
|
374
|
+
<View nativeID='poll_options' style={{ flex:1, maxWidth:flash_size.width, padding:5, flexDirection:'row', flexWrap:'wrap', alignItems:'center'}}>
|
|
375
|
+
{visible_options.sort((a,b) => a.priority - b.priority).map((po, i) => {
|
|
376
|
+
return renderPollOptions({ item:po, index:i, show_summary:(poll_response && poll_response.status != 'pending') || poll.status == 'closed' ? true : false })
|
|
377
|
+
})}
|
|
216
378
|
</View>
|
|
379
|
+
{poll_response?.status == 'pending' ?
|
|
380
|
+
<View style={{ flex:1, justifyContent:'space-between', backgroundColor:Colors.shades.shade600 }}>
|
|
381
|
+
<View style={{ padding:10, borderBottomWidth:1, borderBottomColor:Colors.shades.shade100 }}>
|
|
382
|
+
<Text size={16} color={Colors.brand.midnight} textAlign='center' weight='bold'>{poll.confidence_allowed ? 'HOW MUCH?': 'ARE YOU SURE?'}</Text>
|
|
383
|
+
</View>
|
|
384
|
+
{poll.confidence_allowed ?
|
|
385
|
+
<View style={{ flex:1, padding:5 }}>
|
|
386
|
+
<View style={{flexDirection:'row', backgroundColor:Colors.shades.white, borderRadius:22 }}>
|
|
387
|
+
<Text style={{ padding:10 }}>{poll.market_type == 'FOR_MONEY' ? '$' : 'E'}</Text>
|
|
388
|
+
<TextInput
|
|
389
|
+
style={{ padding:10, borderWidth:0, borderTopLeftRadius:0, borderBottomLeftRadius:0, backgroundColor:'transparent', width: flash_size.width * 0.22,}}
|
|
390
|
+
autoFocus
|
|
391
|
+
value={poll_response.stake as string}
|
|
392
|
+
onChangeText={(text) => setPollData({
|
|
393
|
+
...poll_data,
|
|
394
|
+
poll_response: { ...poll_response, stake:text }
|
|
395
|
+
})}
|
|
396
|
+
/>
|
|
397
|
+
</View>
|
|
398
|
+
</View>
|
|
399
|
+
:<View style={{flex:1, padding:5}} />}
|
|
400
|
+
<View style={{ flexDirection:'row' }}>
|
|
401
|
+
{selected_option ?
|
|
402
|
+
<Button
|
|
403
|
+
title='X'
|
|
404
|
+
style={{ borderRadius:0 }}
|
|
405
|
+
padding={15}
|
|
406
|
+
title_color={Colors.shades.white}
|
|
407
|
+
backgroundColor={Colors.utility.error}
|
|
408
|
+
onPress={() => handleSelectOption(selected_option)}
|
|
409
|
+
/>
|
|
410
|
+
:<></>}
|
|
411
|
+
<Button
|
|
412
|
+
title='SUBMIT'
|
|
413
|
+
style={{ flex:1, borderRadius:0 }}
|
|
414
|
+
padding={15}
|
|
415
|
+
title_color={Colors.shades.white}
|
|
416
|
+
backgroundColor={Colors.utility.success}
|
|
417
|
+
onPress={() => handleSubmit()}
|
|
418
|
+
/>
|
|
419
|
+
</View>
|
|
420
|
+
</View>
|
|
421
|
+
:<></>}
|
|
217
422
|
</View>
|
|
218
|
-
:<View style={{flex:1}} />}
|
|
219
|
-
<TouchableOpacity style={{ marginTop:10, backgroundColor:Colors.utility.success, padding:10, paddingLeft:20, paddingRight:20, justifyContent:'center', alignItems:'center' }}
|
|
220
|
-
onPress={() => handleSubmit()}>
|
|
221
|
-
<Text weight='bold' size={14} color={Colors.shades.white}>SUBMIT</Text>
|
|
222
|
-
</TouchableOpacity>
|
|
223
423
|
</View>
|
|
224
|
-
</
|
|
225
|
-
|
|
424
|
+
</View>
|
|
425
|
+
}
|
|
226
426
|
</View>
|
|
427
|
+
{next_allowed && !show_leaders ?
|
|
428
|
+
<TouchableOpacity
|
|
429
|
+
style={{ position:'absolute', bottom: 10, right:10, backgroundColor:Colors.brand.electric, ...view_styles.float, borderRadius:100, height:50, width:50, justifyContent:'center', alignItems:'center' }}
|
|
430
|
+
onPress={() => {
|
|
431
|
+
if(!active_poll_index && active_poll_index != 0){ return }
|
|
432
|
+
let last_poll = active_poll_index == polls.length -1 ? true : false
|
|
433
|
+
if(last_poll && campaign_complete){ return setData({ ...data, show_leaders:true }) }
|
|
434
|
+
setData({ ...data, active_poll_index: active_poll_index + 1 })
|
|
435
|
+
}}
|
|
436
|
+
>
|
|
437
|
+
<Icons.ChevronIcon direction='right' color={Colors.shades.white} size={18} />
|
|
438
|
+
</TouchableOpacity>
|
|
439
|
+
:<></>}
|
|
227
440
|
</View>
|
|
228
441
|
)
|
|
229
442
|
}
|
package/src/Poll/index.tsx
CHANGED
|
@@ -5,33 +5,36 @@ import FlashMarket from './flashmarket';
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
type PollCampaignModuleProps = {
|
|
8
|
-
poll_campaign_id
|
|
8
|
+
poll_campaign_id:string,
|
|
9
9
|
poll_id?:string,
|
|
10
10
|
player_id?:string,
|
|
11
11
|
height?:number,
|
|
12
12
|
width?:number,
|
|
13
|
-
type: '
|
|
14
|
-
onRequestAuthenticate: () => void
|
|
13
|
+
type: 'full' | 'mini',
|
|
14
|
+
onRequestAuthenticate: (auth_strategy_id?:string, company_id?:string) => void,
|
|
15
|
+
onComplete:() => void
|
|
15
16
|
}
|
|
16
|
-
const PollCampaign = ({ poll_campaign_id, poll_id, type, player_id, onRequestAuthenticate }: PollCampaignModuleProps ) => {
|
|
17
|
+
const PollCampaign = ({ poll_campaign_id, poll_id, type, player_id, onRequestAuthenticate, onComplete }: PollCampaignModuleProps ) => {
|
|
17
18
|
const [ loaded, setLoaded ] = useState(false);
|
|
18
19
|
useEffect(() => {
|
|
19
20
|
PollCampaignApi.setEnvironment();
|
|
20
21
|
setLoaded(true)
|
|
21
22
|
},[])
|
|
22
23
|
if(!loaded){ return <></> }
|
|
23
|
-
if(type == '
|
|
24
|
+
if(type == 'full' && poll_campaign_id){
|
|
24
25
|
return (
|
|
25
26
|
<CampaignPlay
|
|
26
|
-
|
|
27
|
+
player_id={player_id}
|
|
28
|
+
onRequestAuthenticate={onRequestAuthenticate}
|
|
27
29
|
poll_campaign_id={poll_campaign_id}
|
|
28
|
-
onFinished={
|
|
30
|
+
onFinished={onComplete}
|
|
29
31
|
/>
|
|
30
32
|
)
|
|
31
33
|
}
|
|
32
|
-
if(type == '
|
|
34
|
+
if(type == 'mini'){
|
|
33
35
|
return (
|
|
34
36
|
<FlashMarket
|
|
37
|
+
poll_campaign_id={poll_campaign_id}
|
|
35
38
|
poll_id={poll_id}
|
|
36
39
|
player_id={player_id}
|
|
37
40
|
onRequestAuthenticate={onRequestAuthenticate}
|