be-components 1.3.0 → 1.3.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/Competition/api/index.js +1 -1
- package/lib/commonjs/Competition/api/index.js.map +1 -1
- package/lib/commonjs/Competition/components/CompetitionPlay.js +1 -1
- package/lib/commonjs/Competition/components/CompetitionPlay.js.map +1 -1
- package/lib/commonjs/Competition/components/MarketsCard.js.map +1 -1
- package/lib/commonjs/Competition/index.js +37 -2
- package/lib/commonjs/Competition/index.js.map +1 -1
- package/lib/commonjs/CompetitionManager/api/index.js +153 -35
- package/lib/commonjs/CompetitionManager/api/index.js.map +1 -1
- package/lib/commonjs/CompetitionManager/components/AthleteSelector.js +170 -0
- package/lib/commonjs/CompetitionManager/components/AthleteSelector.js.map +1 -0
- package/lib/commonjs/CompetitionManager/components/CompetitionContestsForm.js +495 -423
- package/lib/commonjs/CompetitionManager/components/CompetitionContestsForm.js.map +1 -1
- package/lib/commonjs/CompetitionManager/components/CompetitionHeader.js +134 -0
- package/lib/commonjs/CompetitionManager/components/CompetitionHeader.js.map +1 -0
- package/lib/commonjs/CompetitionManager/components/CompetitionInfoForm.js +96 -73
- package/lib/commonjs/CompetitionManager/components/CompetitionInfoForm.js.map +1 -1
- package/lib/commonjs/CompetitionManager/components/CompetitionMatchMarketCard.js +147 -127
- package/lib/commonjs/CompetitionManager/components/CompetitionMatchMarketCard.js.map +1 -1
- package/lib/commonjs/CompetitionManager/components/CompetitionSettingsForm.js +38 -127
- package/lib/commonjs/CompetitionManager/components/CompetitionSettingsForm.js.map +1 -1
- package/lib/commonjs/CompetitionManager/components/ContestSelector.js +388 -0
- package/lib/commonjs/CompetitionManager/components/ContestSelector.js.map +1 -0
- package/lib/commonjs/CompetitionManager/components/ContestSettingsForm.js +436 -0
- package/lib/commonjs/CompetitionManager/components/ContestSettingsForm.js.map +1 -0
- package/lib/commonjs/CompetitionManager/components/MarketSelector.js +36 -26
- package/lib/commonjs/CompetitionManager/components/MarketSelector.js.map +1 -1
- package/lib/commonjs/CompetitionManager/index.js +492 -19
- package/lib/commonjs/CompetitionManager/index.js.map +1 -1
- package/lib/commonjs/Components/SearchBox.js +82 -0
- package/lib/commonjs/Components/SearchBox.js.map +1 -0
- package/lib/module/Competition/api/index.js +1 -1
- package/lib/module/Competition/api/index.js.map +1 -1
- package/lib/module/Competition/components/CompetitionPlay.js +1 -1
- package/lib/module/Competition/components/CompetitionPlay.js.map +1 -1
- package/lib/module/Competition/components/MarketsCard.js.map +1 -1
- package/lib/module/Competition/index.js +37 -2
- package/lib/module/Competition/index.js.map +1 -1
- package/lib/module/CompetitionManager/api/index.js +153 -35
- package/lib/module/CompetitionManager/api/index.js.map +1 -1
- package/lib/module/CompetitionManager/components/AthleteSelector.js +161 -0
- package/lib/module/CompetitionManager/components/AthleteSelector.js.map +1 -0
- package/lib/module/CompetitionManager/components/CompetitionContestsForm.js +493 -425
- package/lib/module/CompetitionManager/components/CompetitionContestsForm.js.map +1 -1
- package/lib/module/CompetitionManager/components/CompetitionHeader.js +127 -0
- package/lib/module/CompetitionManager/components/CompetitionHeader.js.map +1 -0
- package/lib/module/CompetitionManager/components/CompetitionInfoForm.js +99 -76
- package/lib/module/CompetitionManager/components/CompetitionInfoForm.js.map +1 -1
- package/lib/module/CompetitionManager/components/CompetitionMatchMarketCard.js +145 -127
- package/lib/module/CompetitionManager/components/CompetitionMatchMarketCard.js.map +1 -1
- package/lib/module/CompetitionManager/components/CompetitionSettingsForm.js +39 -131
- package/lib/module/CompetitionManager/components/CompetitionSettingsForm.js.map +1 -1
- package/lib/module/CompetitionManager/components/ContestSelector.js +379 -0
- package/lib/module/CompetitionManager/components/ContestSelector.js.map +1 -0
- package/lib/module/CompetitionManager/components/ContestSettingsForm.js +428 -0
- package/lib/module/CompetitionManager/components/ContestSettingsForm.js.map +1 -0
- package/lib/module/CompetitionManager/components/MarketSelector.js +34 -26
- package/lib/module/CompetitionManager/components/MarketSelector.js.map +1 -1
- package/lib/module/CompetitionManager/index.js +493 -20
- package/lib/module/CompetitionManager/index.js.map +1 -1
- package/lib/module/Components/SearchBox.js +73 -0
- package/lib/module/Components/SearchBox.js.map +1 -0
- package/lib/typescript/src/Competition/index.d.ts +2 -1
- package/lib/typescript/src/Competition/index.d.ts.map +1 -1
- package/lib/typescript/src/CompetitionManager/api/index.d.ts +32 -3
- package/lib/typescript/src/CompetitionManager/api/index.d.ts.map +1 -1
- package/lib/typescript/src/CompetitionManager/components/AthleteSelector.d.ts +18 -0
- package/lib/typescript/src/CompetitionManager/components/AthleteSelector.d.ts.map +1 -0
- package/lib/typescript/src/CompetitionManager/components/CompetitionContestsForm.d.ts +13 -1
- package/lib/typescript/src/CompetitionManager/components/CompetitionContestsForm.d.ts.map +1 -1
- package/lib/typescript/src/CompetitionManager/components/CompetitionHeader.d.ts +20 -0
- package/lib/typescript/src/CompetitionManager/components/CompetitionHeader.d.ts.map +1 -0
- package/lib/typescript/src/CompetitionManager/components/CompetitionInfoForm.d.ts +2 -1
- package/lib/typescript/src/CompetitionManager/components/CompetitionInfoForm.d.ts.map +1 -1
- package/lib/typescript/src/CompetitionManager/components/CompetitionMatchMarketCard.d.ts +1 -1
- package/lib/typescript/src/CompetitionManager/components/CompetitionMatchMarketCard.d.ts.map +1 -1
- package/lib/typescript/src/CompetitionManager/components/CompetitionSettingsForm.d.ts +3 -3
- package/lib/typescript/src/CompetitionManager/components/CompetitionSettingsForm.d.ts.map +1 -1
- package/lib/typescript/src/CompetitionManager/components/ContestSelector.d.ts +16 -0
- package/lib/typescript/src/CompetitionManager/components/ContestSelector.d.ts.map +1 -0
- package/lib/typescript/src/CompetitionManager/components/ContestSettingsForm.d.ts +15 -0
- package/lib/typescript/src/CompetitionManager/components/ContestSettingsForm.d.ts.map +1 -0
- package/lib/typescript/src/CompetitionManager/components/MarketSelector.d.ts +3 -2
- package/lib/typescript/src/CompetitionManager/components/MarketSelector.d.ts.map +1 -1
- package/lib/typescript/src/CompetitionManager/index.d.ts +2 -1
- package/lib/typescript/src/CompetitionManager/index.d.ts.map +1 -1
- package/lib/typescript/src/Components/SearchBox.d.ts +10 -0
- package/lib/typescript/src/Components/SearchBox.d.ts.map +1 -0
- package/package.json +2 -1
- package/src/Competition/api/index.ts +3 -3
- package/src/Competition/components/CompetitionPlay.tsx +1 -1
- package/src/Competition/components/MarketsCard.tsx +2 -2
- package/src/Competition/index.tsx +24 -4
- package/src/CompetitionManager/api/index.ts +71 -13
- package/src/CompetitionManager/components/AthleteSelector.tsx +127 -0
- package/src/CompetitionManager/components/CompetitionContestsForm.tsx +156 -261
- package/src/CompetitionManager/components/CompetitionHeader.tsx +101 -0
- package/src/CompetitionManager/components/CompetitionInfoForm.tsx +57 -45
- package/src/CompetitionManager/components/CompetitionMatchMarketCard.tsx +29 -70
- package/src/CompetitionManager/components/CompetitionSettingsForm.tsx +36 -103
- package/src/CompetitionManager/components/ContestSelector.tsx +269 -0
- package/src/CompetitionManager/components/ContestSettingsForm.tsx +281 -0
- package/src/CompetitionManager/components/MarketSelector.tsx +34 -23
- package/src/CompetitionManager/index.tsx +412 -16
- package/src/Components/SearchBox.tsx +54 -0
- package/src/types.d.ts +38 -4
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { FlatList, TextInput, TouchableOpacity, View } from "react-native"
|
|
2
2
|
import React, { useEffect, useState } from "react";
|
|
3
|
-
import type { CompetitionProps, CompetitionResultTypeProps,
|
|
3
|
+
import type { CompetitionProps, CompetitionResultTypeProps, PublicPlayerProps } from "../../types";
|
|
4
4
|
import { ManageCompetitionApi } from "../api";
|
|
5
5
|
import Colors from "../../constants/colors";
|
|
6
|
-
import { Icons, Text } from "../../Components";
|
|
6
|
+
import { Button, Icons, Text } from "../../Components";
|
|
7
7
|
import { view_styles } from "../../constants/styles";
|
|
8
8
|
import DropDown from "../../Components/Dropdown";
|
|
9
9
|
|
|
@@ -11,22 +11,24 @@ type CompetitionSettingsFormProps = {
|
|
|
11
11
|
player?: PublicPlayerProps,
|
|
12
12
|
competition: CompetitionProps,
|
|
13
13
|
width:number,
|
|
14
|
+
is_valid?:boolean,
|
|
14
15
|
competition_result_types:CompetitionResultTypeProps[],
|
|
15
|
-
competition_types:CompetitionTypeProps[],
|
|
16
16
|
onCompetitionUpdate:(c:CompetitionProps) => void
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
const market_types = ['FOR_MONEY', 'FREE']
|
|
20
20
|
|
|
21
|
-
const CompetitionSettingsForm = ({ player, width, competition,
|
|
21
|
+
const CompetitionSettingsForm = ({ is_valid, player, width, competition, competition_result_types, onCompetitionUpdate }: CompetitionSettingsFormProps) => {
|
|
22
22
|
const [ expanded, setExpanded ] = useState(false);
|
|
23
|
+
const [ draft_competition, setDraftCompetition ] = useState<CompetitionProps | undefined>(undefined);
|
|
23
24
|
//const [ player_selector_visible, setPlayerSelectorVisible ] = useState(false);
|
|
24
25
|
const [ pacer, setPacer ] = useState<PublicPlayerProps>();
|
|
25
26
|
|
|
26
|
-
const competition_type = competition_types.find(ct => ct.competition_type_id == competition?.competition_type_id);
|
|
27
27
|
const competition_result_type = competition_result_types.find(crt => crt.competition_result_type_id == competition?.competition_result_type_id);
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
setDraftCompetition(competition);
|
|
31
|
+
},[competition])
|
|
30
32
|
|
|
31
33
|
useEffect(() => {
|
|
32
34
|
if(!competition?.pacer_id){ return }
|
|
@@ -48,32 +50,42 @@ const CompetitionSettingsForm = ({ player, width, competition, competition_types
|
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
const renderMarketTypes = (data:{ item:string, index:number }) => {
|
|
53
|
+
if(!draft_competition){ return <></> }
|
|
51
54
|
const selected = data.item == competition.market_type ? true : false
|
|
52
55
|
return (
|
|
53
|
-
<TouchableOpacity style={{ minWidth:75, margin:1, borderRadius:8, padding:10, backgroundColor:selected?Colors.brand.midnight:undefined }} onPress={() => onCompetitionUpdate({ ...
|
|
56
|
+
<TouchableOpacity style={{ minWidth:75, margin:1, borderRadius:8, padding:10, backgroundColor:selected?Colors.brand.midnight:undefined }} onPress={() => onCompetitionUpdate({ ...draft_competition, market_type: data.item })}>
|
|
54
57
|
<Text textAlign="center" color={selected?Colors.shades.white:Colors.brand.midnight} weight={selected?'bold':'regular'} size={14}>{data.item == 'FOR_MONEY'?'USD':'EDGE COINS'}</Text>
|
|
55
58
|
</TouchableOpacity>
|
|
56
59
|
)
|
|
57
60
|
}
|
|
58
61
|
|
|
59
|
-
const renderCompetitionTypes = (data:{ item:CompetitionTypeProps, index:number }) => {
|
|
60
|
-
const selected = data.item.competition_type_id == competition.competition_type_id ? true : false
|
|
61
|
-
return (
|
|
62
|
-
<TouchableOpacity style={{ minWidth:75, margin:1, borderRadius:8, padding:10, backgroundColor:selected?Colors.brand.midnight:undefined }} onPress={() => onCompetitionUpdate({ ...competition, competition_type_id: data.item.competition_type_id })}>
|
|
63
|
-
<Text textAlign="center" color={selected?Colors.shades.white:Colors.brand.midnight} weight={selected?'bold':'regular'} size={14}>{data.item.type_label}</Text>
|
|
64
|
-
</TouchableOpacity>
|
|
65
|
-
)
|
|
66
|
-
}
|
|
67
62
|
|
|
68
|
-
if(!competition){ return <></> }
|
|
63
|
+
if(!competition || !draft_competition){ return <></> }
|
|
64
|
+
const is_changed = JSON.stringify(competition) != JSON.stringify(draft_competition) ? true : false
|
|
65
|
+
|
|
69
66
|
return (
|
|
70
67
|
<View style={{ ...view_styles.section, flexGrow:1 }}>
|
|
71
|
-
<TouchableOpacity style={view_styles.section_header} onPress={() => setExpanded(!expanded)}>
|
|
72
|
-
|
|
68
|
+
<TouchableOpacity style={{ ...view_styles.section_header, maxWidth: width }} onPress={() => setExpanded(!expanded)}>
|
|
69
|
+
{is_valid ?
|
|
70
|
+
<Icons.CheckCirlceIcon size={16} color={Colors.utility.success} />
|
|
71
|
+
:
|
|
72
|
+
<Icons.AlertIcon size={16} color={Colors.utility.warning} />
|
|
73
|
+
}
|
|
74
|
+
<View style={{ flex:1, marginLeft:10 }}>
|
|
73
75
|
<Text theme='header'>Competition Settings</Text>
|
|
74
76
|
<Text style={{ marginTop:3 }} theme='body'>Manage the high level information of this competition</Text>
|
|
75
77
|
</View>
|
|
78
|
+
{is_changed ?
|
|
79
|
+
<Button
|
|
80
|
+
title='SAVE'
|
|
81
|
+
padding={10}
|
|
82
|
+
title_color={Colors.shades.white}
|
|
83
|
+
backgroundColor={Colors.utility.success}
|
|
84
|
+
onPress={() => onCompetitionUpdate(draft_competition)}
|
|
85
|
+
/>
|
|
86
|
+
:
|
|
76
87
|
<Icons.ChevronIcon direction={expanded ? 'up' : 'down'} color={Colors.brand.midnight} size={8} />
|
|
88
|
+
}
|
|
77
89
|
</TouchableOpacity>
|
|
78
90
|
{expanded ?
|
|
79
91
|
<View nativeID="competition_settings" style={{ ...view_styles.section_body, maxWidth:width, backgroundColor:Colors.shades.shade100 }}>
|
|
@@ -93,21 +105,6 @@ const CompetitionSettingsForm = ({ player, width, competition, competition_types
|
|
|
93
105
|
/>
|
|
94
106
|
</View>
|
|
95
107
|
</View>
|
|
96
|
-
|
|
97
|
-
<View nativeID="competition_type" style={{ ...view_styles.body_row, flexWrap:'wrap', maxWidth:width}}>
|
|
98
|
-
<View style={{ flex:1, margin:5, minWidth:200 }}>
|
|
99
|
-
<Text theme="header_2">Competition Type</Text>
|
|
100
|
-
<Text style={{ marginTop:3 }} theme="body">{competition_type?competition_type.description:'Choose the type of competition this is.'}</Text>
|
|
101
|
-
</View>
|
|
102
|
-
<View style={{ justifyContent:'flex-end', margin:5, borderRadius:8, backgroundColor:Colors.shades.white }}>
|
|
103
|
-
<FlatList
|
|
104
|
-
data={competition_types}
|
|
105
|
-
renderItem={renderCompetitionTypes}
|
|
106
|
-
keyExtractor={(item) => item.competition_type_id.toString()}
|
|
107
|
-
horizontal
|
|
108
|
-
/>
|
|
109
|
-
</View>
|
|
110
|
-
</View>
|
|
111
108
|
|
|
112
109
|
<View nativeID="competition_payout" style={{ ...view_styles.body_row, flexWrap:'wrap', maxWidth:width}}>
|
|
113
110
|
<View style={{ flex:1, margin:5, minWidth:200 }}>
|
|
@@ -123,12 +120,11 @@ const CompetitionSettingsForm = ({ player, width, competition, competition_types
|
|
|
123
120
|
onOptionSelect={(type) => {
|
|
124
121
|
const new_result_type = competition_result_types.find(crt => crt.label == type);
|
|
125
122
|
if(!new_result_type){ return }
|
|
126
|
-
onCompetitionUpdate({ ...
|
|
123
|
+
onCompetitionUpdate({ ...draft_competition, competition_result_type_id: new_result_type.competition_result_type_id })
|
|
127
124
|
}}
|
|
128
125
|
/>
|
|
129
126
|
</View>
|
|
130
127
|
</View>
|
|
131
|
-
|
|
132
128
|
|
|
133
129
|
<View nativeID="buy_in" style={{ ...view_styles.body_row, flexWrap:'wrap', maxWidth:width}}>
|
|
134
130
|
<View style={{ flex:1, margin:5, minWidth:200 }}>
|
|
@@ -137,9 +133,9 @@ const CompetitionSettingsForm = ({ player, width, competition, competition_types
|
|
|
137
133
|
</View>
|
|
138
134
|
<TextInput
|
|
139
135
|
style={{ ...view_styles.input, textAlign:'center', margin:5, width:100, backgroundColor:Colors.shades.white }}
|
|
140
|
-
onChangeText={(text) =>
|
|
136
|
+
onChangeText={(text) => setDraftCompetition({ ...draft_competition, buy_in: text })}
|
|
141
137
|
placeholder="25"
|
|
142
|
-
value={
|
|
138
|
+
value={draft_competition.buy_in as string}
|
|
143
139
|
placeholderTextColor={Colors.brand.slate}
|
|
144
140
|
/>
|
|
145
141
|
</View>
|
|
@@ -151,9 +147,9 @@ const CompetitionSettingsForm = ({ player, width, competition, competition_types
|
|
|
151
147
|
</View>
|
|
152
148
|
<TextInput
|
|
153
149
|
style={{ ...view_styles.input, textAlign:'center', width:100, backgroundColor:Colors.shades.white }}
|
|
154
|
-
onChangeText={(text) =>
|
|
150
|
+
onChangeText={(text) => setDraftCompetition({ ...draft_competition, available_tickets: text })}
|
|
155
151
|
placeholder="100"
|
|
156
|
-
value={
|
|
152
|
+
value={draft_competition.available_tickets as string}
|
|
157
153
|
placeholderTextColor={Colors.brand.slate}
|
|
158
154
|
/>
|
|
159
155
|
</View>
|
|
@@ -163,67 +159,4 @@ const CompetitionSettingsForm = ({ player, width, competition, competition_types
|
|
|
163
159
|
)
|
|
164
160
|
}
|
|
165
161
|
|
|
166
|
-
export default CompetitionSettingsForm
|
|
167
|
-
|
|
168
|
-
/*
|
|
169
|
-
{competition_result_type?.type == 'outpace' ?
|
|
170
|
-
<View nativeID="competition_payout_type" style={{ flexDirection:'row', flexWrap:'wrap', padding:10, borderBottomWidth:1, borderBottomColor:Colors.shades.white }}>
|
|
171
|
-
<View style={{ flex:1, marginRight:5 }}>
|
|
172
|
-
<Text size={16} color={Colors.brand.midnight} weight='bold'>Pacer</Text>
|
|
173
|
-
<Text size={14} color={Colors.brand.midnight} weight='regular'>Select the player that must be beat</Text>
|
|
174
|
-
</View>
|
|
175
|
-
<View style={{ flexDirection:'row', padding:5, backgroundColor:Colors.shades.white, borderRadius:8 }}>
|
|
176
|
-
{pacer?
|
|
177
|
-
<View style={{ flexDirection:'row', padding:5, backgroundColor:Colors.shades.white, borderRightWidth:1, borderRightColor:Colors.shades.shade600 }}>
|
|
178
|
-
<Image
|
|
179
|
-
source={{ uri: pacer.profile_pic }}
|
|
180
|
-
style={{ height:40, width:40, padding:5 }}
|
|
181
|
-
resizeMode="cover"
|
|
182
|
-
/>
|
|
183
|
-
<View style={{ flex:1, padding:5 }}>
|
|
184
|
-
<Text size={14} color={Colors.brand.midnight}>@{pacer.username}</Text>
|
|
185
|
-
</View>
|
|
186
|
-
</View>
|
|
187
|
-
:<></>}
|
|
188
|
-
<Button
|
|
189
|
-
title={pacer?'Change':'Add Pacer'}
|
|
190
|
-
title_color={Colors.brand.electric}
|
|
191
|
-
onPress={() => setPlayerSelectorVisible(true)}
|
|
192
|
-
/>
|
|
193
|
-
</View>
|
|
194
|
-
</View>
|
|
195
|
-
:<></>}
|
|
196
|
-
*/
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
/*
|
|
200
|
-
<View style={{ position:'absolute', top:0, left:0, right:0, alignItems:'center' }}>
|
|
201
|
-
<PlayerSelector
|
|
202
|
-
visible={player_selector_visible}
|
|
203
|
-
onPlayerSelect={(player) => {
|
|
204
|
-
setPacer(player)
|
|
205
|
-
onCompetitionUpdate({ ...competition, pacer_id:player.player_id })
|
|
206
|
-
setPlayerSelectorVisible(false)
|
|
207
|
-
}}
|
|
208
|
-
onClose={() => setPlayerSelectorVisible(false)}
|
|
209
|
-
/>
|
|
210
|
-
</View>
|
|
211
|
-
*/
|
|
212
|
-
|
|
213
|
-
/*
|
|
214
|
-
{creator?.role == 'admin' ?
|
|
215
|
-
<View nativeID="Guaranteed_payout" style={{ flexDirection:'row', flexWrap:'wrap', padding:10, borderBottomWidth:1, borderBottomColor:Colors.shades.white }}>
|
|
216
|
-
<View style={{ flex:1, marginRight:5 }}>
|
|
217
|
-
<Text size={16} color={Colors.brand.midnight} weight='bold'>Guaranteed Payout (ADMIN ONLY)</Text>
|
|
218
|
-
<Text size={14} color={Colors.brand.midnight} weight='regular'>How much payout is guaranteed?</Text>
|
|
219
|
-
</View>
|
|
220
|
-
<TextInput
|
|
221
|
-
style={{ padding:10, borderRadius:8, backgroundColor:Colors.shades.white }}
|
|
222
|
-
onChangeText={(text) => onCompetitionUpdate({ ...competition, guaranteed_payout: text })}
|
|
223
|
-
placeholder="0"
|
|
224
|
-
value={competition.guaranteed_payout}
|
|
225
|
-
placeholderTextColor={Colors.brand.slate}
|
|
226
|
-
/>
|
|
227
|
-
</View>
|
|
228
|
-
:<></>}
|
|
229
|
-
*/
|
|
162
|
+
export default CompetitionSettingsForm
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import { View, FlatList, TouchableOpacity, ScrollView, Image, ActivityIndicator } from "react-native"
|
|
3
|
+
import Colors from '../../constants/colors';
|
|
4
|
+
import { view_styles } from '../../constants/styles';
|
|
5
|
+
import { Button, Switch, Text } from '../../Components';
|
|
6
|
+
import DropDown from '../../Components/Dropdown';
|
|
7
|
+
import type { EventProps, LeagueProps } from '../../types';
|
|
8
|
+
import { ManageCompetitionMatchApi } from '../api';
|
|
9
|
+
import moment from 'moment-mini';
|
|
10
|
+
import SearchBox from '../../Components/SearchBox';
|
|
11
|
+
|
|
12
|
+
type ContestSelectorProps = {
|
|
13
|
+
width: number,
|
|
14
|
+
action_loading:boolean,
|
|
15
|
+
height:number,
|
|
16
|
+
leagues:LeagueProps[],
|
|
17
|
+
selected_team_events:EventProps[],
|
|
18
|
+
onSelectTeamEvent:(event:EventProps) => void,
|
|
19
|
+
onSelectTeamEvents: (events:EventProps[]) => void,
|
|
20
|
+
onDeselectTeamEvent: (event:EventProps) => void,
|
|
21
|
+
onClose:() => void
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const ContestSelector = ({ action_loading, width, height, leagues, selected_team_events, onClose, onSelectTeamEvent, onDeselectTeamEvent, onSelectTeamEvents }:ContestSelectorProps) => {
|
|
25
|
+
const [ search_value, setSearchValue ] = useState('');
|
|
26
|
+
const [ filters, setFilters ] = useState<{
|
|
27
|
+
ranked?:boolean,
|
|
28
|
+
division?:string,
|
|
29
|
+
sub_division?:string
|
|
30
|
+
}>({})
|
|
31
|
+
const [ selector_data, setData ] = useState<{
|
|
32
|
+
loading:boolean,
|
|
33
|
+
events:EventProps[],
|
|
34
|
+
range_dates:string[],
|
|
35
|
+
active_league?:LeagueProps,
|
|
36
|
+
active_date: string
|
|
37
|
+
}>({
|
|
38
|
+
loading:false,
|
|
39
|
+
events: [],
|
|
40
|
+
range_dates: [],
|
|
41
|
+
active_date: moment().format('YYYY/MM/DD')
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
const { loading, events, range_dates, active_league, active_date } = selector_data;
|
|
45
|
+
|
|
46
|
+
let filtered_events = events.filter(e => `${e.event_id} ${e.away?.market_name} ${e.away?.name} ${e.home?.market_name} ${e.home?.name}`.toLowerCase().includes(search_value.toLowerCase()))
|
|
47
|
+
.filter(e => moment(e.scheduled_datetime).format('YYYY/MM/DD') == active_date)
|
|
48
|
+
.sort((a,b) => moment(a.scheduled_datetime).unix() - moment(b.scheduled_datetime).unix());
|
|
49
|
+
|
|
50
|
+
const divisions = [ ...new Set(filtered_events.map(e => e.away?.division ?? '').concat(filtered_events.map(e => e.home?.division ?? ''))) ].sort((a,b) => {
|
|
51
|
+
return (a < b) ? -1 : (a > b) ? 1 : 0;
|
|
52
|
+
})
|
|
53
|
+
const show_ranked = filtered_events.find(e => e.away?.rank || e.home?.rank) ? true : false
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
if(filters.division){
|
|
57
|
+
filtered_events = filtered_events.filter(e => `${e.away?.division}` == filters.division || `${e.home?.division}` == filters.division)
|
|
58
|
+
}
|
|
59
|
+
const sub_divisions = [ ...new Set(filtered_events.filter(e => e.away?.division == filters.division || e.home?.division == filters.division).map(e => e.away?.sub_division ?? '').concat(filtered_events.map(e => e.home?.sub_division ?? ''))) ].sort((a,b) => {
|
|
60
|
+
return (a < b) ? -1 : (a > b) ? 1 : 0;
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
if(filters.sub_division){
|
|
64
|
+
filtered_events = filtered_events.filter(e => `${e.away?.sub_division}` == filters.sub_division || `${e.home?.sub_division}` == filters.sub_division)
|
|
65
|
+
}
|
|
66
|
+
if(filters.ranked){
|
|
67
|
+
console.log('filtering to ranked')
|
|
68
|
+
filtered_events = filtered_events.filter(e => e.away?.rank || e.home?.rank)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const show_add_all = filtered_events.filter(e => !selected_team_events.map(e => e.event_id.toString()).includes(e.event_id)).length > 0 ? true : false
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
if(leagues.length == 0){ return }
|
|
76
|
+
if(!active_league){ setData({ ...selector_data, active_league: leagues.sort((a,b) => a.priority - b.priority)[0] }) }
|
|
77
|
+
},[leagues])
|
|
78
|
+
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
if(!active_league){ return }
|
|
81
|
+
getDataFromServer(active_league.league_id)
|
|
82
|
+
},[active_league])
|
|
83
|
+
|
|
84
|
+
const getDataFromServer = async(league_id:string) => {
|
|
85
|
+
setData({ ...selector_data, loading:true })
|
|
86
|
+
const resp = await ManageCompetitionMatchApi.getEventsByDate(moment().format('YYYY/MM/DD'), league_id);
|
|
87
|
+
const unique_dates = [ ...new Set(resp.range_dates.filter(d => moment(d).isAfter(moment().subtract(1, 'days'))).sort((a,b) => moment(a).unix() - moment(b).unix()).map(d => moment(d).format('YYYY/MM/DD'))) ]
|
|
88
|
+
//Check to see if we have an event on today's date
|
|
89
|
+
let best_day = unique_dates.find(d => d == moment().format('YYYY/MM/DD'))
|
|
90
|
+
if(!best_day){
|
|
91
|
+
best_day = unique_dates[0] ?? moment().format('YYYY/MM/DD')
|
|
92
|
+
}
|
|
93
|
+
setData({ ...selector_data, loading:false, events: resp.events, range_dates: unique_dates, active_date: best_day })
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const renderDivisions = (data: { item:string, index:number }) => {
|
|
97
|
+
const selected = filters.division == data.item ? true : false
|
|
98
|
+
return (
|
|
99
|
+
<TouchableOpacity style={{ padding:10 }} onPress={() => selected ? setFilters({ ...filters, division: undefined }) : setFilters({ ...filters, division:data.item })}>
|
|
100
|
+
<Text color={selected ? Colors.brand.midnight : Colors.brand.slate} weight={selected ? 'bold': 'regular'}>{data.item}</Text>
|
|
101
|
+
</TouchableOpacity>
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
const renderSubDivisions = (data: { item:string, index:number }) => {
|
|
105
|
+
const selected = filters.sub_division == data.item ? true : false
|
|
106
|
+
return (
|
|
107
|
+
<TouchableOpacity style={{ padding:10 }} onPress={() => selected ? setFilters({ ...filters, sub_division: undefined }) : setFilters({ ...filters, sub_division:data.item })}>
|
|
108
|
+
<Text color={selected ? Colors.brand.midnight : Colors.brand.slate} weight={selected ? 'bold': 'regular'}>{data.item}</Text>
|
|
109
|
+
</TouchableOpacity>
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const renderDates = (data: { item: string, index:number }) => {
|
|
114
|
+
const formatted_date = moment(data.item, 'YYYY/MM/DD')
|
|
115
|
+
const active = active_date == data.item ? true : false
|
|
116
|
+
return (
|
|
117
|
+
<TouchableOpacity style={{ padding:10, justifyContent:'center', alignItems:'center' }} onPress={() => setData({ ...selector_data, active_date: data.item })}>
|
|
118
|
+
<Text size={12} color={Colors.brand.midnight} textAlign='center' weight={active ? 'bold' : 'regular'}>{formatted_date.format('ddd')}</Text>
|
|
119
|
+
<Text style={{ marginTop:3 }} size={12} color={Colors.brand.midnight} textAlign='center' weight={active ? 'bold' : 'regular'}>{formatted_date.format('MMM DD')}</Text>
|
|
120
|
+
</TouchableOpacity>
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const renderEvents = (data: { item:EventProps, index:number }) => {
|
|
125
|
+
const selected = selected_team_events.map(e => e.event_id.toString()).includes(data.item.event_id.toString()) ? true : false
|
|
126
|
+
const is_live = moment(data.item.scheduled_datetime).isBefore(moment()) ? true : false
|
|
127
|
+
return (
|
|
128
|
+
<View style={{ ...view_styles.body_row, padding:10, borderBottomWidth:1, borderColor:Colors.shades.shade600 }}>
|
|
129
|
+
<View style={{ flexDirection:'row', alignItems:'center', paddingRight:10, borderRightWidth:1, borderColor:Colors.shades.shade600 }}>
|
|
130
|
+
<Image
|
|
131
|
+
source={{ uri: data.item.away?.image?.url }}
|
|
132
|
+
style={{ height:34, width:34, borderRadius:4 }}
|
|
133
|
+
resizeMode='cover'
|
|
134
|
+
/>
|
|
135
|
+
<Text style={{ padding:5 }} theme='body'>VS</Text>
|
|
136
|
+
<Image
|
|
137
|
+
source={{ uri: data.item.home?.image?.url }}
|
|
138
|
+
style={{ height:34, width:34, borderRadius:4 }}
|
|
139
|
+
resizeMode='cover'
|
|
140
|
+
/>
|
|
141
|
+
</View>
|
|
142
|
+
<View style={{ flex:1, marginLeft: 10 }}>
|
|
143
|
+
<Text theme='header_2'>{data.item.event_title}</Text>
|
|
144
|
+
<Text style={{ marginTop:3 }} theme='body'>{data.item.time_detail == 'scheduled' ? moment(data.item.scheduled_datetime).format('MMM DD hh:mm a'): data.item.time_detail}</Text>
|
|
145
|
+
</View>
|
|
146
|
+
{!is_live ?
|
|
147
|
+
<Switch
|
|
148
|
+
switch_type='on_off'
|
|
149
|
+
value={selected}
|
|
150
|
+
onChange={() => {
|
|
151
|
+
if(action_loading){ return }
|
|
152
|
+
if(selected){ return onDeselectTeamEvent(data.item) }
|
|
153
|
+
return onSelectTeamEvent(data.item)
|
|
154
|
+
}}
|
|
155
|
+
/>
|
|
156
|
+
:<></>}
|
|
157
|
+
</View>
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return (
|
|
162
|
+
<View style={{ ...view_styles.section, margin:0, width, height }}>
|
|
163
|
+
<View style={{ ...view_styles.section_header, zIndex: 1}}>
|
|
164
|
+
{active_league ?
|
|
165
|
+
<Image
|
|
166
|
+
source={{ uri: active_league.league_image }}
|
|
167
|
+
style={{ height:50, width:50, marginRight:10, borderRadius:4 }}
|
|
168
|
+
resizeMode='cover'
|
|
169
|
+
/>
|
|
170
|
+
:<></>}
|
|
171
|
+
<View style={{ flex:1, marginRight:50 }}>
|
|
172
|
+
<Text theme='header'>MANAGE CONTESTS</Text>
|
|
173
|
+
<Text style={{ marginTop:3 }} theme='body'>Add / Remove contests from the competition</Text>
|
|
174
|
+
</View>
|
|
175
|
+
<View style={{ position: 'absolute', top:10, right:10, justifyContent:'center', alignItems:'center' }}>
|
|
176
|
+
<DropDown
|
|
177
|
+
dropdown_options={[
|
|
178
|
+
{value:'league_id', eligible_options: leagues.sort((a,b) => a.priority - b.priority).map(l => l.league_name)}
|
|
179
|
+
]}
|
|
180
|
+
selected_value={active_league?.league_name ?? 'Select League'}
|
|
181
|
+
onOptionSelect={(league_name) => {
|
|
182
|
+
const league = leagues.find(l => l.league_name == league_name);
|
|
183
|
+
setData({ ...selector_data, active_league: league })
|
|
184
|
+
}}
|
|
185
|
+
/>
|
|
186
|
+
</View>
|
|
187
|
+
</View>
|
|
188
|
+
<ScrollView style={{ flex:1 }}>
|
|
189
|
+
<View style={{ padding:10 }}>
|
|
190
|
+
<FlatList
|
|
191
|
+
data={range_dates}
|
|
192
|
+
renderItem={renderDates}
|
|
193
|
+
horizontal
|
|
194
|
+
keyExtractor={(item) => item}
|
|
195
|
+
/>
|
|
196
|
+
</View>
|
|
197
|
+
<View style={{ marginTop:0 }}>
|
|
198
|
+
<SearchBox
|
|
199
|
+
onChange={(text) => setSearchValue(text)}
|
|
200
|
+
hide_search_button
|
|
201
|
+
/>
|
|
202
|
+
</View>
|
|
203
|
+
{divisions.length > 1 ?
|
|
204
|
+
<View nativeID='filters' style={{ flexDirection:'row' }}>
|
|
205
|
+
{show_ranked ?
|
|
206
|
+
<TouchableOpacity style={{ padding:10 }} onPress={() => filters.ranked ? setFilters({ ...filters, ranked: false }) : setFilters({ ...filters, ranked: true })}>
|
|
207
|
+
<Text color={filters.ranked ? Colors.brand.midnight : Colors.brand.slate} weight={filters.ranked ? 'bold': 'regular'}>Top 25</Text>
|
|
208
|
+
</TouchableOpacity>
|
|
209
|
+
:<></>}
|
|
210
|
+
<FlatList
|
|
211
|
+
data={divisions}
|
|
212
|
+
renderItem={renderDivisions}
|
|
213
|
+
horizontal
|
|
214
|
+
keyExtractor={(item) => item}
|
|
215
|
+
/>
|
|
216
|
+
</View>
|
|
217
|
+
:<></>}
|
|
218
|
+
{filters.division && sub_divisions.length > 1 ?
|
|
219
|
+
<View>
|
|
220
|
+
<FlatList
|
|
221
|
+
data={sub_divisions}
|
|
222
|
+
renderItem={renderSubDivisions}
|
|
223
|
+
horizontal
|
|
224
|
+
keyExtractor={(item) => item}
|
|
225
|
+
/>
|
|
226
|
+
</View>
|
|
227
|
+
:<></>}
|
|
228
|
+
<View style={{ padding:10 }}>
|
|
229
|
+
{loading ?
|
|
230
|
+
<ActivityIndicator style={{ padding:20, alignSelf:'center' }} size='large' color={Colors.brand.midnight} />
|
|
231
|
+
:<></>}
|
|
232
|
+
<FlatList
|
|
233
|
+
data={filtered_events}
|
|
234
|
+
renderItem={renderEvents}
|
|
235
|
+
keyExtractor={(item) => item.event_id.toString()}
|
|
236
|
+
/>
|
|
237
|
+
</View>
|
|
238
|
+
</ScrollView>
|
|
239
|
+
<View style={{ ...view_styles.section_footer, flexDirection:'row' }}>
|
|
240
|
+
{filtered_events.length > 0 ?
|
|
241
|
+
<Button
|
|
242
|
+
title='ADD ALL'
|
|
243
|
+
style={{ flex:2, marginRight:10, opacity:!show_add_all || action_loading?0.5:1 }}
|
|
244
|
+
loading={action_loading}
|
|
245
|
+
disabled={!show_add_all || action_loading}
|
|
246
|
+
padding={15}
|
|
247
|
+
title_color={Colors.shades.white}
|
|
248
|
+
backgroundColor={Colors.brand.electric}
|
|
249
|
+
onPress={() => {
|
|
250
|
+
///First remove any event that is already selected
|
|
251
|
+
let add_events = filtered_events.filter(e => !selected_team_events.map(e => e.event_id.toString()).includes(e.event_id))
|
|
252
|
+
onSelectTeamEvents(add_events);
|
|
253
|
+
}}
|
|
254
|
+
/>
|
|
255
|
+
:<></>}
|
|
256
|
+
<Button
|
|
257
|
+
style={{ flex:1 }}
|
|
258
|
+
padding={15}
|
|
259
|
+
title='CLOSE'
|
|
260
|
+
title_color={Colors.shades.white}
|
|
261
|
+
backgroundColor={Colors.utility.error}
|
|
262
|
+
onPress={() => onClose()}
|
|
263
|
+
/>
|
|
264
|
+
</View>
|
|
265
|
+
</View>
|
|
266
|
+
)
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export default ContestSelector
|