be-components 1.2.9 → 1.3.1

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 (124) hide show
  1. package/lib/commonjs/Competition/api/index.js +1 -1
  2. package/lib/commonjs/Competition/api/index.js.map +1 -1
  3. package/lib/commonjs/Competition/components/CompetitionPlay.js +1 -1
  4. package/lib/commonjs/Competition/components/CompetitionPlay.js.map +1 -1
  5. package/lib/commonjs/Competition/components/MarketsCard.js.map +1 -1
  6. package/lib/commonjs/Competition/index.js +1 -1
  7. package/lib/commonjs/Competition/index.js.map +1 -1
  8. package/lib/commonjs/CompetitionManager/api/index.js +153 -35
  9. package/lib/commonjs/CompetitionManager/api/index.js.map +1 -1
  10. package/lib/commonjs/CompetitionManager/components/AthleteSelector.js +170 -0
  11. package/lib/commonjs/CompetitionManager/components/AthleteSelector.js.map +1 -0
  12. package/lib/commonjs/CompetitionManager/components/CompetitionContestsForm.js +495 -423
  13. package/lib/commonjs/CompetitionManager/components/CompetitionContestsForm.js.map +1 -1
  14. package/lib/commonjs/CompetitionManager/components/CompetitionHeader.js +134 -0
  15. package/lib/commonjs/CompetitionManager/components/CompetitionHeader.js.map +1 -0
  16. package/lib/commonjs/CompetitionManager/components/CompetitionInfoForm.js +96 -73
  17. package/lib/commonjs/CompetitionManager/components/CompetitionInfoForm.js.map +1 -1
  18. package/lib/commonjs/CompetitionManager/components/CompetitionMatchMarketCard.js +147 -127
  19. package/lib/commonjs/CompetitionManager/components/CompetitionMatchMarketCard.js.map +1 -1
  20. package/lib/commonjs/CompetitionManager/components/CompetitionSettingsForm.js +38 -127
  21. package/lib/commonjs/CompetitionManager/components/CompetitionSettingsForm.js.map +1 -1
  22. package/lib/commonjs/CompetitionManager/components/ContestSelector.js +388 -0
  23. package/lib/commonjs/CompetitionManager/components/ContestSelector.js.map +1 -0
  24. package/lib/commonjs/CompetitionManager/components/ContestSettingsForm.js +436 -0
  25. package/lib/commonjs/CompetitionManager/components/ContestSettingsForm.js.map +1 -0
  26. package/lib/commonjs/CompetitionManager/components/MarketSelector.js +36 -26
  27. package/lib/commonjs/CompetitionManager/components/MarketSelector.js.map +1 -1
  28. package/lib/commonjs/CompetitionManager/index.js +477 -18
  29. package/lib/commonjs/CompetitionManager/index.js.map +1 -1
  30. package/lib/commonjs/Components/SearchBox.js +82 -0
  31. package/lib/commonjs/Components/SearchBox.js.map +1 -0
  32. package/lib/commonjs/Squares/components/Countdown.js +74 -0
  33. package/lib/commonjs/Squares/components/Countdown.js.map +1 -0
  34. package/lib/commonjs/Squares/components/SquaresBoard.js +95 -2
  35. package/lib/commonjs/Squares/components/SquaresBoard.js.map +1 -1
  36. package/lib/commonjs/Squares/index.js +1 -0
  37. package/lib/commonjs/Squares/index.js.map +1 -1
  38. package/lib/module/Competition/api/index.js +1 -1
  39. package/lib/module/Competition/api/index.js.map +1 -1
  40. package/lib/module/Competition/components/CompetitionPlay.js +1 -1
  41. package/lib/module/Competition/components/CompetitionPlay.js.map +1 -1
  42. package/lib/module/Competition/components/MarketsCard.js.map +1 -1
  43. package/lib/module/Competition/index.js +1 -1
  44. package/lib/module/Competition/index.js.map +1 -1
  45. package/lib/module/CompetitionManager/api/index.js +153 -35
  46. package/lib/module/CompetitionManager/api/index.js.map +1 -1
  47. package/lib/module/CompetitionManager/components/AthleteSelector.js +161 -0
  48. package/lib/module/CompetitionManager/components/AthleteSelector.js.map +1 -0
  49. package/lib/module/CompetitionManager/components/CompetitionContestsForm.js +493 -425
  50. package/lib/module/CompetitionManager/components/CompetitionContestsForm.js.map +1 -1
  51. package/lib/module/CompetitionManager/components/CompetitionHeader.js +127 -0
  52. package/lib/module/CompetitionManager/components/CompetitionHeader.js.map +1 -0
  53. package/lib/module/CompetitionManager/components/CompetitionInfoForm.js +99 -76
  54. package/lib/module/CompetitionManager/components/CompetitionInfoForm.js.map +1 -1
  55. package/lib/module/CompetitionManager/components/CompetitionMatchMarketCard.js +145 -127
  56. package/lib/module/CompetitionManager/components/CompetitionMatchMarketCard.js.map +1 -1
  57. package/lib/module/CompetitionManager/components/CompetitionSettingsForm.js +39 -131
  58. package/lib/module/CompetitionManager/components/CompetitionSettingsForm.js.map +1 -1
  59. package/lib/module/CompetitionManager/components/ContestSelector.js +379 -0
  60. package/lib/module/CompetitionManager/components/ContestSelector.js.map +1 -0
  61. package/lib/module/CompetitionManager/components/ContestSettingsForm.js +428 -0
  62. package/lib/module/CompetitionManager/components/ContestSettingsForm.js.map +1 -0
  63. package/lib/module/CompetitionManager/components/MarketSelector.js +34 -26
  64. package/lib/module/CompetitionManager/components/MarketSelector.js.map +1 -1
  65. package/lib/module/CompetitionManager/index.js +478 -19
  66. package/lib/module/CompetitionManager/index.js.map +1 -1
  67. package/lib/module/Components/SearchBox.js +73 -0
  68. package/lib/module/Components/SearchBox.js.map +1 -0
  69. package/lib/module/Squares/components/Countdown.js +65 -0
  70. package/lib/module/Squares/components/Countdown.js.map +1 -0
  71. package/lib/module/Squares/components/SquaresBoard.js +97 -4
  72. package/lib/module/Squares/components/SquaresBoard.js.map +1 -1
  73. package/lib/module/Squares/index.js +1 -0
  74. package/lib/module/Squares/index.js.map +1 -1
  75. package/lib/typescript/src/CompetitionManager/api/index.d.ts +32 -3
  76. package/lib/typescript/src/CompetitionManager/api/index.d.ts.map +1 -1
  77. package/lib/typescript/src/CompetitionManager/components/AthleteSelector.d.ts +18 -0
  78. package/lib/typescript/src/CompetitionManager/components/AthleteSelector.d.ts.map +1 -0
  79. package/lib/typescript/src/CompetitionManager/components/CompetitionContestsForm.d.ts +13 -1
  80. package/lib/typescript/src/CompetitionManager/components/CompetitionContestsForm.d.ts.map +1 -1
  81. package/lib/typescript/src/CompetitionManager/components/CompetitionHeader.d.ts +20 -0
  82. package/lib/typescript/src/CompetitionManager/components/CompetitionHeader.d.ts.map +1 -0
  83. package/lib/typescript/src/CompetitionManager/components/CompetitionInfoForm.d.ts +2 -1
  84. package/lib/typescript/src/CompetitionManager/components/CompetitionInfoForm.d.ts.map +1 -1
  85. package/lib/typescript/src/CompetitionManager/components/CompetitionMatchMarketCard.d.ts +1 -1
  86. package/lib/typescript/src/CompetitionManager/components/CompetitionMatchMarketCard.d.ts.map +1 -1
  87. package/lib/typescript/src/CompetitionManager/components/CompetitionSettingsForm.d.ts +3 -3
  88. package/lib/typescript/src/CompetitionManager/components/CompetitionSettingsForm.d.ts.map +1 -1
  89. package/lib/typescript/src/CompetitionManager/components/ContestSelector.d.ts +16 -0
  90. package/lib/typescript/src/CompetitionManager/components/ContestSelector.d.ts.map +1 -0
  91. package/lib/typescript/src/CompetitionManager/components/ContestSettingsForm.d.ts +15 -0
  92. package/lib/typescript/src/CompetitionManager/components/ContestSettingsForm.d.ts.map +1 -0
  93. package/lib/typescript/src/CompetitionManager/components/MarketSelector.d.ts +3 -2
  94. package/lib/typescript/src/CompetitionManager/components/MarketSelector.d.ts.map +1 -1
  95. package/lib/typescript/src/CompetitionManager/index.d.ts +1 -1
  96. package/lib/typescript/src/CompetitionManager/index.d.ts.map +1 -1
  97. package/lib/typescript/src/Components/SearchBox.d.ts +10 -0
  98. package/lib/typescript/src/Components/SearchBox.d.ts.map +1 -0
  99. package/lib/typescript/src/Squares/components/Countdown.d.ts +10 -0
  100. package/lib/typescript/src/Squares/components/Countdown.d.ts.map +1 -0
  101. package/lib/typescript/src/Squares/components/SquaresBoard.d.ts +2 -1
  102. package/lib/typescript/src/Squares/components/SquaresBoard.d.ts.map +1 -1
  103. package/lib/typescript/src/Squares/index.d.ts.map +1 -1
  104. package/package.json +2 -1
  105. package/src/Competition/api/index.ts +3 -3
  106. package/src/Competition/components/CompetitionPlay.tsx +1 -1
  107. package/src/Competition/components/MarketsCard.tsx +2 -2
  108. package/src/Competition/index.tsx +1 -1
  109. package/src/CompetitionManager/api/index.ts +71 -13
  110. package/src/CompetitionManager/components/AthleteSelector.tsx +127 -0
  111. package/src/CompetitionManager/components/CompetitionContestsForm.tsx +156 -261
  112. package/src/CompetitionManager/components/CompetitionHeader.tsx +101 -0
  113. package/src/CompetitionManager/components/CompetitionInfoForm.tsx +57 -45
  114. package/src/CompetitionManager/components/CompetitionMatchMarketCard.tsx +29 -70
  115. package/src/CompetitionManager/components/CompetitionSettingsForm.tsx +36 -103
  116. package/src/CompetitionManager/components/ContestSelector.tsx +269 -0
  117. package/src/CompetitionManager/components/ContestSettingsForm.tsx +281 -0
  118. package/src/CompetitionManager/components/MarketSelector.tsx +34 -23
  119. package/src/CompetitionManager/index.tsx +399 -15
  120. package/src/Components/SearchBox.tsx +54 -0
  121. package/src/Squares/components/Countdown.tsx +52 -0
  122. package/src/Squares/components/SquaresBoard.tsx +57 -5
  123. package/src/Squares/index.tsx +1 -0
  124. package/src/types.d.ts +38 -4
@@ -12,20 +12,35 @@ var _colors = _interopRequireDefault(require("../constants/colors"));
12
12
  var _api = require("./api");
13
13
  var _CompetitionSettingsForm = _interopRequireDefault(require("./components/CompetitionSettingsForm"));
14
14
  var _CompetitionContestsForm = _interopRequireDefault(require("./components/CompetitionContestsForm"));
15
+ var _ContestSelector = _interopRequireDefault(require("./components/ContestSelector"));
16
+ var _MarketSelector = _interopRequireDefault(require("./components/MarketSelector"));
17
+ var _AthleteSelector = _interopRequireDefault(require("./components/AthleteSelector"));
18
+ var _ContestSettingsForm = _interopRequireDefault(require("./components/ContestSettingsForm"));
19
+ var _CompetitionHeader = _interopRequireDefault(require("./components/CompetitionHeader"));
15
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
21
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
17
22
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
18
23
  const CompetitionManager = ({
24
+ player_id,
19
25
  competition_id
20
26
  }) => {
21
27
  const [module_size, setModuleSize] = (0, _react.useState)({
22
28
  height: 0,
23
29
  width: 0
24
30
  });
31
+ const [action_loading, setActionLoading] = (0, _react.useState)(false);
32
+ const [show_athletes, setShowAthletes] = (0, _react.useState)({
33
+ filtered_positions: []
34
+ });
35
+ const [show_contests, setShowContests] = (0, _react.useState)({
36
+ visible: false
37
+ });
38
+ const [show_markets, setShowMarkets] = (0, _react.useState)({});
25
39
  const [competition_data, setCompetitionData] = (0, _react.useState)({
26
40
  loaded: false,
27
41
  loading: false,
28
42
  competition_result_types: [],
43
+ competition_summaries: [],
29
44
  competition_types: [],
30
45
  competition_matches: [],
31
46
  competition_payout_types: [],
@@ -33,15 +48,21 @@ const CompetitionManager = ({
33
48
  markets: [],
34
49
  leagues: [],
35
50
  events: [],
51
+ trades: [],
36
52
  tournaments: [],
37
53
  matches: [],
38
54
  teams: [],
39
55
  athletes: []
40
56
  });
57
+ const {
58
+ contest_id,
59
+ contest_type
60
+ } = show_markets;
41
61
  const {
42
62
  loaded,
43
63
  competition,
44
64
  competition_result_types,
65
+ trades,
45
66
  competition_types,
46
67
  draft_competition,
47
68
  competition_matches,
@@ -54,6 +75,44 @@ const CompetitionManager = ({
54
75
  teams,
55
76
  athletes
56
77
  } = competition_data;
78
+
79
+ //Market Selector Stuff
80
+ const showing_market_event = events.find(e => e.event_id == contest_id && contest_type == 'team');
81
+ const showing_market_event_matches = competition_matches.filter(cm => cm.event_type == 'team' && cm.event_id == contest_id);
82
+ 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));
83
+ const show_market_id_overrides = showing_market_event_matches.filter(cm => cm.market_id_override).map(cm => cm.market_id_override ?? '0');
84
+
85
+ //AthleteSelectorStuff
86
+ 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);
87
+ const selected_athletes = select_athlete_matches.filter(m => m.side_type_override == 'athlete').map(m => m.side_id_override ?? '0');
88
+ const select_athlete_event = events.find(e => show_athletes.contest_type == 'team' && e.event_id == show_athletes.contest_id);
89
+ const select_athlete_positions = markets.find(m => m.market_id == show_athletes.market_id)?.supported_positions ?? [];
90
+ //Filter Athletes to those with trades
91
+ 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))];
92
+
93
+ //Lets figure out if we can add / remove a primary market for all of them
94
+ let primary_markets = [];
95
+ events.map(e => {
96
+ if (!e.supported_markets) {
97
+ return;
98
+ }
99
+ e.supported_markets.map(sm => {
100
+ let market = markets.find(m => m.market_id == sm.market_id);
101
+ if (!market?.primary_market) {
102
+ return;
103
+ }
104
+ let exists = primary_markets.find(pm => pm.market.market_id == sm.market_id);
105
+ if (!exists) {
106
+ //check if this has been included or not!
107
+ let included = competition_match_markets.find(cmm => cmm.market_id == market.market_id) ? true : false;
108
+ primary_markets.push({
109
+ market,
110
+ included
111
+ });
112
+ }
113
+ });
114
+ });
115
+ const competition_valid = _api.ManageCompetitionHelpers.isCompetitionValid(competition_types, competition_result_types, competition_matches, competition_match_markets, events, competition);
57
116
  (0, _react.useEffect)(() => {
58
117
  if (!loaded) {
59
118
  _api.ManageCompetitionApi.setEnvironment();
@@ -66,6 +125,7 @@ const CompetitionManager = ({
66
125
  const options = await _api.ManageCompetitionApi.getCompetitionOptions();
67
126
  const lgs = await _api.ManageCompetitionApi.getLeagues();
68
127
  const mks = await _api.ManageCompetitionApi.getMarkets();
128
+ const summaries = await _api.ManageCompetitionApi.getCompetitionSummaries(id);
69
129
  //Get unique contests
70
130
  let event_ids = cm_resp.competition_matches.filter(cm => cm.event_type == 'team').map(cm => cm.event_id);
71
131
  let tournament_ids = cm_resp.competition_matches.filter(cm => cm.event_type == 'tournament').map(cm => cm.event_id);
@@ -77,14 +137,17 @@ const CompetitionManager = ({
77
137
  if (event_ids.length > 0) {
78
138
  c_events = await _api.ManageCompetitionMatchApi.getEventsByEventIds(event_ids);
79
139
  }
140
+ let e_trades = await _api.ManageCompetitionMarketApi.getLatestTradesByEventIds(event_ids, 'team');
80
141
  let c_tournaments = [];
81
142
  if (tournament_ids.length > 0) {
82
143
  c_tournaments = await _api.ManageCompetitionMatchApi.getTournamentsByTournamentIds(tournament_ids);
83
144
  }
145
+ let t_trades = await _api.ManageCompetitionMarketApi.getLatestTradesByEventIds(tournament_ids, 'tournamet');
84
146
  let c_matches = [];
85
147
  if (match_ids.length > 0) {
86
148
  c_matches = await _api.ManageCompetitionMatchApi.getMatchesByMatchIds(match_ids);
87
149
  }
150
+ let m_trades = await _api.ManageCompetitionMarketApi.getLatestTradesByEventIds(match_ids, 'match');
88
151
  let c_teams = [];
89
152
  if (team_ids.length > 0) {
90
153
  c_teams = await _api.ManageCompetitionMatchApi.getTeamsByIds(team_ids);
@@ -98,6 +161,7 @@ const CompetitionManager = ({
98
161
  loading: false,
99
162
  competition: c,
100
163
  leagues: lgs,
164
+ competition_summaries: summaries,
101
165
  competition_types: options.competition_types,
102
166
  competition_payout_types: options.competition_payout_types,
103
167
  competition_result_types: options.competition_result_types,
@@ -106,13 +170,272 @@ const CompetitionManager = ({
106
170
  competition_match_markets: cm_resp.competition_match_markets,
107
171
  events: c_events,
108
172
  markets: mks,
173
+ trades: e_trades.concat(m_trades).concat(t_trades),
109
174
  tournaments: c_tournaments,
110
175
  matches: c_matches,
111
176
  teams: c_teams,
112
177
  athletes: c_athletes
113
178
  });
114
179
  };
115
- if (!competition || !draft_competition) {
180
+ const handleRemovePrimaryMarket = async market => {
181
+ setActionLoading(true);
182
+ //Grab all markets
183
+ let remove_markets = competition_match_markets.filter(cmm => cmm.market_id == market.market_id);
184
+ await _api.ManageCompetitionMatchApi.deleteCompetitionMatchMarkets(remove_markets.map(cmm => cmm.competition_match_market_id));
185
+ setCompetitionData({
186
+ ...competition_data,
187
+ competition_match_markets: competition_match_markets.filter(cmm => cmm.market_id != market.market_id)
188
+ });
189
+ setActionLoading(false);
190
+ };
191
+ const handleAddPrimaryMarket = async market => {
192
+ setActionLoading(true);
193
+ let market_cmms = [];
194
+ let primary_matches = competition_matches.filter(cm => !cm.market_id_override);
195
+ primary_matches.map(cm => {
196
+ let existing_markets = competition_match_markets.filter(cmm => cmm.competition_match_id == cm.competition_match_id && cmm.market_id == market.market_id);
197
+ if (existing_markets.length > 0) {
198
+ return;
199
+ } //Dont do anything on that one!
200
+ 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);
201
+ if (market_trades.length != 2) {
202
+ console.log(`no trades for event ${cm.event_id}`);
203
+ return;
204
+ } //This event doesnt have the trades
205
+ let new_cmms = [];
206
+ market_trades.map(t => {
207
+ new_cmms.push({
208
+ ..._api.ManageCompetitionHelpers.createCompetitionMatchMarketFromTrade(t),
209
+ competition_match_id: cm.competition_match_id
210
+ });
211
+ });
212
+ market_cmms = market_cmms.concat(new_cmms);
213
+ });
214
+ market_cmms = await _api.ManageCompetitionMatchApi.createCompetitionMatchMarkets(market_cmms);
215
+ setCompetitionData({
216
+ ...competition_data,
217
+ 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)
218
+ });
219
+ setActionLoading(false);
220
+ };
221
+ const handleSelectTeamEvents = async new_events => {
222
+ if (action_loading || !competition) {
223
+ return;
224
+ }
225
+ setActionLoading(true);
226
+ let added_matches = [];
227
+ const addEvents = new_events.map(async e => {
228
+ const cm = await _api.ManageCompetitionMatchApi.createCompetitionMatch(competition_id, e.event_id, 'team', 'event', undefined, undefined, undefined);
229
+ added_matches.push(cm);
230
+ });
231
+ await Promise.all(addEvents);
232
+ const e_trades = await _api.ManageCompetitionMarketApi.getLatestTradesByEventIds(new_events.map(e => e.event_id), 'team');
233
+ setCompetitionData({
234
+ ...competition_data,
235
+ competition: {
236
+ ...competition,
237
+ scheduled_datetime: undefined
238
+ },
239
+ competition_matches: competition_matches.concat(added_matches),
240
+ events: events.filter(e => !new_events.find(ne => ne.event_id == e.event_id)).concat(new_events),
241
+ trades: trades.filter(t => !events.map(e => e.event_id.toString()).includes(t.event_id)).concat(e_trades)
242
+ });
243
+ setActionLoading(false);
244
+ };
245
+ const handleSelectTeamEvent = async event => {
246
+ if (action_loading || !competition) {
247
+ return;
248
+ }
249
+ setActionLoading(true);
250
+ const cm = await _api.ManageCompetitionMatchApi.createCompetitionMatch(competition_id, event.event_id, 'team', 'event', undefined, undefined, undefined);
251
+ const e_trades = await _api.ManageCompetitionMarketApi.getLatestTradesByEventIds([event.event_id], 'team');
252
+ setCompetitionData({
253
+ ...competition_data,
254
+ competition: {
255
+ ...competition,
256
+ scheduled_datetime: undefined
257
+ },
258
+ competition_matches: competition_matches.concat(cm),
259
+ events: events.filter(e => e.event_id != event.event_id).concat(event),
260
+ trades: trades.filter(t => t.event_id != event.event_id).concat(e_trades)
261
+ });
262
+ setActionLoading(false);
263
+ };
264
+ const handleRemoveCompetitionMatch = async competition_match_id => {
265
+ if (action_loading) {
266
+ return;
267
+ }
268
+ setActionLoading(true);
269
+ await _api.ManageCompetitionMatchApi.deleteCompetitionMatch(competition_match_id);
270
+ setCompetitionData({
271
+ ...competition_data,
272
+ competition_matches: competition_matches.filter(cm => cm.competition_match_id != competition_match_id)
273
+ });
274
+ setActionLoading(false);
275
+ };
276
+ const handleRemoveCompetitionMatchMarkets = async cmms => {
277
+ if (action_loading) {
278
+ return;
279
+ }
280
+ setActionLoading(true);
281
+ await _api.ManageCompetitionMatchApi.deleteCompetitionMatchMarkets(cmms.map(cmm => cmm.competition_match_market_id));
282
+ setCompetitionData({
283
+ ...competition_data,
284
+ competition_match_markets: competition_match_markets.filter(cmm => !cmms.map(rmm => rmm.competition_match_market_id.toString()).includes(cmm.competition_match_market_id))
285
+ });
286
+ setActionLoading(false);
287
+ };
288
+ const handleDeselectTeamEvent = async event => {
289
+ const cms = competition_matches.filter(cm => cm.event_id == event.event_id && cm.event_type == 'team');
290
+ const deleteCMS = cms.map(async cm => {
291
+ await _api.ManageCompetitionMatchApi.deleteCompetitionMatch(cm.competition_match_id);
292
+ });
293
+ await Promise.all(deleteCMS);
294
+ setCompetitionData({
295
+ ...competition_data,
296
+ competition_matches: competition_matches.filter(cm => !cms.find(dcm => dcm.competition_match_id == cm.competition_match_id))
297
+ });
298
+ };
299
+ const handleSelectAthlete = async athlete => {
300
+ if (!show_athletes?.contest_id || !show_athletes?.contest_type) {
301
+ return;
302
+ }
303
+ 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);
304
+ if (athlete_trades.length != 2) {
305
+ return alert('Unable to add');
306
+ }
307
+ if (action_loading) {
308
+ return;
309
+ }
310
+ setActionLoading(true);
311
+ //First check if there is an existing market_id override without a side_id_override and add it!
312
+ 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);
313
+ if (existing_cm) {
314
+ existing_cm = await _api.ManageCompetitionMatchApi.updateCompetitionMatch({
315
+ ...existing_cm,
316
+ side_type_override: 'athlete',
317
+ side_id_override: athlete.athlete_id
318
+ });
319
+ } else {
320
+ console.log('CREATING NEW MATCH!!!');
321
+ existing_cm = await _api.ManageCompetitionMatchApi.createCompetitionMatch(competition_id, show_athletes.contest_id, show_athletes.contest_type, 'athlete', show_athletes.market_id, 'athlete', athlete.athlete_id);
322
+ }
323
+ let new_cmms = [];
324
+ athlete_trades.map(t => {
325
+ new_cmms.push({
326
+ ..._api.ManageCompetitionHelpers.createCompetitionMatchMarketFromTrade(t),
327
+ competition_match_id: existing_cm.competition_match_id
328
+ });
329
+ });
330
+ new_cmms = await _api.ManageCompetitionMatchApi.createCompetitionMatchMarkets(new_cmms);
331
+ setCompetitionData({
332
+ ...competition_data,
333
+ athletes: athletes.concat(athlete),
334
+ competition_matches: competition_matches.filter(cm => cm.competition_match_id != existing_cm.competition_match_id).concat(existing_cm),
335
+ 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)
336
+ });
337
+ setActionLoading(false);
338
+ };
339
+ const handleDeselectAthlete = async athlete => {
340
+ if (!show_athletes?.contest_id || !show_athletes?.contest_type || !show_athletes?.market_id) {
341
+ return;
342
+ }
343
+ let athlete_cm = competition_matches.find(cm => cm.market_id_override == show_athletes.market_id && cm.side_id_override == athlete.athlete_id);
344
+ if (!athlete_cm) {
345
+ return alert('Unable to remove');
346
+ }
347
+ if (action_loading) {
348
+ return;
349
+ }
350
+ setActionLoading(true);
351
+ let cmms = competition_match_markets.filter(cmm => cmm.competition_match_id == athlete_cm.competition_match_id);
352
+ await _api.ManageCompetitionMatchApi.deleteCompetitionMatch(athlete_cm.competition_match_id);
353
+ await _api.ManageCompetitionMatchApi.deleteCompetitionMatchMarkets(cmms.map(cmm => cmm.competition_match_id));
354
+ setCompetitionData({
355
+ ...competition_data,
356
+ competition_matches: competition_matches.filter(cm => cm.competition_match_id != athlete_cm.competition_match_id),
357
+ competition_match_markets: competition_match_markets.filter(cmm => !cmms.map(rmm => rmm.competition_match_market_id.toString()).includes(cmm.competition_match_market_id))
358
+ });
359
+ setActionLoading(false);
360
+ };
361
+ const handleRemoveMarket = async (contest_id, contest_type, market) => {
362
+ if (action_loading) {
363
+ return;
364
+ }
365
+ setActionLoading(true);
366
+ let relevant_matches = competition_matches.filter(cm => cm.event_id == contest_id && cm.event_type == contest_type);
367
+ //First remove all the non_primary if there are any
368
+ let non_primary_matches = relevant_matches.filter(cm => cm.market_id_override == market.market_id);
369
+ let matches_removed = [];
370
+ let markets_removed = [];
371
+ const rem_non_primary = non_primary_matches.map(async cm => {
372
+ const del_response = await _api.ManageCompetitionMatchApi.deleteCompetitionMatch(cm.competition_match_id);
373
+ matches_removed = matches_removed.concat(del_response.competition_match.competition_match_id);
374
+ markets_removed = markets_removed.concat(del_response.competition_match_markets.map(cmm => cmm.competition_match_market_id));
375
+ });
376
+ await Promise.all(rem_non_primary);
377
+
378
+ //Ok now lets looks for the primary market one
379
+ let primary_match = relevant_matches.find(cm => !cm.market_id_override);
380
+ if (primary_match) {
381
+ let primary_cmms = competition_match_markets.filter(cmm => cmm.competition_match_id == primary_match.competition_match_id && cmm.market_id == market.market_id);
382
+ await _api.ManageCompetitionMatchApi.deleteCompetitionMatchMarkets(primary_cmms.map(cmm => cmm.competition_match_market_id));
383
+ markets_removed = markets_removed.concat(primary_cmms.map(cmm => cmm.competition_match_market_id));
384
+ }
385
+ setCompetitionData({
386
+ ...competition_data,
387
+ competition_matches: competition_matches.filter(cm => !matches_removed.includes(cm.competition_match_id)),
388
+ competition_match_markets: competition_match_markets.filter(cmm => !markets_removed.includes(cmm.competition_match_market_id))
389
+ });
390
+ setActionLoading(false);
391
+ };
392
+ const handleAddMarket = async (contest_id, contest_type, market) => {
393
+ if (action_loading) {
394
+ return;
395
+ }
396
+ setActionLoading(true);
397
+ //First check if this is a primary market
398
+ if (market.primary_market) {
399
+ //Get the competition match that is available for it!
400
+ let primary_match = competition_matches.find(cm => cm.event_type == contest_type && cm.event_id == contest_id && !cm.market_id_override);
401
+ if (!primary_match) {
402
+ setActionLoading(false);
403
+ return alert('Unable to add this market');
404
+ }
405
+ //Now lets get the trades!!
406
+ 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);
407
+ let cmms = [];
408
+ market_trades.map(t => {
409
+ cmms.push({
410
+ ..._api.ManageCompetitionHelpers.createCompetitionMatchMarketFromTrade(t),
411
+ competition_match_id: primary_match.competition_match_id
412
+ });
413
+ });
414
+ if (cmms.length != 2) {
415
+ setActionLoading(false);
416
+ return alert('Unable to add this market');
417
+ }
418
+ const new_cmms = await _api.ManageCompetitionMatchApi.createCompetitionMatchMarkets(cmms);
419
+ setActionLoading(false);
420
+ return setCompetitionData({
421
+ ...competition_data,
422
+ 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)
423
+ });
424
+ }
425
+ //If this is not a primary market - we need to add a market_id override for the competition match!!
426
+ let existing_match = competition_matches.find(cm => cm.event_type == contest_type && cm.event_id == contest_id && cm.market_id_override == market.market_id);
427
+ if (existing_match) {
428
+ setActionLoading(false);
429
+ return alert('Already added this market!');
430
+ }
431
+ const new_cm = await _api.ManageCompetitionMatchApi.createCompetitionMatch(competition_id, contest_id, contest_type, market.level, market.market_id);
432
+ setCompetitionData({
433
+ ...competition_data,
434
+ competition_matches: competition_matches.concat(new_cm)
435
+ });
436
+ setActionLoading(false);
437
+ };
438
+ if (!competition || !draft_competition || player_id != competition.admin_id) {
116
439
  return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
117
440
  style: {
118
441
  flex: 1
@@ -126,7 +449,6 @@ const CompetitionManager = ({
126
449
  }
127
450
  }));
128
451
  }
129
- console.log(module_size);
130
452
  return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
131
453
  style: {
132
454
  flex: 1
@@ -149,40 +471,177 @@ const CompetitionManager = ({
149
471
  style: {
150
472
  ..._styles.view_styles.wrapper
151
473
  }
152
- }, /*#__PURE__*/_react.default.createElement(_CompetitionInfoForm.default, {
153
- competition: draft_competition,
474
+ }, /*#__PURE__*/_react.default.createElement(_CompetitionHeader.default, {
475
+ action_loading: action_loading,
476
+ width: module_size.width,
477
+ competition: competition,
478
+ competition_valid: competition_valid,
479
+ onActivate: async () => {
480
+ setActionLoading(true);
481
+ const new_c = await _api.ManageCompetitionApi.activateCompetition(competition_id);
482
+ setCompetitionData({
483
+ ...competition_data,
484
+ competition: new_c
485
+ });
486
+ setActionLoading(false);
487
+ },
488
+ onPause: async () => {
489
+ setActionLoading(true);
490
+ const new_c = await _api.ManageCompetitionApi.pauseCompetition(competition_id);
491
+ const new_summaries = await _api.ManageCompetitionApi.getCompetitionSummaries(competition_id);
492
+ setCompetitionData({
493
+ ...competition_data,
494
+ competition: new_c,
495
+ competition_summaries: new_summaries
496
+ });
497
+ setActionLoading(false);
498
+ },
499
+ onResume: async () => {
500
+ setActionLoading(true);
501
+ const new_c = await _api.ManageCompetitionApi.resumeCompetition(competition_id);
502
+ setCompetitionData({
503
+ ...competition_data,
504
+ competition: new_c
505
+ });
506
+ setActionLoading(false);
507
+ }
508
+ }), /*#__PURE__*/_react.default.createElement(_CompetitionInfoForm.default, {
509
+ is_valid: competition_valid.info,
510
+ competition: competition,
154
511
  width: module_size.width - 20,
155
- onCompetitionUpdate: comp => setCompetitionData({
156
- ...competition_data,
157
- draft_competition: comp
158
- })
512
+ onCompetitionUpdate: async comp => {
513
+ const new_c = await _api.ManageCompetitionApi.updateCompetition(comp);
514
+ setCompetitionData({
515
+ ...competition_data,
516
+ competition: new_c
517
+ });
518
+ }
159
519
  }), /*#__PURE__*/_react.default.createElement(_CompetitionSettingsForm.default, {
160
- competition: draft_competition,
520
+ is_valid: competition_valid.settings,
521
+ competition: competition,
161
522
  width: module_size.width - 20,
162
523
  competition_result_types: competition_result_types,
163
- competition_types: competition_types,
164
- onCompetitionUpdate: comp => setCompetitionData({
165
- ...competition_data,
166
- draft_competition: comp
167
- })
524
+ onCompetitionUpdate: async comp => {
525
+ const new_c = await _api.ManageCompetitionApi.updateCompetition(comp);
526
+ setCompetitionData({
527
+ ...competition_data,
528
+ competition: new_c
529
+ });
530
+ }
168
531
  }), /*#__PURE__*/_react.default.createElement(_CompetitionContestsForm.default, {
532
+ action_loading: action_loading,
533
+ is_valid: competition_valid.contests,
169
534
  width: module_size.width - 20,
170
- competition: draft_competition,
535
+ competition: competition,
171
536
  competition_matches: competition_matches,
172
537
  competition_match_markets: competition_match_markets,
173
538
  events: events,
539
+ primary_markets: primary_markets,
174
540
  teams: teams,
175
541
  athletes: athletes,
176
542
  tournaments: tournaments,
543
+ onAddPrimaryMarket: market => handleAddPrimaryMarket(market),
544
+ onRemovePrimaryMarket: market => handleRemovePrimaryMarket(market),
177
545
  matches: matches,
178
546
  leagues: leagues,
179
547
  markets: markets,
548
+ onDeleteMarket: (contest_id, contest_type, market) => handleRemoveMarket(contest_id, contest_type, market),
549
+ onShowAthletes: (contest_id, contest_type, market_id) => setShowAthletes({
550
+ contest_id,
551
+ contest_type,
552
+ market_id,
553
+ filtered_positions: []
554
+ }),
555
+ onShowMarkets: (contest_id, contest_type) => setShowMarkets({
556
+ contest_id,
557
+ contest_type
558
+ }),
559
+ onShowContests: () => setShowContests({
560
+ visible: true
561
+ }),
180
562
  onSaveCompetitionMatch: () => console.log('SAVE EVENT'),
181
- onDeleteCompetitionMatch: () => console.log('DELEVE'),
563
+ onDeleteCompetitionMatch: competition_match_id => handleRemoveCompetitionMatch(competition_match_id),
182
564
  onUpdateCompetitionMatch: () => console.log('UPDATE'),
183
565
  onSaveCompetitionMatchMarkets: smms => console.log(smms),
184
- onDeleteCompetitionMatchMarkets: cmms => console.log(cmms)
185
- }))));
566
+ onDeleteCompetitionMatchMarkets: cmms => handleRemoveCompetitionMatchMarkets(cmms)
567
+ }), /*#__PURE__*/_react.default.createElement(_ContestSettingsForm.default, {
568
+ is_valid: competition_valid.contest_settings,
569
+ width: module_size.width - 20,
570
+ competition: competition,
571
+ competition_matches: competition_matches,
572
+ competition_match_markets: competition_match_markets,
573
+ competition_types: competition_types,
574
+ events: events,
575
+ onCompetitionUpdate: async c => {
576
+ const new_c = await _api.ManageCompetitionApi.updateCompetition(c);
577
+ setCompetitionData({
578
+ ...competition_data,
579
+ competition: new_c
580
+ });
581
+ }
582
+ }))), show_contests.visible ? /*#__PURE__*/_react.default.createElement(_reactNative.View, {
583
+ style: {
584
+ position: 'absolute',
585
+ top: 0,
586
+ left: 0,
587
+ right: 0,
588
+ bottom: 0,
589
+ backgroundColor: _colors.default.shades.black_faded,
590
+ justifyContent: 'flex-end'
591
+ }
592
+ }, /*#__PURE__*/_react.default.createElement(_ContestSelector.default, {
593
+ action_loading: action_loading,
594
+ height: module_size.height,
595
+ width: module_size.width,
596
+ leagues: leagues,
597
+ onClose: () => setShowContests({
598
+ visible: false
599
+ }),
600
+ onSelectTeamEvent: event => handleSelectTeamEvent(event),
601
+ onSelectTeamEvents: events => handleSelectTeamEvents(events),
602
+ onDeselectTeamEvent: event => handleDeselectTeamEvent(event),
603
+ 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()))
604
+ })) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null), show_athletes.contest_id ? /*#__PURE__*/_react.default.createElement(_reactNative.View, {
605
+ style: {
606
+ position: 'absolute',
607
+ top: 0,
608
+ left: 0,
609
+ right: 0,
610
+ bottom: 0,
611
+ backgroundColor: _colors.default.shades.black_faded,
612
+ justifyContent: 'flex-end'
613
+ }
614
+ }, /*#__PURE__*/_react.default.createElement(_AthleteSelector.default, {
615
+ width: module_size.width,
616
+ height: module_size.height,
617
+ event: select_athlete_event,
618
+ selected_athletes: selected_athletes,
619
+ filtered_positions: select_athlete_positions,
620
+ filtered_athletes: trade_athletes,
621
+ onSelectAthlete: athlete => handleSelectAthlete(athlete),
622
+ onDeselectAthlete: athlete => handleDeselectAthlete(athlete),
623
+ onClose: () => setShowAthletes({
624
+ filtered_positions: []
625
+ })
626
+ })) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null), show_markets.contest_id && show_markets.contest_type && showing_market_event ? /*#__PURE__*/_react.default.createElement(_reactNative.View, {
627
+ style: {
628
+ position: 'absolute',
629
+ top: 0,
630
+ left: 0,
631
+ right: 0,
632
+ bottom: 0,
633
+ backgroundColor: _colors.default.shades.black_faded,
634
+ justifyContent: 'flex-end'
635
+ }
636
+ }, /*#__PURE__*/_react.default.createElement(_MarketSelector.default, {
637
+ height: module_size.height,
638
+ width: module_size.width,
639
+ markets: markets.filter(m => showing_market_event.supported_markets?.map(m => m.market_id.toString()).includes(m.market_id.toString())),
640
+ onClose: () => setShowMarkets({}),
641
+ onDeselectMarket: market => handleRemoveMarket(show_markets.contest_id ?? '0', show_markets.contest_type ?? 'team', market),
642
+ onSelectMarket: market => handleAddMarket(show_markets.contest_id ?? '0', show_markets.contest_type ?? 'team', market),
643
+ selected_markets: [...new Set(show_market_markets.map(cmm => cmm.market_id).concat(show_market_id_overrides))]
644
+ })) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null));
186
645
  };
187
646
  var _default = exports.default = CompetitionManager;
188
647
  //# sourceMappingURL=index.js.map