be-components 0.7.6 → 0.7.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/lib/commonjs/Poll/api/index.js +63 -18
  2. package/lib/commonjs/Poll/api/index.js.map +1 -1
  3. package/lib/commonjs/Poll/components/CampaignPlay.js +1 -1
  4. package/lib/commonjs/Poll/components/CampaignPlay.js.map +1 -1
  5. package/lib/commonjs/Poll/components/CampaignProgressBar.js +1 -0
  6. package/lib/commonjs/Poll/components/CampaignProgressBar.js.map +1 -1
  7. package/lib/commonjs/Poll/components/CampaignResult.js +2 -2
  8. package/lib/commonjs/Poll/components/CampaignResult.js.map +1 -1
  9. package/lib/commonjs/Poll/components/ResponseTimer.js.map +1 -1
  10. package/lib/commonjs/Poll/flashmarket/ResultCard.js +419 -0
  11. package/lib/commonjs/Poll/flashmarket/ResultCard.js.map +1 -0
  12. package/lib/commonjs/Poll/flashmarket/index.js +355 -68
  13. package/lib/commonjs/Poll/flashmarket/index.js.map +1 -1
  14. package/lib/commonjs/Poll/index.js +8 -5
  15. package/lib/commonjs/Poll/index.js.map +1 -1
  16. package/lib/module/Poll/api/index.js +63 -18
  17. package/lib/module/Poll/api/index.js.map +1 -1
  18. package/lib/module/Poll/components/CampaignPlay.js +1 -1
  19. package/lib/module/Poll/components/CampaignPlay.js.map +1 -1
  20. package/lib/module/Poll/components/CampaignProgressBar.js +1 -0
  21. package/lib/module/Poll/components/CampaignProgressBar.js.map +1 -1
  22. package/lib/module/Poll/components/CampaignResult.js +2 -2
  23. package/lib/module/Poll/components/CampaignResult.js.map +1 -1
  24. package/lib/module/Poll/components/ResponseTimer.js.map +1 -1
  25. package/lib/module/Poll/flashmarket/ResultCard.js +410 -0
  26. package/lib/module/Poll/flashmarket/ResultCard.js.map +1 -0
  27. package/lib/module/Poll/flashmarket/index.js +357 -70
  28. package/lib/module/Poll/flashmarket/index.js.map +1 -1
  29. package/lib/module/Poll/index.js +8 -5
  30. package/lib/module/Poll/index.js.map +1 -1
  31. package/lib/typescript/src/Poll/api/index.d.ts +7 -2
  32. package/lib/typescript/src/Poll/api/index.d.ts.map +1 -1
  33. package/lib/typescript/src/Poll/components/CampaignPlay.d.ts +1 -1
  34. package/lib/typescript/src/Poll/components/CampaignPlay.d.ts.map +1 -1
  35. package/lib/typescript/src/Poll/components/CampaignProgressBar.d.ts.map +1 -1
  36. package/lib/typescript/src/Poll/components/ResponseTimer.d.ts.map +1 -1
  37. package/lib/typescript/src/Poll/flashmarket/ResultCard.d.ts +12 -0
  38. package/lib/typescript/src/Poll/flashmarket/ResultCard.d.ts.map +1 -0
  39. package/lib/typescript/src/Poll/flashmarket/index.d.ts +5 -3
  40. package/lib/typescript/src/Poll/flashmarket/index.d.ts.map +1 -1
  41. package/lib/typescript/src/Poll/index.d.ts +5 -4
  42. package/lib/typescript/src/Poll/index.d.ts.map +1 -1
  43. package/package.json +1 -1
  44. package/src/Poll/api/index.ts +54 -16
  45. package/src/Poll/components/CampaignPlay.tsx +2 -2
  46. package/src/Poll/components/CampaignProgressBar.tsx +1 -2
  47. package/src/Poll/components/CampaignResult.tsx +2 -2
  48. package/src/Poll/components/ResponseTimer.tsx +1 -0
  49. package/src/Poll/flashmarket/ResultCard.tsx +194 -0
  50. package/src/Poll/flashmarket/index.tsx +309 -96
  51. package/src/Poll/index.tsx +11 -8
@@ -0,0 +1,194 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { Image, View, TouchableOpacity, ActivityIndicator } from 'react-native';
3
+ import type { PollCampaignLeaderProps, PollProps, PollResponseProps, PublicPlayerProps } from '../../types';
4
+ import { PollCampaignApi, PollCampaignHelpers } from '../api';
5
+ import { Icons, Text } from '../../Components';
6
+ import Colors from '../../constants/colors';
7
+ import { view_styles } from '../../constants/styles';
8
+ type ResultCardProps = {
9
+ poll_campaign_id:string,
10
+ width:number,
11
+ polls:PollProps[],
12
+ poll_responses:PollResponseProps[],
13
+ onClose:() => void
14
+ }
15
+
16
+ const ResultCard = ({ poll_campaign_id, polls, width, poll_responses, onClose }:ResultCardProps) => {
17
+ const [ result_data, setData ] = useState<{
18
+ loading:boolean,
19
+ offset:number,
20
+ players:PublicPlayerProps[]
21
+ my_leader?:PollCampaignLeaderProps,
22
+ selected_leader?:PollCampaignLeaderProps,
23
+ poll_campaign_leaders:PollCampaignLeaderProps[]
24
+ }>({
25
+ loading:false,
26
+ offset:0,
27
+ players:[],
28
+ poll_campaign_leaders:[]
29
+ })
30
+
31
+ const { loading, offset, poll_campaign_leaders, players, my_leader, selected_leader } = result_data;
32
+
33
+ useEffect(() => {
34
+ getResultsFromServer(0)
35
+ },[poll_campaign_id])
36
+
37
+ const getResultsFromServer = async(offset:number) => {
38
+ setData({ ...result_data, loading: true })
39
+ const resp = await PollCampaignApi.getLeadersByCampaignId(poll_campaign_id, offset)
40
+ const player_ids = resp.poll_campaign_leaders.map(l => l.player_id);
41
+ const ps = await PollCampaignApi.getPlayersByPlayerIds(player_ids);
42
+ let new_my_leader:PollCampaignLeaderProps|undefined = my_leader;
43
+ if(!new_my_leader){ new_my_leader = resp.my_leaderboard }
44
+ setData({
45
+ ...result_data,
46
+ loading:false,
47
+ poll_campaign_leaders: resp.poll_campaign_leaders,
48
+ my_leader: new_my_leader,
49
+ players:players.concat(ps),
50
+ offset:offset
51
+ })
52
+ }
53
+
54
+ /*
55
+ const renderTrophy = (place:number) => {
56
+ switch(place){
57
+ case 1: return <Icons.TrophyIcon color={Colors.incentive.gold} size={16}/>
58
+ case 2: return <Icons.TrophyIcon color={Colors.incentive.silver} size={16}/>
59
+ case 3: return <Icons.TrophyIcon color={Colors.incentive.bronze} size={16}/>
60
+ default: return <></>
61
+ }
62
+ }
63
+ */
64
+
65
+ const renderLeaders = (data: {item:PollCampaignLeaderProps, index:number}) => {
66
+ const player = players.find(p => p.player_id == data.item.player_id);
67
+ if(!player){ return <></> }
68
+ return (
69
+ <TouchableOpacity style={{ width:(width/5)-10, flexDirection:'row', alignItems:'center', margin:4, padding:10, borderRadius:22, backgroundColor:Colors.shades.white }}
70
+ onPress={() => setData({ ...result_data, selected_leader: { ...data.item, place: parseInt(`${offset>0?offset:''}${(data.index+1)}`) } } )}>
71
+ {width > 1000 ?
72
+ <View nativeID="place" style={{ margin:5, height:20, width:20, justifyContent:'center', alignItems:'center', borderRadius:100, borderWidth:1, borderColor:Colors.brand.slate }}>
73
+ <Text size={10} color={Colors.brand.midnight} weight='bold' textAlign="center">{offset>0?offset:''}{(data.index+1)}</Text>
74
+ </View>
75
+ :<></>}
76
+ <View nativeID="player" style={{ flex:1, flexDirection:width>1000?'row':'column', alignItems:'center' }}>
77
+ <View nativeID="profile_pic" style={{ marginRight:width>1000?10:0 }}>
78
+ <Image
79
+ source={{ uri: player.profile_pic && player.profile_pic != '' ? player.profile_pic : 'https://res.cloudinary.com/hoabts6mc/image/upload/v1689262384/default-avatar_bbkn2t.png' }}
80
+ style={{ height:40, width:40, borderRadius:100 }}
81
+ resizeMode='cover'
82
+ />
83
+ </View>
84
+ <View style={{ flex:1 }} nativeID="name">
85
+ {width > 600 ?
86
+ <Text size={14} color={Colors.brand.midnight} weight='bold'>{player.username}</Text>
87
+ :<></>}
88
+ <Text style={{ marginTop:3 }} size={12} color={Colors.brand.midnight} weight='regular' textAlign={width>1000?'left':'center'}>{data.item.winnings.toFixed(2)} Points</Text>
89
+ </View>
90
+
91
+ </View>
92
+ </TouchableOpacity>
93
+ )
94
+ }
95
+
96
+ const me = players.find(p => p.player_id == my_leader?.player_id);
97
+ //const questions_answered = poll_responses.length
98
+ let correct_answers = poll_responses.filter(pr => pr.result_ind == 'win').length
99
+ //let incorrect_answers = poll_responses.filter(pr => pr.result_ind == 'lose').length
100
+ let ungraded_answers = poll_responses.filter(pr => !pr.result_ind).length
101
+ const selected_player = players.find(p => p.player_id == selected_leader?.player_id);
102
+ return (
103
+ <View>
104
+ <View nativeID="my_results" style={{ padding:10, backgroundColor:Colors.incentive.gold_faded }}>
105
+ {me && my_leader ?
106
+ <View style={{ flexDirection:'row', alignItems:'center' }}>
107
+ <View style={{ padding:10, paddingRight:20, paddingLeft:20, flexDirection:width>600 ?'row': 'column', alignItems:'center', justifyContent:'center' }}>
108
+ <Image
109
+ source={{ uri: me.profile_pic && me.profile_pic != '' ? me.profile_pic : 'https://res.cloudinary.com/hoabts6mc/image/upload/v1689262384/default-avatar_bbkn2t.png' }}
110
+ style={{ height:40, width:40, borderRadius:100 }}
111
+ resizeMode='cover'
112
+ />
113
+ <View style={{ marginLeft:width > 600 ? 10: 0 }}>
114
+ <Text size={14} color={Colors.brand.midnight} weight='bold' textAlign={width > 600 ? 'left':'center'}>{me.username}</Text>
115
+ <Text style={{ marginTop:3 }} size={12} color={Colors.brand.midnight} weight='regular' textAlign={width>600?'left':'center'}>{my_leader.winnings.toFixed(2)} Points</Text>
116
+ </View>
117
+ </View>
118
+ <View style={{ flex:1, flexDirection:'row', alignItems:'center' }}>
119
+ <View nativeID="total_questions" style={{ flex:1, justifyContent:'center', alignItems:'center' }}>
120
+ <Text size={12} color={Colors.brand.slate} weight='semibold'>TOTAL QUESTIONS</Text>
121
+ <Text style={{ marginTop:5 }} size={14} color={Colors.brand.midnight} weight='bold'>{polls.length} Questions</Text>
122
+ </View>
123
+ <View nativeID="completion_pct" style={{ flex:1, justifyContent:'center', alignItems:'center' }}>
124
+ <Text size={12} color={Colors.brand.slate} weight='semibold'>COMPLETION</Text>
125
+ <Text style={{ marginTop:5 }} size={14} color={Colors.brand.midnight} weight='bold'>{(((polls.length - ungraded_answers) / polls.length) * 100).toFixed()}%</Text>
126
+ </View>
127
+ <View nativeID="total_questions" style={{ flex:1, justifyContent:'center', alignItems:'center' }}>
128
+ <Text size={12} color={Colors.brand.slate} weight='semibold'>SUCCESS RATE</Text>
129
+ <Text style={{ marginTop:5 }} size={14} color={Colors.brand.midnight} weight='bold'>{((correct_answers / polls.length)*100).toFixed()}%</Text>
130
+ </View>
131
+ </View>
132
+ </View>
133
+ :<></>}
134
+ </View>
135
+ <View>
136
+ <View style={{ flexDirection:'row', alignItems:'center', flexWrap:'wrap' }}>
137
+ {poll_campaign_leaders.map((l, i) => {
138
+ return (
139
+ renderLeaders({ item: l, index:i })
140
+ )
141
+ })}
142
+ {loading ?
143
+ <View style={{ position:'absolute', top:0, left:0, right:0, bottom:0, justifyContent:'center', alignItems:'center' }}>
144
+ <ActivityIndicator size='large' color={Colors.brand.midnight} />
145
+ </View>
146
+ :<></>}
147
+ </View>
148
+ {offset > 0 ?
149
+ <TouchableOpacity style={{ position:'absolute', left:10, top:-15, borderRadius:100, height:30, width:30, justifyContent:'center', alignItems:'center', backgroundColor:Colors.shades.white, ...view_styles.float }}
150
+ onPress={async() => {
151
+ getResultsFromServer(offset - 1)
152
+ }}>
153
+ <Icons.ChevronIcon direction='left' color={Colors.brand.midnight} size={12} />
154
+ </TouchableOpacity>
155
+ :<></>}
156
+ <TouchableOpacity style={{ position:'absolute', right:10, top:-15, borderRadius:100, height:30, width:30, justifyContent:'center', alignItems:'center', backgroundColor:Colors.shades.white, ...view_styles.float }}
157
+ onPress={async() => {
158
+ getResultsFromServer(offset + 1)
159
+ }}>
160
+ <Icons.ChevronIcon direction='right' color={Colors.brand.midnight} size={12} />
161
+ </TouchableOpacity>
162
+ {selected_leader && selected_player ?
163
+ <TouchableOpacity style={{ position:'absolute', top:0, left:0, right:0, bottom:0, backgroundColor:Colors.shades.black_faded_heavy, justifyContent:'center', alignItems:'center' }} onPress={() => setData({ ...result_data, selected_leader: undefined })}>
164
+ <View style={{ flexDirection:'row', backgroundColor:Colors.shades.white, borderRadius:8, ...view_styles.float }}>
165
+ <View>
166
+ <Image
167
+ source={{ uri: selected_player.profile_pic }}
168
+ style={{ height:70, width:70, borderTopLeftRadius:8, borderBottomLeftRadius:8 }}
169
+ resizeMode='cover'
170
+ />
171
+ </View>
172
+ <View style={{ flex:1, padding:10 }}>
173
+ <Text size={16} color={Colors.brand.midnight} weight='bold'>{selected_player.username}</Text>
174
+ <Text style={{ marginTop:5 }} size={14} color={Colors.brand.midnight} weight='regular'>{selected_leader.winnings.toFixed(2)} Points</Text>
175
+ </View>
176
+ <View style={{ paddingRight:15, paddingLeft:15, borderTopRightRadius:8, borderBottomRightRadius:8, backgroundColor:Colors.incentive.gold_faded, justifyContent:'center', alignItems:'center' }}>
177
+ <Text size={18} color={Colors.brand.midnight} weight='bold' textAlign='center'>{PollCampaignHelpers.formatPlace(selected_leader.place)}</Text>
178
+ </View>
179
+ </View>
180
+ </TouchableOpacity>
181
+ :<></>}
182
+ </View>
183
+ <View style={{ flexDirection:'row', padding:10 }}>
184
+ <TouchableOpacity style={{ flexDirection:'row', alignItems:'center' }} onPress={() => onClose()}>
185
+ <Icons.ChevronIcon size={14} direction='left' color={Colors.brand.midnight} />
186
+ <Text style={{ marginLeft:15 }} size={14} color={Colors.brand.midnight} weight='bold'>Review Questions</Text>
187
+ </TouchableOpacity>
188
+ </View>
189
+ </View>
190
+ )
191
+
192
+ }
193
+
194
+ export default ResultCard