be-components 1.1.9 → 1.2.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.
- package/lib/commonjs/Squares/api/index.js +55 -1
- package/lib/commonjs/Squares/api/index.js.map +1 -1
- package/lib/commonjs/Squares/components/EventCard.js +1 -1
- package/lib/commonjs/Squares/components/EventCard.js.map +1 -1
- package/lib/commonjs/Squares/components/MySquaresCard.js +9 -7
- package/lib/commonjs/Squares/components/MySquaresCard.js.map +1 -1
- package/lib/commonjs/Squares/components/MyStatsCard.js +1 -1
- package/lib/commonjs/Squares/components/MyStatsCard.js.map +1 -1
- package/lib/commonjs/Squares/components/SquaresBoard.js +14 -1
- package/lib/commonjs/Squares/components/SquaresBoard.js.map +1 -1
- package/lib/commonjs/Squares/index.js +49 -22
- package/lib/commonjs/Squares/index.js.map +1 -1
- package/lib/module/Squares/api/index.js +55 -1
- package/lib/module/Squares/api/index.js.map +1 -1
- package/lib/module/Squares/components/EventCard.js +1 -1
- package/lib/module/Squares/components/EventCard.js.map +1 -1
- package/lib/module/Squares/components/MySquaresCard.js +9 -7
- package/lib/module/Squares/components/MySquaresCard.js.map +1 -1
- package/lib/module/Squares/components/MyStatsCard.js +1 -1
- package/lib/module/Squares/components/MyStatsCard.js.map +1 -1
- package/lib/module/Squares/components/SquaresBoard.js +14 -1
- package/lib/module/Squares/components/SquaresBoard.js.map +1 -1
- package/lib/module/Squares/index.js +49 -22
- package/lib/module/Squares/index.js.map +1 -1
- package/lib/typescript/src/Squares/api/index.d.ts +5 -0
- package/lib/typescript/src/Squares/api/index.d.ts.map +1 -1
- package/lib/typescript/src/Squares/components/MySquaresCard.d.ts.map +1 -1
- package/lib/typescript/src/Squares/components/SquaresBoard.d.ts.map +1 -1
- package/lib/typescript/src/Squares/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Squares/api/index.ts +42 -1
- package/src/Squares/components/EventCard.tsx +1 -1
- package/src/Squares/components/MySquaresCard.tsx +10 -8
- package/src/Squares/components/MyStatsCard.tsx +1 -1
- package/src/Squares/components/SquaresBoard.tsx +6 -0
- package/src/Squares/index.tsx +41 -18
package/src/Squares/index.tsx
CHANGED
|
@@ -32,6 +32,9 @@ const SquaresModule = ({ sq_comp_id, player_id, distinct_id, onRequestAuthentica
|
|
|
32
32
|
const [ needs_reload, setNeedsReload ] = useState(false);
|
|
33
33
|
const [ module_size, setModuleSize ] = useState({ width:0, height:0 })
|
|
34
34
|
const [ bid_form_expanded, setBidFormExpanded ] = useState(false);
|
|
35
|
+
const [ updated_from_bid, setUpdatedFromBid ]= useState<BuySquaresResponseProps>();
|
|
36
|
+
const [ updated_from_offer, setUpdatedFromOffer ]= useState<OfferResponseProps>();
|
|
37
|
+
|
|
35
38
|
const [ module_data, setModuleData ] = useState<{
|
|
36
39
|
loading:boolean,
|
|
37
40
|
loaded:boolean,
|
|
@@ -69,8 +72,7 @@ const SquaresModule = ({ sq_comp_id, player_id, distinct_id, onRequestAuthentica
|
|
|
69
72
|
const { square_bids, draft_square_offers, submit_ready } = board_data;
|
|
70
73
|
const { loading, league, event, players, loaded, squares_competition, squares, squares_type, squares_payout_type, square_results, square_offers, player_square_history, player_squares } = module_data;
|
|
71
74
|
|
|
72
|
-
const squares_expected_value = SqauresHelpers.getMyExpectedValue(squares, player_squares.filter(ps => ps.status == 'active' && ps.player_id == player_id), squares_competition, player_id)
|
|
73
|
-
|
|
75
|
+
const squares_expected_value = SqauresHelpers.getMyExpectedValue(squares, [ ...player_squares.filter(ps => ps.status == 'active' && ps.player_id == player_id) ], squares_competition, player_id)
|
|
74
76
|
const my_squares = player_squares.filter(ps => ps.status == 'active' && ps.player_id == player_id);
|
|
75
77
|
const home_abbr = event?.home?.abbr??squares_competition?.event_backup?.home?.abbr
|
|
76
78
|
const away_abbr = event?.away?.abbr??squares_competition?.event_backup?.away?.abbr
|
|
@@ -82,8 +84,18 @@ const SquaresModule = ({ sq_comp_id, player_id, distinct_id, onRequestAuthentica
|
|
|
82
84
|
getDataFromServer(sq_comp_id);
|
|
83
85
|
},[sq_comp_id])
|
|
84
86
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if(!updated_from_bid?.squares_competition){ return }
|
|
89
|
+
handleUpdateBoardFromBuy(updated_from_bid)
|
|
90
|
+
},[updated_from_bid])
|
|
91
|
+
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
if(!updated_from_offer?.squares_competition){ return }
|
|
94
|
+
handleUpdateBoardFromOffer(updated_from_offer)
|
|
95
|
+
},[updated_from_offer])
|
|
96
|
+
|
|
97
|
+
const getDataFromServer = async(sq_comp_id:string, options?:any) => {
|
|
98
|
+
if(!options || !options.ignore_load){ setModuleData({ ...module_data, loading: true }) }
|
|
87
99
|
const d = await SquaresApi.getSquareCompetitionById(sq_comp_id);
|
|
88
100
|
const evs = await SquaresApi.getEventsByEventIds([d.squares_competition.event_id]);
|
|
89
101
|
const league_id = evs[0]?.league_id
|
|
@@ -106,7 +118,7 @@ const SquaresModule = ({ sq_comp_id, player_id, distinct_id, onRequestAuthentica
|
|
|
106
118
|
players:ps,
|
|
107
119
|
square_offers: d.square_offers,
|
|
108
120
|
square_results: d.square_results,
|
|
109
|
-
player_squares:d.player_squares,
|
|
121
|
+
player_squares:d.player_squares.filter(ps => ps.status == 'active'),
|
|
110
122
|
player_square_history: d.player_square_history
|
|
111
123
|
})
|
|
112
124
|
}
|
|
@@ -126,8 +138,8 @@ const SquaresModule = ({ sq_comp_id, player_id, distinct_id, onRequestAuthentica
|
|
|
126
138
|
if(submit_ready.is_loading){ return } //Prevent button mashing
|
|
127
139
|
//SUBMIT BIDS!
|
|
128
140
|
setBoardData({ ...board_data, submit_ready: { ...submit_ready, is_loading:true } })
|
|
129
|
-
|
|
130
|
-
if(needs_reload){ handleUpdateBoardFromBuy(resp) } //If we somehow got disconnected from the socket, we need to load it
|
|
141
|
+
await SquaresApi.buySquares(squares_competition.sq_comp_id, square_bids)
|
|
142
|
+
//if(needs_reload){ handleUpdateBoardFromBuy(resp) } //If we somehow got disconnected from the socket, we need to load it
|
|
131
143
|
setBoardData({ ...board_data, square_bids:[], submit_ready:{ is_loading: false, is_ready: false } })
|
|
132
144
|
setBidFormExpanded(false);
|
|
133
145
|
}
|
|
@@ -145,8 +157,8 @@ const SquaresModule = ({ sq_comp_id, player_id, distinct_id, onRequestAuthentica
|
|
|
145
157
|
//SUBMIT BIDS!
|
|
146
158
|
|
|
147
159
|
setBoardData({ ...board_data, submit_ready: { ...submit_ready, is_loading:true } })
|
|
148
|
-
|
|
149
|
-
if(needs_reload){ handleUpdateBoardFromOffer(resp) } //If we somehow got disconnected from the socket, we need to load it
|
|
160
|
+
await SquaresApi.offserSquare(draft_square_offers[0])
|
|
161
|
+
//if(needs_reload){ handleUpdateBoardFromOffer(resp) } //If we somehow got disconnected from the socket, we need to load it
|
|
150
162
|
setBoardData({ ...board_data, draft_square_offers:[], submit_ready:{ is_loading: false, is_ready: false } })
|
|
151
163
|
}
|
|
152
164
|
|
|
@@ -228,21 +240,32 @@ const SquaresModule = ({ sq_comp_id, player_id, distinct_id, onRequestAuthentica
|
|
|
228
240
|
}
|
|
229
241
|
|
|
230
242
|
const handleUpdateBoardFromOffer = (data:OfferResponseProps) => {
|
|
231
|
-
|
|
243
|
+
//First remove squares
|
|
244
|
+
//let new_ps = player_squares.filter(ps => !data.removed_player_squares.find(nps => nps.sq_player_square_id == ps.sq_player_square_id))
|
|
245
|
+
//Now update squares
|
|
246
|
+
let new_ps = SqauresHelpers.updatePlayerSquaresWithSavedSquares([ ...player_squares ], data.saved_player_squares)
|
|
247
|
+
new_ps = SqauresHelpers.updatePlayerSquaresWithRemovedSquares(new_ps, data.removed_player_squares);
|
|
232
248
|
setModuleData({
|
|
233
249
|
...module_data,
|
|
234
|
-
|
|
235
|
-
|
|
250
|
+
squares_competition: data.squares_competition ? data.squares_competition : squares_competition,
|
|
251
|
+
player_squares: new_ps,
|
|
252
|
+
square_offers: SqauresHelpers.updateSquareOffersWithUpdatedOffers(square_offers, data.updated_offers)
|
|
236
253
|
})
|
|
237
254
|
}
|
|
238
255
|
|
|
239
256
|
const handleUpdateBoardFromBuy = (data:BuySquaresResponseProps) => {
|
|
240
|
-
|
|
257
|
+
//First remove squares
|
|
258
|
+
//Now update squares
|
|
259
|
+
let new_ps = SqauresHelpers.updatePlayerSquaresWithSavedSquares([ ...player_squares ], data.saved_player_squares)
|
|
260
|
+
new_ps = SqauresHelpers.updatePlayerSquaresWithRemovedSquares(new_ps, data.removed_player_squares);
|
|
261
|
+
let new_sq = SqauresHelpers.updateSquaresWithUpdatedSquares([ ...squares], data.updated_squares)
|
|
262
|
+
let new_ps_his = SqauresHelpers.updatePlayerSquareHistoryWithRemovedSquares([ ...player_square_history], data.removed_player_squares);
|
|
241
263
|
setModuleData({
|
|
242
264
|
...module_data,
|
|
243
265
|
squares_competition: data.squares_competition,
|
|
244
|
-
squares:
|
|
245
|
-
player_squares:
|
|
266
|
+
squares: new_sq,
|
|
267
|
+
player_squares: new_ps,
|
|
268
|
+
player_square_history: new_ps_his
|
|
246
269
|
})
|
|
247
270
|
}
|
|
248
271
|
|
|
@@ -371,7 +394,7 @@ const SquaresModule = ({ sq_comp_id, player_id, distinct_id, onRequestAuthentica
|
|
|
371
394
|
onConnect={() => {
|
|
372
395
|
if(needs_reload){
|
|
373
396
|
setNeedsReload(false);
|
|
374
|
-
getDataFromServer(sq_comp_id);
|
|
397
|
+
getDataFromServer(sq_comp_id, { ignore_load:true });
|
|
375
398
|
}
|
|
376
399
|
}}
|
|
377
400
|
onDisconnect={() => setNeedsReload(true)}
|
|
@@ -381,8 +404,8 @@ const SquaresModule = ({ sq_comp_id, player_id, distinct_id, onRequestAuthentica
|
|
|
381
404
|
case 'V1_UPDATE_SQUARE_DETAILS':
|
|
382
405
|
let data = ev.data as BuySquaresResponseProps | OfferResponseProps
|
|
383
406
|
if(!data.squares_competition || data.squares_competition.sq_comp_id != squares_competition.sq_comp_id){ break } //This isn't this competition;
|
|
384
|
-
if(ev.action == 'buy'){
|
|
385
|
-
if(ev.action == 'offer')[
|
|
407
|
+
if(ev.action == 'buy'){ setUpdatedFromBid(data as BuySquaresResponseProps) }
|
|
408
|
+
if(ev.action == 'offer')[ setUpdatedFromOffer(data as OfferResponseProps) ]
|
|
386
409
|
break;
|
|
387
410
|
default: break;
|
|
388
411
|
}
|