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
|
@@ -2,19 +2,44 @@ import React, { useEffect, useState } from 'react';
|
|
|
2
2
|
import { ScrollView, View, ActivityIndicator } from "react-native"
|
|
3
3
|
import { view_styles } from '../constants/styles';
|
|
4
4
|
import CompetitionInfoForm from './components/CompetitionInfoForm';
|
|
5
|
-
import type { AthleteProps, CompetitionMatchMarketProps, CompetitionMatchProps, CompetitionPayoutTypeProps, CompetitionProps, CompetitionResultTypeProps, CompetitionTypeProps, EventProps, LeagueProps, MarketProps, MatchProps, TeamProps, TournamentProps } from '../types';
|
|
5
|
+
import type { AthleteProps, CompetitionMatchMarketProps, CompetitionMatchProps, CompetitionPayoutTypeProps, CompetitionProps, CompetitionResultTypeProps, CompetitionSummaryProps, CompetitionTypeProps, EventProps, LeagueProps, MarketProps, MatchProps, TeamProps, TournamentProps, TradeProps } from '../types';
|
|
6
6
|
import Colors from '../constants/colors';
|
|
7
|
-
import { ManageCompetitionApi, ManageCompetitionMatchApi } from './api';
|
|
7
|
+
import { ManageCompetitionApi, ManageCompetitionHelpers, ManageCompetitionMarketApi, ManageCompetitionMatchApi } from './api';
|
|
8
8
|
import CompetitionSettingsForm from './components/CompetitionSettingsForm';
|
|
9
9
|
import CompetitionContestsForm from './components/CompetitionContestsForm';
|
|
10
|
+
import ContestSelector from './components/ContestSelector';
|
|
11
|
+
import MarketSelector from './components/MarketSelector';
|
|
12
|
+
import AthleteSelector from './components/AthleteSelector';
|
|
13
|
+
import ContestSettingsForm from './components/ContestSettingsForm';
|
|
14
|
+
import CompetitionHeader from './components/CompetitionHeader';
|
|
15
|
+
import { Button } from '../Components';
|
|
10
16
|
|
|
11
17
|
type CompetitionManagerProps = {
|
|
12
18
|
player_id?:string,
|
|
13
|
-
competition_id:string
|
|
19
|
+
competition_id:string,
|
|
20
|
+
onClose:() => void
|
|
14
21
|
}
|
|
15
22
|
|
|
16
|
-
const CompetitionManager = ({ competition_id }:CompetitionManagerProps) => {
|
|
23
|
+
const CompetitionManager = ({ player_id, competition_id, onClose }:CompetitionManagerProps) => {
|
|
17
24
|
const [ module_size, setModuleSize ] = useState({ height:0, width:0 });
|
|
25
|
+
const [ action_loading, setActionLoading ] = useState(false);
|
|
26
|
+
const [ show_athletes, setShowAthletes ] = useState<{
|
|
27
|
+
contest_id?:string,
|
|
28
|
+
contest_type?:string,
|
|
29
|
+
market_id?:string,
|
|
30
|
+
filtered_positions:string[]
|
|
31
|
+
}>({
|
|
32
|
+
filtered_positions: []
|
|
33
|
+
});
|
|
34
|
+
const [ show_contests, setShowContests ] = useState<{
|
|
35
|
+
visible: boolean
|
|
36
|
+
}>({
|
|
37
|
+
visible: false
|
|
38
|
+
})
|
|
39
|
+
const [ show_markets, setShowMarkets ] = useState<{
|
|
40
|
+
contest_id?:string,
|
|
41
|
+
contest_type?:string
|
|
42
|
+
}>({})
|
|
18
43
|
const [ competition_data, setCompetitionData ] = useState<{
|
|
19
44
|
loaded:boolean,
|
|
20
45
|
loading:boolean,
|
|
@@ -25,6 +50,8 @@ const CompetitionManager = ({ competition_id }:CompetitionManagerProps) => {
|
|
|
25
50
|
competition_types:CompetitionTypeProps[],
|
|
26
51
|
competition_matches:CompetitionMatchProps[],
|
|
27
52
|
competition_match_markets:CompetitionMatchMarketProps[],
|
|
53
|
+
competition_summaries: CompetitionSummaryProps[],
|
|
54
|
+
trades:TradeProps[],
|
|
28
55
|
markets:MarketProps[],
|
|
29
56
|
leagues:LeagueProps[],
|
|
30
57
|
events:EventProps[],
|
|
@@ -37,6 +64,7 @@ const CompetitionManager = ({ competition_id }:CompetitionManagerProps) => {
|
|
|
37
64
|
loaded:false,
|
|
38
65
|
loading:false,
|
|
39
66
|
competition_result_types: [],
|
|
67
|
+
competition_summaries:[],
|
|
40
68
|
competition_types: [],
|
|
41
69
|
competition_matches: [],
|
|
42
70
|
competition_payout_types:[],
|
|
@@ -44,14 +72,48 @@ const CompetitionManager = ({ competition_id }:CompetitionManagerProps) => {
|
|
|
44
72
|
markets: [],
|
|
45
73
|
leagues:[],
|
|
46
74
|
events: [],
|
|
75
|
+
trades:[],
|
|
47
76
|
tournaments: [],
|
|
48
77
|
matches:[],
|
|
49
78
|
teams:[],
|
|
50
79
|
athletes:[]
|
|
51
80
|
})
|
|
81
|
+
const { contest_id, contest_type } = show_markets;
|
|
82
|
+
const { loaded, competition, competition_result_types, trades, competition_types, draft_competition, competition_matches, competition_match_markets, markets, leagues, events, tournaments, matches, teams, athletes } = competition_data;
|
|
83
|
+
|
|
84
|
+
//Market Selector Stuff
|
|
85
|
+
const showing_market_event = events.find(e => e.event_id == contest_id && contest_type == 'team');
|
|
86
|
+
const showing_market_event_matches = competition_matches.filter(cm => cm.event_type == 'team' && cm.event_id == contest_id);
|
|
87
|
+
const show_market_markets = competition_match_markets.filter(cmm => showing_market_event_matches.map(cm => cm.competition_match_id.toString()).includes(cmm.competition_match_id))
|
|
88
|
+
const show_market_id_overrides = showing_market_event_matches.filter(cm => cm.market_id_override).map(cm => cm.market_id_override??'0');
|
|
89
|
+
|
|
90
|
+
//AthleteSelectorStuff
|
|
91
|
+
const select_athlete_matches = competition_matches.filter(cm => cm.event_id == show_athletes.contest_id && cm.event_type == show_athletes.contest_type && cm.market_id_override == show_athletes.market_id);
|
|
92
|
+
const selected_athletes = select_athlete_matches.filter(m => m.side_type_override == 'athlete').map(m => m.side_id_override ?? '0');
|
|
93
|
+
const select_athlete_event = events.find(e => show_athletes.contest_type == 'team' && e.event_id == show_athletes.contest_id);
|
|
94
|
+
const select_athlete_positions = markets.find(m => m.market_id == show_athletes.market_id)?.supported_positions ?? []
|
|
95
|
+
//Filter Athletes to those with trades
|
|
96
|
+
let trade_athletes = [ ...new Set(trades.filter(t => t.market_type == 'FOR_MONEY' && t.market_id == show_athletes.market_id && t.side_type == 'athlete').map(t => t.side_id))]
|
|
97
|
+
|
|
98
|
+
//Lets figure out if we can add / remove a primary market for all of them
|
|
99
|
+
let primary_markets:{ market: MarketProps, included: boolean }[] = []
|
|
100
|
+
events.map(e => {
|
|
101
|
+
if(!e.supported_markets){ return }
|
|
102
|
+
e.supported_markets.map(sm => {
|
|
103
|
+
let market = markets.find(m => m.market_id == sm.market_id)
|
|
104
|
+
if(!market?.primary_market){ return }
|
|
105
|
+
let exists = primary_markets.find(pm => pm.market.market_id == sm.market_id)
|
|
106
|
+
if(!exists){
|
|
107
|
+
//check if this has been included or not!
|
|
108
|
+
let included = competition_match_markets.find(cmm => cmm.market_id == market.market_id) ? true : false
|
|
109
|
+
primary_markets.push({ market, included })
|
|
110
|
+
|
|
111
|
+
}
|
|
112
|
+
})
|
|
113
|
+
})
|
|
52
114
|
|
|
53
|
-
const { loaded, competition, competition_result_types, competition_types, draft_competition, competition_matches, competition_match_markets, markets, leagues, events, tournaments, matches, teams, athletes } = competition_data;
|
|
54
115
|
|
|
116
|
+
const competition_valid = ManageCompetitionHelpers.isCompetitionValid(competition_types, competition_result_types, competition_matches, competition_match_markets, events, competition)
|
|
55
117
|
|
|
56
118
|
useEffect(() => {
|
|
57
119
|
if(!loaded){ ManageCompetitionApi.setEnvironment() }
|
|
@@ -64,6 +126,7 @@ const CompetitionManager = ({ competition_id }:CompetitionManagerProps) => {
|
|
|
64
126
|
const options = await ManageCompetitionApi.getCompetitionOptions()
|
|
65
127
|
const lgs = await ManageCompetitionApi.getLeagues();
|
|
66
128
|
const mks = await ManageCompetitionApi.getMarkets();
|
|
129
|
+
const summaries = await ManageCompetitionApi.getCompetitionSummaries(id);
|
|
67
130
|
//Get unique contests
|
|
68
131
|
let event_ids = cm_resp.competition_matches.filter(cm => cm.event_type == 'team').map(cm => cm.event_id);
|
|
69
132
|
let tournament_ids = cm_resp.competition_matches.filter(cm => cm.event_type == 'tournament').map(cm => cm.event_id);
|
|
@@ -74,12 +137,14 @@ const CompetitionManager = ({ competition_id }:CompetitionManagerProps) => {
|
|
|
74
137
|
|
|
75
138
|
let c_events:EventProps[] = []
|
|
76
139
|
if(event_ids.length > 0){ c_events = await ManageCompetitionMatchApi.getEventsByEventIds(event_ids) }
|
|
77
|
-
|
|
140
|
+
let e_trades = await ManageCompetitionMarketApi.getLatestTradesByEventIds(event_ids, 'team');
|
|
78
141
|
let c_tournaments:TournamentProps[] = []
|
|
79
142
|
if(tournament_ids.length > 0){ c_tournaments = await ManageCompetitionMatchApi.getTournamentsByTournamentIds(tournament_ids) }
|
|
143
|
+
let t_trades = await ManageCompetitionMarketApi.getLatestTradesByEventIds(tournament_ids, 'tournamet');
|
|
80
144
|
|
|
81
145
|
let c_matches:MatchProps[] = []
|
|
82
146
|
if(match_ids.length > 0){ c_matches = await ManageCompetitionMatchApi.getMatchesByMatchIds(match_ids) }
|
|
147
|
+
let m_trades = await ManageCompetitionMarketApi.getLatestTradesByEventIds(match_ids, 'match');
|
|
83
148
|
|
|
84
149
|
let c_teams:TeamProps[] = []
|
|
85
150
|
if(team_ids.length > 0){ c_teams = await ManageCompetitionMatchApi.getTeamsByIds(team_ids) }
|
|
@@ -92,6 +157,7 @@ const CompetitionManager = ({ competition_id }:CompetitionManagerProps) => {
|
|
|
92
157
|
loading: false,
|
|
93
158
|
competition: c,
|
|
94
159
|
leagues: lgs,
|
|
160
|
+
competition_summaries: summaries,
|
|
95
161
|
competition_types: options.competition_types,
|
|
96
162
|
competition_payout_types: options.competition_payout_types,
|
|
97
163
|
competition_result_types: options.competition_result_types,
|
|
@@ -100,23 +166,244 @@ const CompetitionManager = ({ competition_id }:CompetitionManagerProps) => {
|
|
|
100
166
|
competition_match_markets: cm_resp.competition_match_markets,
|
|
101
167
|
events: c_events,
|
|
102
168
|
markets: mks,
|
|
169
|
+
trades: e_trades.concat(m_trades).concat(t_trades),
|
|
103
170
|
tournaments: c_tournaments,
|
|
104
171
|
matches: c_matches,
|
|
105
172
|
teams: c_teams,
|
|
106
173
|
athletes: c_athletes,
|
|
107
174
|
})
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const handleRemovePrimaryMarket = async(market:MarketProps) => {
|
|
178
|
+
setActionLoading(true);
|
|
179
|
+
//Grab all markets
|
|
180
|
+
let remove_markets = competition_match_markets.filter(cmm => cmm.market_id == market.market_id);
|
|
181
|
+
await ManageCompetitionMatchApi.deleteCompetitionMatchMarkets(remove_markets.map(cmm => cmm.competition_match_market_id));
|
|
182
|
+
setCompetitionData({
|
|
183
|
+
...competition_data,
|
|
184
|
+
competition_match_markets: competition_match_markets.filter(cmm => cmm.market_id != market.market_id)
|
|
185
|
+
})
|
|
186
|
+
setActionLoading(false);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const handleAddPrimaryMarket = async(market:MarketProps) => {
|
|
190
|
+
setActionLoading(true);
|
|
191
|
+
let market_cmms:CompetitionMatchMarketProps[] = [];
|
|
192
|
+
let primary_matches = competition_matches.filter(cm => !cm.market_id_override);
|
|
193
|
+
primary_matches.map(cm => {
|
|
194
|
+
let existing_markets = competition_match_markets.filter(cmm => cmm.competition_match_id == cm.competition_match_id && cmm.market_id == market.market_id);
|
|
195
|
+
if(existing_markets.length > 0){ return } //Dont do anything on that one!
|
|
196
|
+
let market_trades = trades.filter(t => t.market_type == 'FOR_MONEY' && t.event_id == cm.event_id && t.event_type == cm.event_type && t.market_id == market.market_id);
|
|
197
|
+
if(market_trades.length != 2){ console.log(`no trades for event ${cm.event_id}`); return } //This event doesnt have the trades
|
|
198
|
+
let new_cmms:CompetitionMatchMarketProps[] = []
|
|
199
|
+
market_trades.map(t => {
|
|
200
|
+
new_cmms.push({ ...ManageCompetitionHelpers.createCompetitionMatchMarketFromTrade(t), competition_match_id: cm.competition_match_id })
|
|
201
|
+
})
|
|
202
|
+
market_cmms = market_cmms.concat(new_cmms)
|
|
203
|
+
})
|
|
204
|
+
market_cmms = await ManageCompetitionMatchApi.createCompetitionMatchMarkets(market_cmms);
|
|
205
|
+
setCompetitionData({
|
|
206
|
+
...competition_data,
|
|
207
|
+
competition_match_markets: competition_match_markets.filter(cmm => !market_cmms.find(ncmm => ncmm.competition_match_market_id == cmm.competition_match_market_id)).concat(market_cmms)
|
|
208
|
+
})
|
|
209
|
+
setActionLoading(false)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const handleSelectTeamEvents = async(new_events:EventProps[]) => {
|
|
213
|
+
if(action_loading || !competition){ return }
|
|
214
|
+
setActionLoading(true);
|
|
215
|
+
let added_matches:CompetitionMatchProps[] = [];
|
|
216
|
+
const addEvents = new_events.map(async e => {
|
|
217
|
+
const cm = await ManageCompetitionMatchApi.createCompetitionMatch(competition_id, e.event_id, 'team', 'event', undefined, undefined, undefined);
|
|
218
|
+
added_matches.push(cm)
|
|
219
|
+
})
|
|
220
|
+
await Promise.all(addEvents);
|
|
221
|
+
const e_trades = await ManageCompetitionMarketApi.getLatestTradesByEventIds(new_events.map(e => e.event_id), 'team');
|
|
222
|
+
setCompetitionData({
|
|
223
|
+
...competition_data,
|
|
224
|
+
competition: { ...competition, scheduled_datetime: undefined },
|
|
225
|
+
competition_matches: competition_matches.concat(added_matches),
|
|
226
|
+
events: events.filter(e => !new_events.find(ne => ne.event_id == e.event_id)).concat(new_events),
|
|
227
|
+
trades: trades.filter(t => !events.map(e => e.event_id.toString()).includes(t.event_id)).concat(e_trades)
|
|
228
|
+
})
|
|
229
|
+
setActionLoading(false)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const handleSelectTeamEvent = async(event:EventProps) => {
|
|
233
|
+
if(action_loading || !competition){ return }
|
|
234
|
+
setActionLoading(true);
|
|
235
|
+
const cm = await ManageCompetitionMatchApi.createCompetitionMatch(competition_id, event.event_id, 'team', 'event', undefined, undefined, undefined);
|
|
236
|
+
const e_trades = await ManageCompetitionMarketApi.getLatestTradesByEventIds([event.event_id], 'team');
|
|
237
|
+
setCompetitionData({
|
|
238
|
+
...competition_data,
|
|
239
|
+
competition: { ...competition, scheduled_datetime: undefined },
|
|
240
|
+
competition_matches: competition_matches.concat(cm),
|
|
241
|
+
events: events.filter(e => e.event_id != event.event_id).concat(event),
|
|
242
|
+
trades: trades.filter(t => t.event_id != event.event_id).concat(e_trades)
|
|
243
|
+
})
|
|
244
|
+
setActionLoading(false);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const handleRemoveCompetitionMatch = async(competition_match_id:string) => {
|
|
248
|
+
if(action_loading){ return }
|
|
249
|
+
setActionLoading(true);
|
|
250
|
+
await ManageCompetitionMatchApi.deleteCompetitionMatch(competition_match_id);
|
|
251
|
+
setCompetitionData({
|
|
252
|
+
...competition_data,
|
|
253
|
+
competition_matches: competition_matches.filter(cm => cm.competition_match_id != competition_match_id)
|
|
254
|
+
})
|
|
255
|
+
setActionLoading(false)
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const handleRemoveCompetitionMatchMarkets = async(cmms:CompetitionMatchMarketProps[]) => {
|
|
259
|
+
if(action_loading){ return }
|
|
260
|
+
setActionLoading(true);
|
|
261
|
+
await ManageCompetitionMatchApi.deleteCompetitionMatchMarkets(cmms.map(cmm => cmm.competition_match_market_id));
|
|
262
|
+
setCompetitionData({
|
|
263
|
+
...competition_data,
|
|
264
|
+
competition_match_markets: competition_match_markets.filter(cmm => !cmms.map(rmm => rmm.competition_match_market_id.toString()).includes(cmm.competition_match_market_id))
|
|
265
|
+
})
|
|
266
|
+
setActionLoading(false)
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const handleDeselectTeamEvent = async(event:EventProps) => {
|
|
270
|
+
const cms = competition_matches.filter(cm => cm.event_id == event.event_id && cm.event_type == 'team');
|
|
271
|
+
const deleteCMS = cms.map(async cm => {
|
|
272
|
+
await ManageCompetitionMatchApi.deleteCompetitionMatch(cm.competition_match_id);
|
|
273
|
+
})
|
|
274
|
+
await Promise.all(deleteCMS);
|
|
275
|
+
setCompetitionData({
|
|
276
|
+
...competition_data,
|
|
277
|
+
competition_matches: competition_matches.filter(cm => !cms.find(dcm => dcm.competition_match_id == cm.competition_match_id))
|
|
278
|
+
})
|
|
279
|
+
}
|
|
280
|
+
const handleSelectAthlete = async(athlete:AthleteProps) => {
|
|
281
|
+
if(!show_athletes?.contest_id || !show_athletes?.contest_type){ return }
|
|
282
|
+
let athlete_trades = trades.filter(t => t.market_type == 'FOR_MONEY' && t.side_type == 'athlete' && t.side_id == athlete.athlete_id && t.market_id == show_athletes.market_id);
|
|
283
|
+
if(athlete_trades.length != 2){ return alert('Unable to add') }
|
|
284
|
+
|
|
285
|
+
if(action_loading){ return }
|
|
286
|
+
setActionLoading(true);
|
|
287
|
+
//First check if there is an existing market_id override without a side_id_override and add it!
|
|
288
|
+
let existing_cm = competition_matches.find(cm => cm.event_id == show_athletes.contest_id && cm.event_type == show_athletes.contest_type && cm.market_id_override == show_athletes.market_id && !cm.side_id_override);
|
|
289
|
+
if(existing_cm){
|
|
290
|
+
existing_cm = await ManageCompetitionMatchApi.updateCompetitionMatch({ ...existing_cm, side_type_override: 'athlete', side_id_override: athlete.athlete_id });
|
|
291
|
+
} else {
|
|
292
|
+
existing_cm = await ManageCompetitionMatchApi.createCompetitionMatch(competition_id, show_athletes.contest_id, show_athletes.contest_type, 'athlete', show_athletes.market_id, 'athlete', athlete.athlete_id)
|
|
293
|
+
}
|
|
294
|
+
let new_cmms:CompetitionMatchMarketProps[] = []
|
|
295
|
+
athlete_trades.map(t => {
|
|
296
|
+
new_cmms.push({ ...ManageCompetitionHelpers.createCompetitionMatchMarketFromTrade(t), competition_match_id: existing_cm.competition_match_id })
|
|
297
|
+
})
|
|
298
|
+
new_cmms = await ManageCompetitionMatchApi.createCompetitionMatchMarkets(new_cmms);
|
|
299
|
+
setCompetitionData({
|
|
300
|
+
...competition_data,
|
|
301
|
+
athletes: athletes.concat(athlete),
|
|
302
|
+
competition_matches: competition_matches.filter(cm => cm.competition_match_id != existing_cm.competition_match_id).concat(existing_cm),
|
|
303
|
+
competition_match_markets:competition_match_markets.filter(cmm => !new_cmms.find(ncmm => ncmm.competition_match_market_id == cmm.competition_match_market_id)).concat(new_cmms)
|
|
304
|
+
})
|
|
305
|
+
setActionLoading(false)
|
|
306
|
+
}
|
|
108
307
|
|
|
308
|
+
const handleDeselectAthlete = async(athlete:AthleteProps) => {
|
|
309
|
+
if(!show_athletes?.contest_id || !show_athletes?.contest_type || !show_athletes?.market_id){ return }
|
|
310
|
+
let athlete_cm = competition_matches.find(cm => cm.market_id_override == show_athletes.market_id && cm.side_id_override == athlete.athlete_id)
|
|
311
|
+
if(!athlete_cm){ return alert('Unable to remove') }
|
|
312
|
+
if(action_loading){ return }
|
|
313
|
+
setActionLoading(true);
|
|
314
|
+
let cmms = competition_match_markets.filter(cmm => cmm.competition_match_id == athlete_cm.competition_match_id);
|
|
315
|
+
await ManageCompetitionMatchApi.deleteCompetitionMatch(athlete_cm.competition_match_id);
|
|
316
|
+
await ManageCompetitionMatchApi.deleteCompetitionMatchMarkets(cmms.map(cmm => cmm.competition_match_id))
|
|
317
|
+
setCompetitionData({
|
|
318
|
+
...competition_data,
|
|
319
|
+
competition_matches: competition_matches.filter(cm => cm.competition_match_id != athlete_cm.competition_match_id),
|
|
320
|
+
competition_match_markets: competition_match_markets.filter(cmm => !cmms.map(rmm => rmm.competition_match_market_id.toString()).includes(cmm.competition_match_market_id))
|
|
321
|
+
})
|
|
322
|
+
setActionLoading(false)
|
|
109
323
|
}
|
|
110
324
|
|
|
325
|
+
const handleRemoveMarket = async(contest_id:string, contest_type:string, market:MarketProps) => {
|
|
326
|
+
if(action_loading){ return }
|
|
327
|
+
setActionLoading(true);
|
|
328
|
+
let relevant_matches = competition_matches.filter(cm => cm.event_id == contest_id && cm.event_type == contest_type);
|
|
329
|
+
//First remove all the non_primary if there are any
|
|
330
|
+
let non_primary_matches = relevant_matches.filter(cm => cm.market_id_override == market.market_id);
|
|
331
|
+
let matches_removed:string[] = []
|
|
332
|
+
let markets_removed:string[] = []
|
|
333
|
+
const rem_non_primary = non_primary_matches.map(async cm => {
|
|
334
|
+
const del_response = await ManageCompetitionMatchApi.deleteCompetitionMatch(cm.competition_match_id);
|
|
335
|
+
matches_removed = matches_removed.concat(del_response.competition_match.competition_match_id)
|
|
336
|
+
markets_removed = markets_removed.concat(del_response.competition_match_markets.map(cmm => cmm.competition_match_market_id))
|
|
337
|
+
})
|
|
338
|
+
await Promise.all(rem_non_primary)
|
|
339
|
+
|
|
340
|
+
//Ok now lets looks for the primary market one
|
|
341
|
+
let primary_match = relevant_matches.find(cm => !cm.market_id_override)
|
|
342
|
+
if(primary_match){
|
|
343
|
+
let primary_cmms = competition_match_markets.filter(cmm => cmm.competition_match_id == primary_match.competition_match_id && cmm.market_id == market.market_id);
|
|
344
|
+
|
|
345
|
+
await ManageCompetitionMatchApi.deleteCompetitionMatchMarkets(primary_cmms.map(cmm => cmm.competition_match_market_id));
|
|
346
|
+
markets_removed = markets_removed.concat(primary_cmms.map(cmm => cmm.competition_match_market_id));
|
|
347
|
+
}
|
|
348
|
+
setCompetitionData({
|
|
349
|
+
...competition_data,
|
|
350
|
+
competition_matches: competition_matches.filter(cm => !matches_removed.includes(cm.competition_match_id)),
|
|
351
|
+
competition_match_markets: competition_match_markets.filter(cmm => !markets_removed.includes(cmm.competition_match_market_id))
|
|
352
|
+
})
|
|
353
|
+
setActionLoading(false);
|
|
354
|
+
}
|
|
111
355
|
|
|
112
|
-
|
|
356
|
+
const handleAddMarket = async(contest_id:string, contest_type:string, market:MarketProps) => {
|
|
357
|
+
if(action_loading){ return }
|
|
358
|
+
setActionLoading(true);
|
|
359
|
+
//First check if this is a primary market
|
|
360
|
+
if(market.primary_market){
|
|
361
|
+
//Get the competition match that is available for it!
|
|
362
|
+
let primary_match = competition_matches.find(cm => cm.event_type == contest_type && cm.event_id == contest_id && !cm.market_id_override);
|
|
363
|
+
if(!primary_match){
|
|
364
|
+
setActionLoading(false)
|
|
365
|
+
return alert('Unable to add this market')
|
|
366
|
+
}
|
|
367
|
+
//Now lets get the trades!!
|
|
368
|
+
let market_trades = trades.filter(t => t.market_type == 'FOR_MONEY' && t.event_id == contest_id && t.event_type == contest_type && t.market_id == market.market_id)
|
|
369
|
+
let cmms:CompetitionMatchMarketProps[] = []
|
|
370
|
+
market_trades.map(t => {
|
|
371
|
+
cmms.push({ ...ManageCompetitionHelpers.createCompetitionMatchMarketFromTrade(t), competition_match_id: primary_match.competition_match_id })
|
|
372
|
+
})
|
|
373
|
+
if(cmms.length != 2){
|
|
374
|
+
setActionLoading(false)
|
|
375
|
+
return alert('Unable to add this market')
|
|
376
|
+
}
|
|
377
|
+
const new_cmms = await ManageCompetitionMatchApi.createCompetitionMatchMarkets(cmms);
|
|
378
|
+
setActionLoading(false);
|
|
379
|
+
return setCompetitionData({
|
|
380
|
+
...competition_data,
|
|
381
|
+
competition_match_markets: competition_match_markets.filter(cmms => new_cmms.find(ncms => ncms.competition_match_market_id != cmms.competition_match_market_id)).concat(new_cmms)
|
|
382
|
+
})
|
|
383
|
+
}
|
|
384
|
+
//If this is not a primary market - we need to add a market_id override for the competition match!!
|
|
385
|
+
let existing_match = competition_matches.find(cm => cm.event_type == contest_type && cm.event_id == contest_id && cm.market_id_override == market.market_id);
|
|
386
|
+
if(existing_match){
|
|
387
|
+
setActionLoading(false)
|
|
388
|
+
return alert('Already added this market!')
|
|
389
|
+
}
|
|
390
|
+
const new_cm = await ManageCompetitionMatchApi.createCompetitionMatch(competition_id, contest_id, contest_type, market.level, market.market_id);
|
|
391
|
+
setCompetitionData({
|
|
392
|
+
...competition_data,
|
|
393
|
+
competition_matches: competition_matches.concat(new_cm)
|
|
394
|
+
})
|
|
395
|
+
setActionLoading(false)
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
if(!competition || !draft_competition || player_id != competition.admin_id){
|
|
113
400
|
return (
|
|
114
401
|
<View style={{flex:1}}>
|
|
115
402
|
<ActivityIndicator size='large' color={Colors.brand.midnight} style={{ padding:20, alignSelf:'center' }} />
|
|
116
403
|
</View>
|
|
117
404
|
)
|
|
118
405
|
}
|
|
119
|
-
|
|
406
|
+
|
|
120
407
|
return (
|
|
121
408
|
<View style={{ flex:1 }}>
|
|
122
409
|
<ScrollView style={{ flex:1 }} onLayout={(ev) => {
|
|
@@ -124,38 +411,147 @@ const CompetitionManager = ({ competition_id }:CompetitionManagerProps) => {
|
|
|
124
411
|
setModuleSize({ height, width })
|
|
125
412
|
}}>
|
|
126
413
|
<View style={{ ...view_styles.wrapper }}>
|
|
414
|
+
<CompetitionHeader
|
|
415
|
+
action_loading={action_loading}
|
|
416
|
+
width={module_size.width}
|
|
417
|
+
competition={competition}
|
|
418
|
+
competition_valid={competition_valid}
|
|
419
|
+
onActivate={async() => {
|
|
420
|
+
setActionLoading(true);
|
|
421
|
+
const new_c = await ManageCompetitionApi.activateCompetition(competition_id)
|
|
422
|
+
setCompetitionData({ ...competition_data, competition: new_c })
|
|
423
|
+
setActionLoading(false);
|
|
424
|
+
}}
|
|
425
|
+
onPause={async() => {
|
|
426
|
+
setActionLoading(true);
|
|
427
|
+
const new_c = await ManageCompetitionApi.pauseCompetition(competition_id)
|
|
428
|
+
const new_summaries = await ManageCompetitionApi.getCompetitionSummaries(competition_id);
|
|
429
|
+
setCompetitionData({ ...competition_data, competition: new_c, competition_summaries: new_summaries })
|
|
430
|
+
setActionLoading(false);
|
|
431
|
+
}}
|
|
432
|
+
onResume={async() => {
|
|
433
|
+
setActionLoading(true);
|
|
434
|
+
const new_c = await ManageCompetitionApi.resumeCompetition(competition_id);
|
|
435
|
+
setCompetitionData({ ...competition_data, competition: new_c })
|
|
436
|
+
setActionLoading(false);
|
|
437
|
+
|
|
438
|
+
}}
|
|
439
|
+
/>
|
|
127
440
|
<CompetitionInfoForm
|
|
128
|
-
|
|
441
|
+
is_valid={competition_valid.info}
|
|
442
|
+
competition={competition}
|
|
129
443
|
width={module_size.width - 20}
|
|
130
|
-
onCompetitionUpdate={(comp) =>
|
|
444
|
+
onCompetitionUpdate={async(comp) => {
|
|
445
|
+
const new_c = await ManageCompetitionApi.updateCompetition(comp);
|
|
446
|
+
setCompetitionData({ ...competition_data, competition: new_c });
|
|
447
|
+
}}
|
|
131
448
|
/>
|
|
132
449
|
<CompetitionSettingsForm
|
|
133
|
-
|
|
450
|
+
is_valid={competition_valid.settings}
|
|
451
|
+
competition={competition}
|
|
134
452
|
width={module_size.width - 20}
|
|
135
453
|
competition_result_types={competition_result_types}
|
|
136
|
-
|
|
137
|
-
|
|
454
|
+
onCompetitionUpdate={async(comp) => {
|
|
455
|
+
const new_c = await ManageCompetitionApi.updateCompetition(comp);
|
|
456
|
+
setCompetitionData({ ...competition_data, competition: new_c });
|
|
457
|
+
}}
|
|
138
458
|
/>
|
|
139
459
|
<CompetitionContestsForm
|
|
460
|
+
action_loading={action_loading}
|
|
461
|
+
is_valid={competition_valid.contests}
|
|
140
462
|
width={module_size.width - 20}
|
|
141
|
-
competition={
|
|
463
|
+
competition={competition}
|
|
142
464
|
competition_matches={competition_matches}
|
|
143
465
|
competition_match_markets={competition_match_markets}
|
|
144
466
|
events={events}
|
|
467
|
+
primary_markets={primary_markets}
|
|
145
468
|
teams={teams}
|
|
146
469
|
athletes={athletes}
|
|
147
470
|
tournaments={tournaments}
|
|
471
|
+
onAddPrimaryMarket={(market) => handleAddPrimaryMarket(market)}
|
|
472
|
+
onRemovePrimaryMarket={(market) => handleRemovePrimaryMarket(market)}
|
|
148
473
|
matches={matches}
|
|
149
474
|
leagues={leagues}
|
|
150
475
|
markets={markets}
|
|
476
|
+
onDeleteMarket={(contest_id, contest_type, market) => handleRemoveMarket(contest_id, contest_type, market)}
|
|
477
|
+
onShowAthletes={(contest_id, contest_type, market_id) => setShowAthletes({ contest_id, contest_type, market_id, filtered_positions:[] })}
|
|
478
|
+
onShowMarkets={(contest_id, contest_type) => setShowMarkets({ contest_id, contest_type })}
|
|
479
|
+
onShowContests={() => setShowContests({ visible:true })}
|
|
151
480
|
onSaveCompetitionMatch={() => console.log('SAVE EVENT')}
|
|
152
|
-
onDeleteCompetitionMatch={() =>
|
|
481
|
+
onDeleteCompetitionMatch={(competition_match_id) => handleRemoveCompetitionMatch(competition_match_id)}
|
|
153
482
|
onUpdateCompetitionMatch={() => console.log('UPDATE')}
|
|
154
483
|
onSaveCompetitionMatchMarkets={(smms) => console.log(smms)}
|
|
155
|
-
onDeleteCompetitionMatchMarkets={(cmms) =>
|
|
484
|
+
onDeleteCompetitionMatchMarkets={(cmms) => handleRemoveCompetitionMatchMarkets(cmms)}
|
|
485
|
+
/>
|
|
486
|
+
<ContestSettingsForm
|
|
487
|
+
is_valid={competition_valid.contest_settings}
|
|
488
|
+
width={module_size.width - 20}
|
|
489
|
+
competition={competition}
|
|
490
|
+
competition_matches={competition_matches}
|
|
491
|
+
competition_match_markets={competition_match_markets}
|
|
492
|
+
competition_types={competition_types}
|
|
493
|
+
events={events}
|
|
494
|
+
onCompetitionUpdate={async(c) => {
|
|
495
|
+
const new_c = await ManageCompetitionApi.updateCompetition(c)
|
|
496
|
+
setCompetitionData({ ...competition_data, competition: new_c })
|
|
497
|
+
}}
|
|
156
498
|
/>
|
|
157
499
|
</View>
|
|
158
500
|
</ScrollView>
|
|
501
|
+
{show_contests.visible ?
|
|
502
|
+
<View style={{ position:'absolute', top:0, left:0, right:0, bottom:0, backgroundColor:Colors.shades.black_faded, justifyContent:'flex-end' }}>
|
|
503
|
+
<ContestSelector
|
|
504
|
+
action_loading={action_loading}
|
|
505
|
+
height={module_size.height}
|
|
506
|
+
width={module_size.width}
|
|
507
|
+
leagues={leagues}
|
|
508
|
+
onClose={() => setShowContests({ visible: false })}
|
|
509
|
+
onSelectTeamEvent={(event) => handleSelectTeamEvent(event)}
|
|
510
|
+
onSelectTeamEvents={(events) => handleSelectTeamEvents(events)}
|
|
511
|
+
onDeselectTeamEvent={(event) => handleDeselectTeamEvent(event)}
|
|
512
|
+
selected_team_events={events.filter(e => competition_matches.filter(cm => cm.event_type == 'team').map(cm => cm.event_id.toString()).includes(e.event_id.toString()))}
|
|
513
|
+
/>
|
|
514
|
+
</View>
|
|
515
|
+
:<></>}
|
|
516
|
+
{show_athletes.contest_id ?
|
|
517
|
+
<View style={{ position:'absolute', top:0, left:0, right:0, bottom:0, backgroundColor:Colors.shades.black_faded, justifyContent:'flex-end' }}>
|
|
518
|
+
<AthleteSelector
|
|
519
|
+
width={module_size.width}
|
|
520
|
+
height={module_size.height}
|
|
521
|
+
event={select_athlete_event}
|
|
522
|
+
selected_athletes={selected_athletes}
|
|
523
|
+
filtered_positions={select_athlete_positions}
|
|
524
|
+
filtered_athletes={trade_athletes}
|
|
525
|
+
onSelectAthlete={(athlete) => handleSelectAthlete(athlete)}
|
|
526
|
+
onDeselectAthlete={(athlete) => handleDeselectAthlete(athlete)}
|
|
527
|
+
onClose={() => setShowAthletes({ filtered_positions: [] })}
|
|
528
|
+
/>
|
|
529
|
+
</View>
|
|
530
|
+
:<></>}
|
|
531
|
+
{show_markets.contest_id && show_markets.contest_type && showing_market_event ?
|
|
532
|
+
<View style={{ position:'absolute', top:0, left:0, right:0, bottom:0, backgroundColor:Colors.shades.black_faded, justifyContent:'flex-end' }}>
|
|
533
|
+
<MarketSelector
|
|
534
|
+
height={module_size.height}
|
|
535
|
+
width={module_size.width}
|
|
536
|
+
markets={markets.filter(m => showing_market_event.supported_markets?.map(m => m.market_id.toString()).includes(m.market_id.toString()))}
|
|
537
|
+
onClose={() => setShowMarkets({})}
|
|
538
|
+
onDeselectMarket={(market) => handleRemoveMarket(show_markets.contest_id ?? '0', show_markets.contest_type ?? 'team', market)}
|
|
539
|
+
onSelectMarket={(market) => handleAddMarket(show_markets.contest_id ?? '0', show_markets.contest_type ?? 'team', market)}
|
|
540
|
+
selected_markets={[ ...new Set(show_market_markets.map(cmm => cmm.market_id).concat(show_market_id_overrides))]}
|
|
541
|
+
/>
|
|
542
|
+
</View>
|
|
543
|
+
:<></>}
|
|
544
|
+
<View style={{ ...view_styles.section_footer }}>
|
|
545
|
+
<Button
|
|
546
|
+
title='CLOSE'
|
|
547
|
+
style={{ flex:1 }}
|
|
548
|
+
title_color={Colors.shades.white}
|
|
549
|
+
backgroundColor={Colors.utility.error}
|
|
550
|
+
padding={15}
|
|
551
|
+
onPress={() => onClose()}
|
|
552
|
+
|
|
553
|
+
/>
|
|
554
|
+
</View>
|
|
159
555
|
</View>
|
|
160
556
|
)
|
|
161
557
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { TextInput, View } from "react-native"
|
|
2
|
+
import Button from "./Button";
|
|
3
|
+
import React, { useState } from "react";
|
|
4
|
+
import Icons from "./Icons";
|
|
5
|
+
import Colors from "../constants/colors";
|
|
6
|
+
|
|
7
|
+
type SearchBoxProps = {
|
|
8
|
+
onSearch?: (text:string) => void,
|
|
9
|
+
onChange? : (text:string) => void,
|
|
10
|
+
hide_search_button?:boolean,
|
|
11
|
+
placeholder?: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const SearchBox = ({ placeholder, onSearch, onChange, hide_search_button }:SearchBoxProps) => {
|
|
15
|
+
const [ search_value, setSearchValue ] = useState('');
|
|
16
|
+
|
|
17
|
+
const handleSearch = () => {
|
|
18
|
+
if(!onSearch){ return }
|
|
19
|
+
if(search_value == ''){ return alert('Please provide search value') }
|
|
20
|
+
onSearch(search_value)
|
|
21
|
+
setSearchValue('')
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<View style={{ flex:1, flexDirection:'row', alignItems:'center', padding:5 }}>
|
|
26
|
+
<View style={{ flex:1, flexDirection:'row', alignItems:'center', marginRight:10, borderWidth:1, borderRadius:8, borderColor:Colors.shades.shade400 }}>
|
|
27
|
+
<View style={{ padding:10 }}>
|
|
28
|
+
<Icons.SearchIcon size={12} color={Colors.brand.midnight} />
|
|
29
|
+
</View>
|
|
30
|
+
<TextInput
|
|
31
|
+
placeholder={placeholder ?? 'Search'}
|
|
32
|
+
value={search_value}
|
|
33
|
+
placeholderTextColor={Colors.shades.shade400}
|
|
34
|
+
style={{ flex:1, padding:10, color:Colors.brand.midnight, fontFamily: 'barlow-semibold', fontSize:14 }}
|
|
35
|
+
onChangeText={(text) => {
|
|
36
|
+
setSearchValue(text)
|
|
37
|
+
if(onChange){ onChange(text) }
|
|
38
|
+
}}
|
|
39
|
+
/>
|
|
40
|
+
</View>
|
|
41
|
+
{!hide_search_button ?
|
|
42
|
+
<Button
|
|
43
|
+
title="Search"
|
|
44
|
+
title_color={Colors.shades.white}
|
|
45
|
+
backgroundColor={Colors.brand.midnight}
|
|
46
|
+
borderRadius={8}
|
|
47
|
+
onPress={() => handleSearch()}
|
|
48
|
+
/>
|
|
49
|
+
:<></>}
|
|
50
|
+
</View>
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export default SearchBox
|