move to single endpoint

This commit is contained in:
2025-09-08 20:41:12 -04:00
parent 2103e786bc
commit fc5b3b5b43
3 changed files with 59 additions and 84 deletions
+18 -18
View File
@@ -11,25 +11,25 @@
"preview": "vite preview" "preview": "vite preview"
}, },
"dependencies": { "dependencies": {
"@tailwindcss/vite": "^4.1.4", "@tailwindcss/vite": "4.1.4",
"lucide-react": "^0.488.0", "lucide-react": "0.488.0",
"react": "^19.0.0", "react": "19.0.0",
"react-dom": "^19.0.0", "react-dom": "19.0.0",
"react-router-dom": "^7.6.2", "react-router-dom": "7.6.2",
"tailwindcss": "^4.1.4" "tailwindcss": "4.1.4"
}, },
"devDependencies": { "devDependencies": {
"@eslint/js": "^9.22.0", "@eslint/js": "9.22.0",
"@types/react": "^19.0.10", "@types/react": "19.0.10",
"@types/react-dom": "^19.0.4", "@types/react-dom": "19.0.4",
"@vitejs/plugin-react": "^4.3.4", "@vitejs/plugin-react": "4.3.4",
"eslint": "^9.22.0", "eslint": "9.22.0",
"eslint-plugin-react-hooks": "^5.2.0", "eslint-plugin-react-hooks": "5.2.0",
"eslint-plugin-react-refresh": "^0.4.19", "eslint-plugin-react-refresh": "0.4.19",
"globals": "^16.0.0", "globals": "16.0.0",
"prettier": "^3.5.3", "prettier": "3.5.3",
"typescript": "~5.7.2", "typescript": "5.7.2",
"typescript-eslint": "^8.26.1", "typescript-eslint": "8.26.1",
"vite": "^6.3.1" "vite": "6.3.1"
} }
} }
+24 -49
View File
@@ -1,50 +1,27 @@
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import PlayerCell from "./fantasy/PlayerCell"; import PlayerCell from "./fantasy/PlayerCell";
import { import { type NFLAPIData, type NFLMatchupState } from "../utils/types";
NFLMatchupState,
SleeperUser,
type NFLRosterState,
type NFLState,
} from "../utils/types";
export default function FantasyStatus() { 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 PLAYERS_URL = "https://api.alexav.gg/v4/football/players";
const [personalRoster, setPersonalRoster] = useState<NFLRosterState | null>( const [personalRoster, setPersonalRoster] = useState<NFLMatchupState | null>(
null null
); );
const [opposingRoster, setOpposingRoster] = useState<NFLRosterState | null>( const [opposingRoster, setOpposingRoster] = useState<NFLMatchupState | null>(
null null
); );
// fetch roster information // fetch roster information
useEffect(() => { useEffect(() => {
async function fetchData() { async function fetchData() {
const nflState = (await fetch(NFL_STATE_URL).then((res) => const data = (await fetch("https://api.alexav.gg/v4/football/data").then(
res.json() (res) => res.json()
)) as NFLState; )) as NFLAPIData;
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[];
// rosters // rosters
const ownMatchup = matchups[1]; const ownMatchup = data.matchups[1] as NFLMatchupState;
const oppMatchup = matchups[0]; const oppMatchup = data.matchups[0] as NFLMatchupState;
const ownMatchupPlayers = await fetch( const ownMatchupPlayers = await fetch(
PLAYERS_URL + "?players=" + ownMatchup.starters PLAYERS_URL + "?players=" + ownMatchup.starters
@@ -54,16 +31,14 @@ export default function FantasyStatus() {
).then((res) => res.json()); ).then((res) => res.json());
setPersonalRoster({ setPersonalRoster({
...rosters.filter((v) => v.owner_id === USER_ID)[0], ...ownMatchup,
matchup: matchups[1], playerInfo: ownMatchupPlayers.playerInfo,
players: ownMatchupPlayers.playerInfo, owner: data.users[1],
user: users[1],
}); });
setOpposingRoster({ setOpposingRoster({
...rosters.filter((v) => v.owner_id === OPP_USER_ID)[0], ...oppMatchup,
matchup: matchups[0], playerInfo: oppMatchupPlayers.playerInfo,
players: oppMatchupPlayers.playerInfo, owner: data.users[0],
user: users[0],
}); });
} }
@@ -84,19 +59,19 @@ export default function FantasyStatus() {
<img <img
width="30" width="30"
className="rounded-lg" className="rounded-lg"
src={personalRoster?.user.metadata.avatar} src={personalRoster?.owner.metadata.avatar}
/> />
<h1 className="flex justify-center items-center mx-2 font-semibold"> <h1 className="flex justify-center items-center mx-2 font-semibold">
{personalRoster?.user.metadata.team_name} |{" "} {personalRoster?.owner.metadata.team_name} |{" "}
{personalRoster?.matchup.points} {personalRoster?.points}
</h1> </h1>
</div> </div>
<div className="space-y-2 space-x-2 whitespace-nowrap overflow-x-scroll"> <div className="space-y-2 space-x-2 whitespace-nowrap overflow-x-scroll">
{personalRoster?.players?.map((v, k) => { {personalRoster?.playerInfo?.map((v, k) => {
return ( return (
<div className="inline-block" key={k}> <div className="inline-block" key={k}>
<PlayerCell matchupData={personalRoster.matchup} player={v} /> <PlayerCell matchupData={personalRoster} player={v} />
</div> </div>
); );
})} })}
@@ -106,19 +81,19 @@ export default function FantasyStatus() {
<img <img
width="30" width="30"
className="rounded-lg" className="rounded-lg"
src={opposingRoster?.user.metadata.avatar} src={opposingRoster?.owner.metadata.avatar}
/> />
<h1 className="flex justify-center items-center mx-2 font-semibold"> <h1 className="flex justify-center items-center mx-2 font-semibold">
{opposingRoster?.user.metadata.team_name} |{" "} {opposingRoster?.owner.metadata.team_name} |{" "}
{opposingRoster?.matchup.points} {opposingRoster?.points}
</h1> </h1>
</div> </div>
<div className="space-y-2 space-x-2 whitespace-nowrap overflow-x-scroll"> <div className="space-y-2 space-x-2 whitespace-nowrap overflow-x-scroll">
{opposingRoster?.players?.map((v, k) => { {opposingRoster?.playerInfo?.map((v, k) => {
return ( return (
<div className="inline-block" key={k}> <div className="inline-block" key={k}>
<PlayerCell matchupData={opposingRoster.matchup} player={v} /> <PlayerCell matchupData={opposingRoster} player={v} />
</div> </div>
); );
})} })}
+16 -16
View File
@@ -13,25 +13,25 @@ type LastFMImageObject = {
}; };
// nfl stuff // 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 { interface NFLState {
week: number; week: number;
season_type: "pre" | "post" | "regular"; season_type: "pre" | "post" | "regular";
display_week: number; 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 { interface NFLPlayer {
last_name: string; last_name: string;
injury_status: string | null; injury_status: string | null;
@@ -53,8 +53,8 @@ export type {
LastFMMusicObject, LastFMMusicObject,
LastFMImageObject, LastFMImageObject,
NFLState, NFLState,
NFLRosterState,
NFLPlayer,
NFLMatchupState, NFLMatchupState,
SleeperUser, SleeperUser,
NFLAPIData,
NFLPlayer,
}; };