diff --git a/package.json b/package.json index 42d768c..bd7f8b3 100644 --- a/package.json +++ b/package.json @@ -11,25 +11,25 @@ "preview": "vite preview" }, "dependencies": { - "@tailwindcss/vite": "^4.1.4", - "lucide-react": "^0.488.0", - "react": "^19.0.0", - "react-dom": "^19.0.0", - "react-router-dom": "^7.6.2", - "tailwindcss": "^4.1.4" + "@tailwindcss/vite": "4.1.4", + "lucide-react": "0.488.0", + "react": "19.0.0", + "react-dom": "19.0.0", + "react-router-dom": "7.6.2", + "tailwindcss": "4.1.4" }, "devDependencies": { - "@eslint/js": "^9.22.0", - "@types/react": "^19.0.10", - "@types/react-dom": "^19.0.4", - "@vitejs/plugin-react": "^4.3.4", - "eslint": "^9.22.0", - "eslint-plugin-react-hooks": "^5.2.0", - "eslint-plugin-react-refresh": "^0.4.19", - "globals": "^16.0.0", - "prettier": "^3.5.3", - "typescript": "~5.7.2", - "typescript-eslint": "^8.26.1", - "vite": "^6.3.1" + "@eslint/js": "9.22.0", + "@types/react": "19.0.10", + "@types/react-dom": "19.0.4", + "@vitejs/plugin-react": "4.3.4", + "eslint": "9.22.0", + "eslint-plugin-react-hooks": "5.2.0", + "eslint-plugin-react-refresh": "0.4.19", + "globals": "16.0.0", + "prettier": "3.5.3", + "typescript": "5.7.2", + "typescript-eslint": "8.26.1", + "vite": "6.3.1" } -} +} \ No newline at end of file diff --git a/src/components/FantasyStatus.tsx b/src/components/FantasyStatus.tsx index ac2cad5..61873f5 100644 --- a/src/components/FantasyStatus.tsx +++ b/src/components/FantasyStatus.tsx @@ -1,50 +1,27 @@ import { useEffect, useState } from "react"; import PlayerCell from "./fantasy/PlayerCell"; -import { - NFLMatchupState, - SleeperUser, - type NFLRosterState, - type NFLState, -} from "../utils/types"; +import { type NFLAPIData, type NFLMatchupState } from "../utils/types"; export default function FantasyStatus() { - const USER_ID = "1263620186439696384"; - const OPP_USER_ID = "1032518341627600896"; - const LEAGUE_BASE_URL = - "https://api.sleeper.app/v1/league/1263620000418119680/rosters"; - const NFL_STATE_URL = "https://api.sleeper.app/v1/state/nfl"; - const MATCHUPS_URL = - "https://api.sleeper.app/v1/league/1263620000418119680/matchups/"; - const LEAGUE_USERS = - "https://api.sleeper.app/v1/league/1263620000418119680/users"; const PLAYERS_URL = "https://api.alexav.gg/v4/football/players"; - const [personalRoster, setPersonalRoster] = useState( + const [personalRoster, setPersonalRoster] = useState( null ); - const [opposingRoster, setOpposingRoster] = useState( + const [opposingRoster, setOpposingRoster] = useState( null ); // fetch roster information useEffect(() => { async function fetchData() { - const nflState = (await fetch(NFL_STATE_URL).then((res) => - res.json() - )) as NFLState; - const rosters = (await fetch(LEAGUE_BASE_URL).then((res) => - res.json() - )) as NFLRosterState[]; - const matchups = (await fetch(MATCHUPS_URL + nflState.week).then((res) => - res.json() - )) as NFLMatchupState[]; - const users = (await fetch(LEAGUE_USERS).then((res) => - res.json() - )) as SleeperUser[]; + const data = (await fetch("https://api.alexav.gg/v4/football/data").then( + (res) => res.json() + )) as NFLAPIData; // rosters - const ownMatchup = matchups[1]; - const oppMatchup = matchups[0]; + const ownMatchup = data.matchups[1] as NFLMatchupState; + const oppMatchup = data.matchups[0] as NFLMatchupState; const ownMatchupPlayers = await fetch( PLAYERS_URL + "?players=" + ownMatchup.starters @@ -54,16 +31,14 @@ export default function FantasyStatus() { ).then((res) => res.json()); setPersonalRoster({ - ...rosters.filter((v) => v.owner_id === USER_ID)[0], - matchup: matchups[1], - players: ownMatchupPlayers.playerInfo, - user: users[1], + ...ownMatchup, + playerInfo: ownMatchupPlayers.playerInfo, + owner: data.users[1], }); setOpposingRoster({ - ...rosters.filter((v) => v.owner_id === OPP_USER_ID)[0], - matchup: matchups[0], - players: oppMatchupPlayers.playerInfo, - user: users[0], + ...oppMatchup, + playerInfo: oppMatchupPlayers.playerInfo, + owner: data.users[0], }); } @@ -84,19 +59,19 @@ export default function FantasyStatus() {

- {personalRoster?.user.metadata.team_name} |{" "} - {personalRoster?.matchup.points} + {personalRoster?.owner.metadata.team_name} |{" "} + {personalRoster?.points}

- {personalRoster?.players?.map((v, k) => { + {personalRoster?.playerInfo?.map((v, k) => { return (
- +
); })} @@ -106,19 +81,19 @@ export default function FantasyStatus() {

- {opposingRoster?.user.metadata.team_name} |{" "} - {opposingRoster?.matchup.points} + {opposingRoster?.owner.metadata.team_name} |{" "} + {opposingRoster?.points}

- {opposingRoster?.players?.map((v, k) => { + {opposingRoster?.playerInfo?.map((v, k) => { return (
- +
); })} diff --git a/src/utils/types.ts b/src/utils/types.ts index 02aa2f1..fbdb4cc 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -13,25 +13,25 @@ type LastFMImageObject = { }; // nfl stuff +interface NFLAPIData { + nflState: NFLState; + matchups: NFLMatchupState[]; + users: SleeperUser[]; +} +interface NFLMatchupState { + owner: SleeperUser; + points: number; + players: string[]; + playerInfo: NFLPlayer[]; + starters: string[]; + starters_points: number[]; + players_points: object; +} interface NFLState { week: number; season_type: "pre" | "post" | "regular"; display_week: number; } -interface NFLRosterState { - league_id: string; - owner_id: string; - matchup: NFLMatchupState; - players: NFLPlayer[]; - user: SleeperUser; -} -interface NFLMatchupState { - points: number; - players: string[]; - starters: string[]; - starters_points: number[]; - players_points: object; -} interface NFLPlayer { last_name: string; injury_status: string | null; @@ -53,8 +53,8 @@ export type { LastFMMusicObject, LastFMImageObject, NFLState, - NFLRosterState, - NFLPlayer, NFLMatchupState, SleeperUser, + NFLAPIData, + NFLPlayer, };