be-components 1.9.6 → 1.9.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.
Files changed (89) hide show
  1. package/lib/commonjs/CompetitionManager/components/AdminCompetitionList.js +4 -3
  2. package/lib/commonjs/CompetitionManager/components/AdminCompetitionList.js.map +1 -1
  3. package/lib/commonjs/Components/Icons.js +41 -0
  4. package/lib/commonjs/Components/Icons.js.map +1 -1
  5. package/lib/commonjs/MarketComponents/api/index.js +10 -1
  6. package/lib/commonjs/MarketComponents/api/index.js.map +1 -1
  7. package/lib/commonjs/MarketComponents/components/TeamEventMarket/index.js +13 -2
  8. package/lib/commonjs/MarketComponents/components/TeamEventMarket/index.js.map +1 -1
  9. package/lib/commonjs/Poll/components/CampaignHeader.js +53 -0
  10. package/lib/commonjs/Poll/components/CampaignHeader.js.map +1 -0
  11. package/lib/commonjs/Poll/components/CampaignLeaderboard.js +295 -0
  12. package/lib/commonjs/Poll/components/CampaignLeaderboard.js.map +1 -0
  13. package/lib/commonjs/Poll/components/CampaignPlay.js +11 -89
  14. package/lib/commonjs/Poll/components/CampaignPlay.js.map +1 -1
  15. package/lib/commonjs/Poll/components/CampaignProgressBar.js +0 -1
  16. package/lib/commonjs/Poll/components/CampaignProgressBar.js.map +1 -1
  17. package/lib/commonjs/Poll/components/CampaignResult.js +44 -345
  18. package/lib/commonjs/Poll/components/CampaignResult.js.map +1 -1
  19. package/lib/commonjs/Poll/components/PollCard.js +2 -1
  20. package/lib/commonjs/Poll/components/PollCard.js.map +1 -1
  21. package/lib/commonjs/Poll/components/PollQuestionsSection.js +81 -0
  22. package/lib/commonjs/Poll/components/PollQuestionsSection.js.map +1 -0
  23. package/lib/commonjs/Poll/components/PollSelectCard.js +1 -2
  24. package/lib/commonjs/Poll/components/PollSelectCard.js.map +1 -1
  25. package/lib/commonjs/Poll/index.js +132 -36
  26. package/lib/commonjs/Poll/index.js.map +1 -1
  27. package/lib/module/CompetitionManager/components/AdminCompetitionList.js +5 -4
  28. package/lib/module/CompetitionManager/components/AdminCompetitionList.js.map +1 -1
  29. package/lib/module/Components/Icons.js +41 -0
  30. package/lib/module/Components/Icons.js.map +1 -1
  31. package/lib/module/MarketComponents/api/index.js +10 -1
  32. package/lib/module/MarketComponents/api/index.js.map +1 -1
  33. package/lib/module/MarketComponents/components/TeamEventMarket/index.js +13 -2
  34. package/lib/module/MarketComponents/components/TeamEventMarket/index.js.map +1 -1
  35. package/lib/module/Poll/components/CampaignHeader.js +46 -0
  36. package/lib/module/Poll/components/CampaignHeader.js.map +1 -0
  37. package/lib/module/Poll/components/CampaignLeaderboard.js +286 -0
  38. package/lib/module/Poll/components/CampaignLeaderboard.js.map +1 -0
  39. package/lib/module/Poll/components/CampaignPlay.js +11 -89
  40. package/lib/module/Poll/components/CampaignPlay.js.map +1 -1
  41. package/lib/module/Poll/components/CampaignProgressBar.js +0 -1
  42. package/lib/module/Poll/components/CampaignProgressBar.js.map +1 -1
  43. package/lib/module/Poll/components/CampaignResult.js +48 -348
  44. package/lib/module/Poll/components/CampaignResult.js.map +1 -1
  45. package/lib/module/Poll/components/PollCard.js +2 -1
  46. package/lib/module/Poll/components/PollCard.js.map +1 -1
  47. package/lib/module/Poll/components/PollQuestionsSection.js +72 -0
  48. package/lib/module/Poll/components/PollQuestionsSection.js.map +1 -0
  49. package/lib/module/Poll/components/PollSelectCard.js +1 -2
  50. package/lib/module/Poll/components/PollSelectCard.js.map +1 -1
  51. package/lib/module/Poll/index.js +133 -38
  52. package/lib/module/Poll/index.js.map +1 -1
  53. package/lib/typescript/src/CompetitionManager/components/AdminCompetitionList.d.ts +2 -2
  54. package/lib/typescript/src/CompetitionManager/components/AdminCompetitionList.d.ts.map +1 -1
  55. package/lib/typescript/src/Components/Icons.d.ts +1 -0
  56. package/lib/typescript/src/Components/Icons.d.ts.map +1 -1
  57. package/lib/typescript/src/MarketComponents/api/index.d.ts +1 -0
  58. package/lib/typescript/src/MarketComponents/api/index.d.ts.map +1 -1
  59. package/lib/typescript/src/MarketComponents/components/TeamEventMarket/index.d.ts.map +1 -1
  60. package/lib/typescript/src/Poll/components/CampaignHeader.d.ts +9 -0
  61. package/lib/typescript/src/Poll/components/CampaignHeader.d.ts.map +1 -0
  62. package/lib/typescript/src/Poll/components/CampaignLeaderboard.d.ts +12 -0
  63. package/lib/typescript/src/Poll/components/CampaignLeaderboard.d.ts.map +1 -0
  64. package/lib/typescript/src/Poll/components/CampaignPlay.d.ts.map +1 -1
  65. package/lib/typescript/src/Poll/components/CampaignProgressBar.d.ts.map +1 -1
  66. package/lib/typescript/src/Poll/components/CampaignResult.d.ts +3 -7
  67. package/lib/typescript/src/Poll/components/CampaignResult.d.ts.map +1 -1
  68. package/lib/typescript/src/Poll/components/PollCard.d.ts.map +1 -1
  69. package/lib/typescript/src/Poll/components/PollQuestionsSection.d.ts +11 -0
  70. package/lib/typescript/src/Poll/components/PollQuestionsSection.d.ts.map +1 -0
  71. package/lib/typescript/src/Poll/components/PollSelectCard.d.ts +1 -2
  72. package/lib/typescript/src/Poll/components/PollSelectCard.d.ts.map +1 -1
  73. package/lib/typescript/src/Poll/index.d.ts +4 -2
  74. package/lib/typescript/src/Poll/index.d.ts.map +1 -1
  75. package/package.json +1 -1
  76. package/src/CompetitionManager/components/AdminCompetitionList.tsx +6 -6
  77. package/src/Components/Icons.tsx +16 -0
  78. package/src/MarketComponents/api/index.ts +10 -1
  79. package/src/MarketComponents/components/TeamEventMarket/index.tsx +12 -1
  80. package/src/Poll/components/CampaignHeader.tsx +35 -0
  81. package/src/Poll/components/CampaignLeaderboard.tsx +181 -0
  82. package/src/Poll/components/CampaignPlay.tsx +11 -82
  83. package/src/Poll/components/CampaignProgressBar.tsx +0 -1
  84. package/src/Poll/components/CampaignResult.tsx +42 -162
  85. package/src/Poll/components/PollCard.tsx +2 -1
  86. package/src/Poll/components/PollQuestionsSection.tsx +66 -0
  87. package/src/Poll/components/PollSelectCard.tsx +2 -3
  88. package/src/Poll/index.tsx +120 -31
  89. package/src/types.d.ts +1 -0
@@ -46,6 +46,7 @@ const TeamEventMarket = ({ event, init_expanded, show_id, activate_loading, comp
46
46
  expanded:false,
47
47
  athletes:[]
48
48
  })
49
+ const [ sponsor, setSponsor ] = useState(false);
49
50
  const [ competitions_expanded, setCompetitionsExpanded ] = useState(false);
50
51
  const { expanded, athletes, loaded, loading } = expanded_data;
51
52
  const event_status = TeamEventMarketHelpers.getEventStatus(event);
@@ -54,8 +55,15 @@ const TeamEventMarket = ({ event, init_expanded, show_id, activate_loading, comp
54
55
  useEffect(() => {
55
56
  MarketComponentApi.setEnvironment();
56
57
  if(init_expanded){ expandedEvent(); }
58
+ if(event.sponsor_id){ getCompanyFromServer(event.sponsor_id) }
57
59
  },[])
58
60
 
61
+ const getCompanyFromServer = async(company_id:string) => {
62
+ const resp = await MarketComponentApi.getCompanyById(company_id)
63
+ if(!resp?.company){ return }
64
+ setSponsor(resp.company)
65
+ }
66
+
59
67
  const expandedEvent = async() => {
60
68
  if(!event){ return }
61
69
  if(onExpand){ onExpand(expanded ? false : true) }
@@ -214,6 +222,9 @@ const TeamEventMarket = ({ event, init_expanded, show_id, activate_loading, comp
214
222
  const { non_primary_markets, available } = TeamEventMarketHelpers.sortNonPrimaryMarkets(TeamEventMarketHelpers.getNonPrimaryMarkets(event, markets), event_order_stats, latest_trades)
215
223
  return (
216
224
  <View style={{ ...view_styles.section, borderWidth:1, borderColor:Colors.shades.shade600 }}>
225
+ {sponsor ?
226
+ <Text>HEY</Text>
227
+ :<></>}
217
228
  <View nativeID='event_header_data' style={{ flexDirection:'row', padding:10, borderBottomWidth:1, borderBottomColor:Colors.shades.shade600 }}>
218
229
  {onActivate && event_status != 'closed' ?
219
230
  <Button
@@ -297,7 +308,7 @@ const TeamEventMarket = ({ event, init_expanded, show_id, activate_loading, comp
297
308
  </View>
298
309
  <FlatList
299
310
  key={`${event.event_id}_primary_markets`}
300
- data={primary_markets}
311
+ data={primary_markets.sort((a,b) => parseInt(a.market_id) - parseInt(b.market_id))}
301
312
  horizontal
302
313
  renderItem={renderPrimaryMarkets}
303
314
  keyExtractor={(item) => item.market_id.toString()}
@@ -0,0 +1,35 @@
1
+ import React from 'react';
2
+ import { Image, TouchableOpacity, View } from 'react-native';
3
+ import type { PollCampaignProps } from '../../types';
4
+ import { Icons, Text } from '../../Components';
5
+ import Colors from '../../constants/colors';
6
+
7
+ type CampaignHeaderProps = {
8
+ poll_campaign:PollCampaignProps,
9
+ onSharePollCampaign:(pc:PollCampaignProps) => void
10
+ }
11
+
12
+ const CampaignHeader = ({ poll_campaign, onSharePollCampaign }:CampaignHeaderProps) => {
13
+
14
+ return (
15
+ <View>
16
+ <View nativeID="competition_header" style={{ flexDirection:'row', alignItems:'center', padding:20, borderBottomWidth:1, borderColor:Colors.shades.shade600 }}>
17
+ <View>
18
+ <Image
19
+ source={{ uri: poll_campaign.campaign_image?.url ?? 'https://res.cloudinary.com/hoabts6mc/image/upload/v1649737862/be_logo_jte2ux.webp' }}
20
+ style={{ height:50, width:50, borderRadius:4 }}
21
+ resizeMode="cover"
22
+ />
23
+ </View>
24
+ <View style={{ flex:1, marginLeft:10 }}>
25
+ <Text theme='header'>{poll_campaign.name}</Text>
26
+ </View>
27
+ <TouchableOpacity style={{ paddingLeft:10 }} onPress={() => onSharePollCampaign(poll_campaign)}>
28
+ <Icons.ShareIcon color={Colors.brand.midnight} size={14} />
29
+ </TouchableOpacity>
30
+ </View>
31
+ </View>
32
+ )
33
+ }
34
+
35
+ export default CampaignHeader
@@ -0,0 +1,181 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { View, ScrollView, Image, FlatList, ActivityIndicator } from "react-native"
3
+ import type { PollCampaignLeaderProps, PollCampaignProps, PublicPlayerProps } from '../../types';
4
+ import { PollCampaignApi } from '../api';
5
+ import { Button, Icons, Text } from '../../Components';
6
+ import Colors from '../../constants/colors';
7
+ import { view_styles } from '../../constants/styles';
8
+
9
+ type CampaignLeaderboardProps = {
10
+ poll_campaign:PollCampaignProps,
11
+ view_mode: "short"|"full",
12
+ height?:number,
13
+ onShowFullLeaderboard?: () => void,
14
+ onClose?:() => void
15
+ }
16
+
17
+ const CampaignLeaderboard = ({ poll_campaign, height, view_mode, onShowFullLeaderboard, onClose }:CampaignLeaderboardProps) => {
18
+ const [ leaderboard_data, setLeaderData ] = useState<{
19
+ loading:boolean,
20
+ offset:number,
21
+ leaders:PollCampaignLeaderProps[],
22
+ players:PublicPlayerProps[],
23
+ my_leader?: PollCampaignLeaderProps
24
+ }>({
25
+ loading:false,
26
+ offset:0,
27
+ leaders:[],
28
+ players:[]
29
+ })
30
+ const { loading, leaders, players, my_leader, offset } = leaderboard_data;
31
+ const me = players.find(p => p.player_id == my_leader?.player_id);
32
+
33
+ let filtered_leaders = [ ...leaders ]
34
+ if(view_mode == 'short'){
35
+ filtered_leaders = filtered_leaders.sort((a,b) => a.place - b.place).slice(0,3);
36
+ }
37
+
38
+ useEffect(() => {
39
+ getDataFromServer(0);
40
+ },[poll_campaign.poll_campaign_id])
41
+
42
+ const getDataFromServer = async(offset:number) => {
43
+ setLeaderData({ ...leaderboard_data, loading:true })
44
+ const ls = await PollCampaignApi.getLeadersByCampaignId(poll_campaign.poll_campaign_id, offset)
45
+ const player_ids = ls.poll_campaign_leaders.map(l => l.player_id);
46
+ if(ls.my_leaderboard){
47
+ let my_id = player_ids.find(id => id == ls.my_leaderboard?.player_id);
48
+ if(!my_id){ player_ids.push(ls.my_leaderboard.player_id) }
49
+ }
50
+ const ps = await PollCampaignApi.getPlayersByPlayerIds(player_ids);
51
+ setLeaderData({
52
+ ...leaderboard_data,
53
+ players:ps,
54
+ offset,
55
+ loading: false,
56
+ leaders: ls.poll_campaign_leaders,
57
+ my_leader: ls.my_leaderboard
58
+ })
59
+ }
60
+
61
+ const renderTrophy = (place:number) => {
62
+ switch(place){
63
+ case 1: return <Icons.TrophyIcon color={Colors.incentive.gold} size={16}/>
64
+ case 2: return <Icons.TrophyIcon color={Colors.incentive.silver} size={16}/>
65
+ case 3: return <Icons.TrophyIcon color={Colors.incentive.bronze} size={16}/>
66
+ default: return <></>
67
+ }
68
+ }
69
+
70
+
71
+ const renderLeaders = (data: {item:PollCampaignLeaderProps, index:number}) => {
72
+ const player = players.find(p => p.player_id == data.item.player_id);
73
+ if(!player){ return <></> }
74
+ return (
75
+ <View style={{ flexDirection:'row', alignItems:'center', margin:4, padding:10, borderRadius:22, backgroundColor:Colors.shades.white, borderWidth:1, borderColor:Colors.shades.shade600 }}>
76
+ <View nativeID="place" style={{ margin:5, height:20, width:20, justifyContent:'center', alignItems:'center', borderRadius:100, borderWidth:1, borderColor:Colors.brand.slate }}>
77
+ <Text size={10} color={Colors.brand.midnight} weight='bold' textAlign="center">{offset > 0 ? offset:''}{data.index+1}</Text>
78
+ </View>
79
+ <View nativeID="player" style={{ flex:1, flexDirection:'row', alignItems:'center' }}>
80
+ <View nativeID="profile_pic" style={{ marginRight:10 }}>
81
+ <Image
82
+ source={{ uri: player.profile_pic && player.profile_pic != '' ? player.profile_pic : 'https://res.cloudinary.com/hoabts6mc/image/upload/v1689262384/default-avatar_bbkn2t.png' }}
83
+ style={{ height:40, width:40, borderRadius:100 }}
84
+ resizeMode='cover'
85
+ />
86
+ </View>
87
+ <View style={{ flex:1 }} nativeID="name">
88
+ <Text size={14} color={Colors.brand.midnight} weight='bold'>{player.username}</Text>
89
+ <Text style={{ marginTop:3 }} size={12} color={Colors.brand.midnight} weight='regular'>{data.item.winnings.toFixed(2)} Points</Text>
90
+ </View>
91
+ <View>
92
+ {renderTrophy(data.index+1)}
93
+ </View>
94
+ </View>
95
+ </View>
96
+ )
97
+ }
98
+
99
+ return (
100
+ <View style={{ flex:1, height:height, backgroundColor:Colors.shades.shade100 }}>
101
+ {my_leader && me ?
102
+ <View nativeID="my_results">
103
+ <View style={{ flexDirection:'row', alignItems:'center', margin:4, padding:10, borderRadius:22, backgroundColor:Colors.shades.white }}>
104
+ <View nativeID="place" style={{ margin:5, height:20, width:20, justifyContent:'center', alignItems:'center', borderRadius:100, borderWidth:1, borderColor:Colors.brand.slate }}>
105
+ <Text size={10} color={Colors.brand.midnight} weight='bold' textAlign="center">{my_leader.place}</Text>
106
+ </View>
107
+ <View nativeID="player" style={{ flex:1, flexDirection:'row', alignItems:'center' }}>
108
+ <View nativeID="profile_pic" style={{ marginRight:10 }}>
109
+ <Image
110
+ source={{ uri: me.profile_pic && me.profile_pic != '' ? me.profile_pic : 'https://res.cloudinary.com/hoabts6mc/image/upload/v1689262384/default-avatar_bbkn2t.png' }}
111
+ style={{ height:40, width:40, borderRadius:100 }}
112
+ resizeMode='cover'
113
+ />
114
+ </View>
115
+ <View style={{ flex:1 }} nativeID="name">
116
+ <Text size={14} color={Colors.brand.midnight} weight='bold'>{me.username}</Text>
117
+ <Text style={{ marginTop:3 }} size={12} color={Colors.brand.midnight} weight='regular'>{my_leader.winnings.toFixed(2)} Points</Text>
118
+ </View>
119
+ <View>
120
+ {renderTrophy(my_leader.place)}
121
+ </View>
122
+ </View>
123
+ </View>
124
+ </View>
125
+ :<></>}
126
+ <ScrollView style={{flex:1}}>
127
+ {loading ?
128
+ <ActivityIndicator size='large' color={Colors.brand.midnight} style={{ padding:10, alignSelf:'center' }} />
129
+ :<></>}
130
+ <FlatList
131
+ data={filtered_leaders}
132
+ renderItem={renderLeaders}
133
+ keyExtractor={((item) => item.player_id.toString())}
134
+ />
135
+ </ScrollView>
136
+ {view_mode == 'full' ?
137
+ <View style={{ flexDirection:'row', alignItems:'center' }}>
138
+ {offset > 0 ?
139
+ <Button
140
+ title='PREV'
141
+ title_color={Colors.brand.electric}
142
+ backgroundColor='transparent'
143
+ onPress={() => getDataFromServer(offset - 1)}
144
+ />
145
+ :<></>}
146
+ <View style={{flex:1}} />
147
+ <Button
148
+ title='NEXT'
149
+ title_color={Colors.brand.electric}
150
+ backgroundColor='transparent'
151
+ onPress={() => getDataFromServer(offset + 1)}
152
+ />
153
+ </View>
154
+ :<></>}
155
+ {view_mode == 'short' && onShowFullLeaderboard ?
156
+ <View style={{ ...view_styles.section_footer }}>
157
+ <Button
158
+ title='See Full Leaderboard'
159
+ style={{ flex:1, alignSelf:'center' }}
160
+ title_color={Colors.brand.electric}
161
+ backgroundColor='transparent'
162
+ onPress={() => onShowFullLeaderboard()}
163
+ />
164
+ </View>
165
+ :<></>}
166
+ {onClose ?
167
+ <View style={{ ...view_styles.section_footer }}>
168
+ <Button
169
+ title='CLOSE'
170
+ style={{ flex:1 }}
171
+ title_color={Colors.shades.white}
172
+ backgroundColor={Colors.utility.error}
173
+ onPress={() => onClose()}
174
+ />
175
+ </View>
176
+ :<></>}
177
+ </View>
178
+ )
179
+ }
180
+
181
+ export default CampaignLeaderboard
@@ -35,7 +35,7 @@ const CampaignPlay = ({ player_id, poll_campaign_id, onActiveViewChange, onReque
35
35
  //const [ shareImage, setImage ] = useState<any>(undefined)
36
36
  const [ share_in_process ] = useState(false);
37
37
  const [ play_width, setPlayWidth ] = useState(0);
38
- const [ show_live, setShowLive ] = useState(false);
38
+ //const [ show_live, setShowLive ] = useState(false);
39
39
  const [ active_poll, setActivePoll ] = useState<PollProps|undefined>(undefined);
40
40
  const [ active_view, setActiveView ] = useState('select_poll')
41
41
 
@@ -45,7 +45,7 @@ const CampaignPlay = ({ player_id, poll_campaign_id, onActiveViewChange, onReque
45
45
  if(a.priority && b.priority){ return a.priority - b.priority }
46
46
  else { return parseInt(b.poll_id) - parseInt(a.poll_id) }
47
47
  })
48
- const playable_polls = polls.filter(p => ['closed','active'].includes(p.status))
48
+ const playable_polls = polls.filter(p => ['closed','active','paused'].includes(p.status))
49
49
  const active_polls = polls.filter(p => p.status == 'active');
50
50
  const pending_polls = polls.filter(p => ['pending','paused'].includes(p.status));
51
51
  const closed_polls = polls.filter(p => p.status == 'closed');
@@ -57,6 +57,7 @@ const CampaignPlay = ({ player_id, poll_campaign_id, onActiveViewChange, onReque
57
57
  const active_responded = poll_responses.find(pr => pr.poll_id == active_poll?.poll_id) ? true : false;
58
58
  let active_index = playable_polls.findIndex(p => p.poll_id == active_poll?.poll_id)
59
59
 
60
+ console.log(playable_polls)
60
61
 
61
62
  //const progressRef = useRef()
62
63
 
@@ -105,66 +106,6 @@ const CampaignPlay = ({ player_id, poll_campaign_id, onActiveViewChange, onReque
105
106
  setLoading(false);
106
107
  }
107
108
 
108
- /*
109
- const getImage = async() => {
110
- if(!progressRef?.current){ return alert('Nothing to capture') }
111
- setShareInProcess(true)
112
- }
113
- */
114
-
115
-
116
- /*
117
- const share = async(newImage:string) => {
118
- if(!player){ return }
119
- if(!company){ return alert('no company')}
120
- let text = '';
121
- let url = `https://share.mybe.app/polls/${company.short_name}?poll_campaign_id=${poll_campaign.poll_campaign_id}`
122
- setShareInProcess(false)
123
- if(!newImage){ return alert('No image!') }
124
- if(!navigator?.share){ return alert('Browser does not support sharing')}
125
- const blob = await (await fetch(newImage)).blob();
126
- const filesArray = [
127
- new File([blob], `${player.player_id}_poll.png`, { type:blob.type } )
128
- ]
129
- navigator.share({ text, files:filesArray, url }).then(() => {
130
- //segEventTrack({ event: 'Shared Position', properties: { be_type:route.params.be_type, result:shareablePosition.result_ind } })
131
- }).catch((e) => console.log(e))
132
- }
133
- */
134
-
135
- /*
136
-
137
- const nativeShare = () => {
138
- if(!navigator?.share){ return alert('Your browser does not support native sharing') }
139
- if(!company){ return alert('no company')}
140
- let text = ``
141
- let total = playable_polls.length
142
- let total_resolved = playable_polls.filter(pp => pp.winning_option_id || pp.winning_value).length
143
- let wins = 0
144
- playable_polls.sort((a,b) => a.priority - b.priority).map(pp => {
145
- let resp = poll_responses.find(pr => pr.poll_id == pp.poll_id)
146
- if(!resp && (!pp.winning_option_id || !pp.winning_value)){ return }
147
- if(!resp){ text += `🕚`; return }
148
- if(!resp.result_ind){ text += '🕚'; return }
149
- if(resp.result_ind == 'win'){ wins += 1; text += '✅'; return }
150
- if(resp.result_ind == 'lose'){ text += '❌'; return }
151
- text += '🕚'
152
- return
153
- })
154
- let message = `I just went ${wins} out of ${total} in ${poll_campaign.name}! \n${text}`
155
- if(total_resolved < total){ message = `I just completed the ${poll_campaign.name}!` }
156
- let link = window.location.href
157
- //let link = `https://share.mybe.app/polls/${company.short_name}?poll_campaign_id=${poll_campaign.poll_campaign_id}`
158
- navigator.share({
159
- text:`${message}`,
160
- url: link
161
- }).then(() => {
162
- //segEventTrack({ event: 'Shared Position', properties: { be_type:route.params.be_type, result:shareablePosition.result_ind } })
163
- }).catch((e) => console.log(e))
164
-
165
- }
166
- */
167
-
168
109
  const handleNavPoll = (poll:PollProps) => {
169
110
  if(active_poll?.seconds_allowed){
170
111
  let responded = poll_responses.find(pr => pr.poll_id == active_poll.poll_id)
@@ -187,9 +128,9 @@ const CampaignPlay = ({ player_id, poll_campaign_id, onActiveViewChange, onReque
187
128
  const selected = active_poll?.poll_id == data.item.poll_id ? true : false;
188
129
  const poll_response = poll_responses.find(pr => pr.poll_id == data.item.poll_id);
189
130
  const response_option = data.item.poll_options?.find(po => po.poll_option_id == poll_response?.poll_option_id)
131
+ console.log(data.item)
190
132
  return (
191
133
  <PollSelectCard
192
- index={data.index}
193
134
  poll_campaign={poll_campaign}
194
135
  disabled={data.item.status == 'pending' ? true : false}
195
136
  poll={data.item}
@@ -234,22 +175,10 @@ const CampaignPlay = ({ player_id, poll_campaign_id, onActiveViewChange, onReque
234
175
  <TouchableOpacity style={{ padding:10 }} onPress={() => console.log('NATIVE SHARE')}>
235
176
  <Icons.ShareIcon color={Colors.brand.midnight} size={12}/>
236
177
  </TouchableOpacity>
237
- {poll_campaign.stream ?
238
- <TouchableOpacity style={{ padding:10 }} onPress={() => setShowLive(!show_live)}>
239
- {show_live ?
240
- <Icons.CloseIcon color={Colors.utility.error} size={14}/>
241
- :
242
- <Icons.TVIcon color={Colors.brand.midnight} size={14} />
243
- }
244
- </TouchableOpacity>
245
- :<></>}
178
+
246
179
  </View>
247
180
  </View>
248
- {poll_campaign.stream ?
249
- <View nativeID='campaign_stream' style={{ marginTop: show_live ? 5: 0, height:show_live ? undefined : 0, overflow:'hidden', justifyContent:'center', alignItems:'center' }}>
250
- <Text>STREAM!</Text>
251
- </View>
252
- :<></>}
181
+
253
182
  </View>
254
183
  <View style={{ flex:1 }}>
255
184
  <View nativeID='progress' style={{ padding:10, backgroundColor:Colors.shades.shade600 }}>
@@ -277,7 +206,7 @@ const CampaignPlay = ({ player_id, poll_campaign_id, onActiveViewChange, onReque
277
206
  </View>
278
207
  <View nativeID='active_questions_list' style={{ marginTop: 10, backgroundColor:Colors.shades.shade100, borderRadius:22 }}>
279
208
  <FlatList
280
- data={active_polls}
209
+ data={playable_polls.sort((a,b) => a.priority - b.priority)}
281
210
  renderItem={renderPolls}
282
211
  />
283
212
  </View>
@@ -391,11 +320,11 @@ const CampaignPlay = ({ player_id, poll_campaign_id, onActiveViewChange, onReque
391
320
  <View nativeID='campaign_results' style={{ flex:1 }}>
392
321
  <CampaignResult
393
322
  poll_campaign={poll_campaign}
394
- polls={polls}
323
+ //polls={polls}
395
324
  //hide_back={init_view && init_view !='undefined' ? true : false}
396
- onShare={() => console.log('Share this bad boi!')}
397
- poll_responses={poll_responses}
398
- onClose={() => setActiveView('select_poll')}
325
+ //onShare={() => console.log('Share this bad boi!')}
326
+ //poll_responses={poll_responses}
327
+ //onClose={() => setActiveView('select_poll')}
399
328
  />
400
329
  </View>
401
330
  :<></>}
@@ -27,7 +27,6 @@ const CampaignProgressBar = ({ poll_responses, active_poll, polls, onPollSelect}
27
27
  let color = Colors.shades.white
28
28
  let response = poll_responses.find(pr => pr.poll_id == data.item.poll_id)
29
29
  if(response){ color = getBarColor(response) }
30
- console.log('rendering!!!')
31
30
  const active = active_poll == data.item.poll_id ? true : false
32
31
  return (
33
32
  <TouchableOpacity
@@ -1,174 +1,35 @@
1
- import { FlatList, Image, ScrollView, TouchableOpacity, View } from "react-native"
2
- import React, { useEffect, useState } from "react"
3
- import { PollCampaignApi } from "../api"
4
- import type { PollCampaignLeaderProps, PollCampaignProps, PollProps, PollResponseProps, PublicPlayerProps } from "../../types"
5
- import { Button, Icons, Text } from "../../Components"
1
+ import { TouchableOpacity, View } from "react-native"
2
+ import React, { useState } from "react"
3
+ import type { PollCampaignProps } from "../../types"
4
+ import { Icons, Text } from "../../Components"
6
5
  import Colors from '../../constants/colors';
6
+ import { view_styles } from "../../constants/styles"
7
+ import CampaignLeaderboard from "./CampaignLeaderboard"
7
8
 
8
9
  type CampaignResultProps = {
9
10
  poll_campaign:PollCampaignProps,
10
- polls:PollProps[],
11
- onShare?:() => void,
12
- hide_back?:boolean,
13
- poll_responses:PollResponseProps[],
14
- onClose: () => void
11
+ onShowFullLeaderboard?:() => void
15
12
  }
16
- const CampaignResult = ({ poll_campaign, polls, poll_responses, hide_back, onClose, onShare } : CampaignResultProps) => {
17
- const [ leaders_state, setLeadersState ] = useState<{
18
- loading:boolean,
19
- offset:number,
20
- players:PublicPlayerProps[]
21
- poll_campaign_leaders:PollCampaignLeaderProps[]
22
- }>({
23
- loading:false,
24
- offset:0,
25
- poll_campaign_leaders:[],
26
- players: []
27
- });
28
- const [ points_expanded, setPointsExpanded ] = useState(false);
29
13
 
30
- const { players, poll_campaign_leaders } = leaders_state;
31
-
32
- useEffect(() => {
33
- getDataFromServer(poll_campaign.poll_campaign_id, 0)
34
- },[poll_campaign.poll_campaign_id])
35
-
36
- const getDataFromServer = async(poll_campaign_id:string, offset:number) => {
37
- setLeadersState({ ...leaders_state, loading:true })
38
- const leaders = await PollCampaignApi.getLeadersByCampaignId(poll_campaign_id, offset)
39
- const player_ids = leaders.poll_campaign_leaders.map(l => l.player_id);
40
- const ps = await PollCampaignApi.getPlayersByPlayerIds(player_ids);
41
- setLeadersState({
42
- loading:false,
43
- poll_campaign_leaders: leaders.poll_campaign_leaders,
44
- players: ps,
45
- offset
46
- })
47
- }
48
-
49
- const renderTrophy = (place:number) => {
50
- switch(place){
51
- case 1: return <Icons.TrophyIcon color={Colors.incentive.gold} size={16}/>
52
- case 2: return <Icons.TrophyIcon color={Colors.incentive.silver} size={16}/>
53
- case 3: return <Icons.TrophyIcon color={Colors.incentive.bronze} size={16}/>
54
- default: return <></>
55
- }
56
- }
57
-
58
- const renderLeaders = (data: {item:PollCampaignLeaderProps, index:number}) => {
59
- const player = players.find(p => p.player_id == data.item.player_id);
60
- if(!player){ return <></> }
61
- return (
62
- <View style={{ flexDirection:'row', alignItems:'center', margin:4, padding:10, borderRadius:22, backgroundColor:Colors.shades.white }}>
63
- <View nativeID="place" style={{ margin:5, height:20, width:20, justifyContent:'center', alignItems:'center', borderRadius:100, borderWidth:1, borderColor:Colors.brand.slate }}>
64
- <Text size={10} color={Colors.brand.midnight} weight='bold' textAlign="center">{data.index+1}</Text>
65
- </View>
66
- <View nativeID="player" style={{ flex:1, flexDirection:'row', alignItems:'center' }}>
67
- <View nativeID="profile_pic" style={{ marginRight:10 }}>
68
- <Image
69
- source={{ uri: player.profile_pic && player.profile_pic != '' ? player.profile_pic : 'https://res.cloudinary.com/hoabts6mc/image/upload/v1689262384/default-avatar_bbkn2t.png' }}
70
- style={{ height:40, width:40, borderRadius:100 }}
71
- resizeMode='cover'
72
- />
73
- </View>
74
- <View style={{ flex:1 }} nativeID="name">
75
- <Text size={14} color={Colors.brand.midnight} weight='bold'>{player.username}</Text>
76
- <Text style={{ marginTop:3 }} size={12} color={Colors.brand.midnight} weight='regular'>{data.item.winnings.toFixed(2)} Points</Text>
77
- </View>
78
- <View>
79
- {renderTrophy(data.index + 1)}
80
- </View>
81
- </View>
82
- </View>
83
- )
84
- }
85
-
86
-
87
- //const questions_answered = poll_responses.length
88
- let correct_answers = poll_responses.filter(pr => pr.result_ind == 'win').length
89
- //let incorrect_answers = poll_responses.filter(pr => pr.result_ind == 'lose').length
90
- let ungraded_answers = poll_responses.filter(pr => !pr.result_ind).length
91
- let points_earned = poll_responses.reduce((a,b) => a + b.winnings, 0)
14
+ const CampaignResult = ({ poll_campaign, onShowFullLeaderboard } : CampaignResultProps) => {
15
+ const [ expanded, setExpanded ] = useState(true);
92
16
 
93
17
  return (
94
- <View style={{ flex:1 }}>
95
- <ScrollView style={{ flex:1, padding:10, marginBottom:10 }}>
96
- <TouchableOpacity
97
- style={{ flexDirection:'row', padding:10, paddingRight:15, paddingLeft:15, borderRadius:22, justifyContent:'center', alignItems:'center', marginBottom:10, backgroundColor:Colors.incentive.gold }}
98
- onPress={() => {
99
- if(onShare){ onShare() }
100
- }}
101
- >
102
- <Icons.ShareSocialIcon color={Colors.shades.white} size={14}/>
103
- <Text style={{ marginLeft:5 }} size={14} color={Colors.shades.white} weight='bold'>Share your results for a chance at a prize!</Text>
104
- </TouchableOpacity>
105
- <View nativeID="my_results">
106
- <Text style={{ margin:10 }} size={16} color={Colors.brand.midnight} weight='bold'>My Results</Text>
107
- <View style={{borderRadius:22, backgroundColor:Colors.shades.shade100, padding:20}}>
108
- <View nativeID="completion" style={{ flexDirection: 'row' }}>
109
- <View nativeID="total_questions" style={{ flex:1 }}>
110
- <Text size={12} color={Colors.brand.slate} weight='semibold'>TOTAL QUESTIONS</Text>
111
- <Text style={{ marginTop:5 }} size={16} color={Colors.brand.midnight} weight='bold'>{polls.length} Questions</Text>
112
- </View>
113
- <View nativeID="completion_pct" style={{ flex:1 }}>
114
- <Text size={12} color={Colors.brand.slate} weight='semibold'>COMPLETION</Text>
115
- <Text style={{ marginTop:5 }} size={16} color={Colors.brand.midnight} weight='bold'>{(((polls.length - ungraded_answers) / polls.length) * 100).toFixed()}%</Text>
116
- </View>
117
- </View>
118
- <View nativeID="performance" style={{ flexDirection: 'row', marginTop:10 }}>
119
- <View nativeID="total_questions" style={{ flex:1 }}>
120
- <Text size={12} color={Colors.brand.slate} weight='semibold'>SUCCESS RATE</Text>
121
- <Text style={{ marginTop:5 }} size={16} color={Colors.brand.midnight} weight='bold'>{((correct_answers / polls.length)*100).toFixed()}%</Text>
122
- </View>
123
- <View nativeID="completion_pct" style={{ flex:1 }}>
124
- <Text size={12} color={Colors.brand.slate} weight='semibold'>POINTS EARNED</Text>
125
- <Text style={{ marginTop:5 }} size={16} color={Colors.brand.midnight} weight='bold'>{points_earned.toFixed()} Points</Text>
126
- </View>
127
- </View>
128
- <View style={{ borderRadius:22, backgroundColor:Colors.highlights.highlight200Faded, padding:10, marginTop:10 }}>
129
- <TouchableOpacity style={{ flexDirection:'row', alignItems:'center' }} onPress={() => setPointsExpanded(!points_expanded)}>
130
- <View style={{ flexDirection:'row', alignItems:'center', flex:1 }}>
131
- <Icons.AlertIcon color={Colors.brand.midnight} size={14}/>
132
- <Text style={{ marginLeft:5 }} size={14} color={Colors.brand.midnight} weight='semibold'>How are points calculated?</Text>
133
- </View>
134
- <Icons.ChevronIcon direction={points_expanded ? 'up' : 'down'} color={Colors.brand.midnight}/>
135
- </TouchableOpacity>
136
- {points_expanded ?
137
- <>
138
- <Text size={12} color={Colors.brand.midnight} style={{ marginTop:10 }} weight='regular'>Points are calculated based on the total responses by all participants. Each response is worth 1 point. The responders that selected the winning option will split the total point pool.</Text>
139
- <Text size={12} color={Colors.brand.midnight} style={{ marginTop:5 }} weight='regular'>Therefore, points earned will not be updated until the question is closed!</Text>
140
- </>
141
- :<></>}
142
- </View>
143
- </View>
144
- </View>
145
- <View nativeID="leader_header" style={{ margin:10, flexDirection:'row', alignItems:'center' }}>
146
- <Text style={{ flex:1 }} size={16} color={Colors.brand.midnight} weight='bold'>Leaderboard</Text>
147
- <View style={{ borderRadius:22, padding:10, backgroundColor:Colors.accents.accent100 }}>
148
- <Text size={14} color={Colors.brand.midnight} weight='regular' textAlign="center">{poll_campaign.total_responders} Participants</Text>
149
- </View>
150
- </View>
151
- <View nativeID="leaderboard" style={{ flex:1, borderTopRightRadius:22, borderTopLeftRadius:22, padding:10, backgroundColor:Colors.shades.shade100}}>
152
- {poll_campaign.status == 'active' ?
153
- <Text size={12} color={Colors.utility.warning} textAlign="center">Points change as new responses come in</Text>
154
- :<></>}
155
- <FlatList
156
- data={poll_campaign_leaders}
157
- renderItem={renderLeaders}
158
- keyExtractor={((item) => item.player_id.toString())}
159
- />
18
+ <View style={{ flex:1, ...view_styles.section }}>
19
+ <TouchableOpacity style={{ ...view_styles.section_header }} onPress={() => setExpanded(!expanded)}>
20
+ <Icons.PodiumIcon size={18} color={Colors.brand.midnight} />
21
+ <View style={{flex:1, marginLeft:10}}>
22
+ <Text theme="header">Leaderboard</Text>
23
+ <Text style={{ marginTop:3 }} theme="body">Below are the leaderboard results!</Text>
160
24
  </View>
161
- </ScrollView>
162
- {!hide_back ?
163
- <View nativeID="result_actions" style={{ marginTop:5, padding:10 }}>
164
- <Button
165
- title='Go Back'
166
- title_color={Colors.brand.electric}
167
- borderWidth={1}
168
- padding={14}
169
- borderColor={Colors.brand.electric}
170
- onPress={() => onClose()}
171
- borderRadius={22}
25
+ <Icons.ChevronIcon size={8} color={Colors.brand.midnight} direction={expanded ? 'up' : 'down'} />
26
+ </TouchableOpacity>
27
+ {expanded ?
28
+ <View style={{ ...view_styles.section_body, padding:0, backgroundColor:Colors.shades.shade100 }}>
29
+ <CampaignLeaderboard
30
+ view_mode="short"
31
+ poll_campaign={poll_campaign}
32
+ onShowFullLeaderboard={onShowFullLeaderboard}
172
33
  />
173
34
  </View>
174
35
  :<></>}
@@ -176,4 +37,23 @@ const CampaignResult = ({ poll_campaign, polls, poll_responses, hide_back, onClo
176
37
  )
177
38
  }
178
39
 
40
+
41
+ /*
42
+ <View style={{ borderRadius:22, backgroundColor:Colors.highlights.highlight200Faded, padding:10, marginTop:10 }}>
43
+ <TouchableOpacity style={{ flexDirection:'row', alignItems:'center' }} onPress={() => setPointsExpanded(!points_expanded)}>
44
+ <View style={{ flexDirection:'row', alignItems:'center', flex:1 }}>
45
+ <Icons.AlertIcon color={Colors.brand.midnight} size={14}/>
46
+ <Text style={{ marginLeft:5 }} size={14} color={Colors.brand.midnight} weight='semibold'>How are points calculated?</Text>
47
+ </View>
48
+ <Icons.ChevronIcon direction={points_expanded ? 'up' : 'down'} color={Colors.brand.midnight}/>
49
+ </TouchableOpacity>
50
+ {points_expanded ?
51
+ <View>
52
+ <Text size={12} color={Colors.brand.midnight} style={{ marginTop:10 }} weight='regular'>Points are calculated based on the total responses by all participants. Each response is worth 1 point. The responders that selected the winning option will split the total point pool.</Text>
53
+ <Text size={12} color={Colors.brand.midnight} style={{ marginTop:5 }} weight='regular'>Therefore, points earned will not be updated until the question is closed!</Text>
54
+ </View>
55
+ :<></>}
56
+ </View>
57
+ */
58
+
179
59
  export default CampaignResult