|
1 | 1 | import React from "react";
|
2 | 2 | import Market from "../components/Market";
|
3 | 3 | import { useParams, Link } from "react-router-dom";
|
4 |
| -import useEvent from "../hooks/useEvent"; |
5 | 4 | import formatStartTime from "../helpers/startTime";
|
6 | 5 | import OddsToggle from "../components/OddsToggle";
|
| 6 | +import { useDebounce, useEvent, useStore, useMarkets } from "../hooks/"; |
7 | 7 |
|
8 | 8 | const INITIAL_MARKETS = 10;
|
9 | 9 |
|
10 | 10 | const Event = () => {
|
11 | 11 | const { eventId } = useParams();
|
12 | 12 | const event = useEvent(eventId);
|
13 | 13 |
|
| 14 | + useMarkets(event); |
| 15 | + |
| 16 | + const allMarkets = useDebounce(useStore("markets"), 10); |
| 17 | + |
| 18 | + const orderedMarkets = React.useMemo( |
| 19 | + () => |
| 20 | + Object.values(allMarkets) |
| 21 | + .sort((a, b) => a.displayOrder > b.displayOrder) |
| 22 | + .map(({ marketId }) => marketId) |
| 23 | + .slice(0, INITIAL_MARKETS), |
| 24 | + [allMarkets] |
| 25 | + ); |
| 26 | + |
14 | 27 | if (!event) {
|
15 | 28 | return <div>Loading...</div>;
|
16 | 29 | }
|
17 | 30 |
|
18 |
| - const { markets, startTime } = event; |
| 31 | + const { startTime } = event; |
19 | 32 |
|
20 | 33 | return (
|
21 | 34 | <div className="c-full-event">
|
@@ -47,7 +60,7 @@ const Event = () => {
|
47 | 60 | <div className="c-full-event__meta-item">Request a Bet</div>
|
48 | 61 | )}
|
49 | 62 | </div>
|
50 |
| - {markets.slice(0, INITIAL_MARKETS).map(id => ( |
| 63 | + {orderedMarkets.slice(0, INITIAL_MARKETS).map(id => ( |
51 | 64 | <Market key={id} id={id} />
|
52 | 65 | ))}
|
53 | 66 | </div>
|
|
0 commit comments