From e6b36c6f7c32c261a04913ce0f7246c621ffdecc Mon Sep 17 00:00:00 2001 From: Jose Avalos Date: Mon, 7 Oct 2024 17:53:58 -0500 Subject: [PATCH] playerprop data fetching --- lib/api.ts | 12 ++++++---- .../[sport]/playerprops/[eventid]/page.tsx | 15 ------------ src/app/odds/page.tsx | 2 ++ src/app/odds/playerProps/page.tsx | 23 +++++++++++++++++++ src/components/OddsTable.tsx | 16 ++++++++++--- tsconfig.json | 10 ++++++-- 6 files changed, 53 insertions(+), 25 deletions(-) delete mode 100644 src/app/odds/[sport]/playerprops/[eventid]/page.tsx create mode 100644 src/app/odds/playerProps/page.tsx diff --git a/lib/api.ts b/lib/api.ts index 70db6a4..258fee7 100644 --- a/lib/api.ts +++ b/lib/api.ts @@ -109,15 +109,17 @@ export async function getPointOdds(sport = "upcoming") { export async function getPlayerProps( sport: string, - eventid: string, - markets = "batter_hits" + eventid: string + // markets = "batter_hits" ) { try { const odds = await fetch( - `${baseURL}/v4/sports/${sport}/events/${eventid}/odds/?apiKey=${apiKey}&markets=${markets}` + `${baseURL}/v4/sports/${sport}/events/${eventid}/odds/?apiKey=${apiKey}®ions=us&oddsFormat=american` ); - if (odds) { - return odds; + + const data = odds.json(); + if (data) { + return data ?? []; } return []; } catch (error) { diff --git a/src/app/odds/[sport]/playerprops/[eventid]/page.tsx b/src/app/odds/[sport]/playerprops/[eventid]/page.tsx deleted file mode 100644 index 28827e8..0000000 --- a/src/app/odds/[sport]/playerprops/[eventid]/page.tsx +++ /dev/null @@ -1,15 +0,0 @@ -import { Params } from "next/dist/shared/lib/router/utils/route-matcher"; -import { getPlayerProps } from "../../../../../../lib/api"; - -const playerProps = async ({ params }: { params: Params }) => { - const { sport, eventid } = params; - const props = await getPlayerProps(sport, eventid); - // const league = sport.replaceAll("_", " ").toUpperCase(); - return ( -
-

Player Props real

-
- ); -}; - -export default playerProps; diff --git a/src/app/odds/page.tsx b/src/app/odds/page.tsx index 54a0e68..f661567 100644 --- a/src/app/odds/page.tsx +++ b/src/app/odds/page.tsx @@ -7,6 +7,8 @@ import MoneyLine from "@/components/Moneyline"; async function Odds() { const odds = await getMoneyLineOdds(); + //https://api.the-odds-api.com/v4/sports/americanfootball_nfl/events/a512a48a58c4329048174217b2cc7ce0/odds?apiKey=YOUR_API_KEY®ions=us&markets=player_pass_tds&oddsFormat=american(opens new window) + if (!odds) { notFound(); } diff --git a/src/app/odds/playerProps/page.tsx b/src/app/odds/playerProps/page.tsx new file mode 100644 index 0000000..f8db31c --- /dev/null +++ b/src/app/odds/playerProps/page.tsx @@ -0,0 +1,23 @@ +import { URLSearchParams } from "url"; +import { getPlayerProps } from "../../../../lib/api"; + +interface PlayerPropsParams { + searchParams: { + sport: string; + event: string; + }; +} +const playerProps = async ({ searchParams }: PlayerPropsParams) => { + const { sport, event: eventId } = searchParams; + + const props = await getPlayerProps(sport, eventId); + + console.log(props); + return ( +
+

Player Props real

+
+ ); +}; + +export default playerProps; diff --git a/src/components/OddsTable.tsx b/src/components/OddsTable.tsx index 49330bd..b8db77c 100644 --- a/src/components/OddsTable.tsx +++ b/src/components/OddsTable.tsx @@ -1,6 +1,7 @@ "use client"; import { ReactNode } from "react"; import { Odds } from "../../lib/api"; +import Link from "next/link"; function OddsTable({ oddsItem, home, away, points, draw }: OddsTableProps) { const { away_team, bookmakers, home_team } = oddsItem; @@ -12,9 +13,18 @@ function OddsTable({ oddsItem, home, away, points, draw }: OddsTableProps) { if (!points) { return (
-

- {home_team} vs {away_team} -

+
+

+ {home_team} vs {away_team} +

+ + Player Props + +
+

{startTime}

{home_team} diff --git a/tsconfig.json b/tsconfig.json index fe4a7fa..ec467d2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -23,7 +23,13 @@ "@/*": ["./src/*"] } }, - "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "src/app/odds/[sport]/playerprops"], + "include": [ + "next-env.d.ts", + "**/*.ts", + "**/*.tsx", + ".next/types/**/*.ts", + "src/app/odds/playerProps" + ], "exclude": ["node_modules"], - "baseUrl": "http://localhost:3000", + "baseUrl": "http://localhost:3000" }