new api structure
This commit is contained in:
@@ -3,8 +3,6 @@ import PlayerCell from "./fantasy/PlayerCell";
|
|||||||
import { type NFLAPIData, type NFLMatchupState } from "../utils/types";
|
import { type NFLAPIData, type NFLMatchupState } from "../utils/types";
|
||||||
|
|
||||||
export default function FantasyStatus() {
|
export default function FantasyStatus() {
|
||||||
const PLAYERS_URL = "https://api.alexav.gg/v4/football/players";
|
|
||||||
|
|
||||||
const [personalRoster, setPersonalRoster] = useState<NFLMatchupState | null>(
|
const [personalRoster, setPersonalRoster] = useState<NFLMatchupState | null>(
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
@@ -15,7 +13,7 @@ export default function FantasyStatus() {
|
|||||||
// fetch roster information
|
// fetch roster information
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function fetchData() {
|
async function fetchData() {
|
||||||
const data = (await fetch("https://api.alexav.gg/v4/football/data").then(
|
const data = (await fetch("https://api.alexav.gg/v4/football").then(
|
||||||
(res) => res.json()
|
(res) => res.json()
|
||||||
)) as NFLAPIData;
|
)) as NFLAPIData;
|
||||||
|
|
||||||
@@ -23,21 +21,12 @@ export default function FantasyStatus() {
|
|||||||
const ownMatchup = data.matchups[1] as NFLMatchupState;
|
const ownMatchup = data.matchups[1] as NFLMatchupState;
|
||||||
const oppMatchup = data.matchups[0] as NFLMatchupState;
|
const oppMatchup = data.matchups[0] as NFLMatchupState;
|
||||||
|
|
||||||
const ownMatchupPlayers = await fetch(
|
|
||||||
PLAYERS_URL + "?players=" + ownMatchup.starters
|
|
||||||
).then((res) => res.json());
|
|
||||||
const oppMatchupPlayers = await fetch(
|
|
||||||
PLAYERS_URL + "?players=" + oppMatchup.starters
|
|
||||||
).then((res) => res.json());
|
|
||||||
|
|
||||||
setPersonalRoster({
|
setPersonalRoster({
|
||||||
...ownMatchup,
|
...ownMatchup,
|
||||||
playerInfo: ownMatchupPlayers.playerInfo,
|
|
||||||
owner: data.users[1],
|
owner: data.users[1],
|
||||||
});
|
});
|
||||||
setOpposingRoster({
|
setOpposingRoster({
|
||||||
...oppMatchup,
|
...oppMatchup,
|
||||||
playerInfo: oppMatchupPlayers.playerInfo,
|
|
||||||
owner: data.users[0],
|
owner: data.users[0],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -68,10 +57,10 @@ export default function FantasyStatus() {
|
|||||||
</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?.playerInfo?.map((v, k) => {
|
{personalRoster?.starters.map((v, k) => {
|
||||||
return (
|
return (
|
||||||
<div className="inline-block" key={k}>
|
<div className="inline-block" key={k}>
|
||||||
<PlayerCell matchupData={personalRoster} player={v} />
|
<PlayerCell player={v} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
@@ -90,10 +79,10 @@ export default function FantasyStatus() {
|
|||||||
</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?.playerInfo?.map((v, k) => {
|
{opposingRoster?.starters.map((v, k) => {
|
||||||
return (
|
return (
|
||||||
<div className="inline-block" key={k}>
|
<div className="inline-block" key={k}>
|
||||||
<PlayerCell matchupData={opposingRoster} player={v} />
|
<PlayerCell player={v} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
@@ -1,34 +1,11 @@
|
|||||||
import type { NFLMatchupState, NFLPlayer } from "../../utils/types";
|
import type { NFLPlayer } from "../../utils/types";
|
||||||
|
|
||||||
export default function PlayerCell({
|
|
||||||
player,
|
|
||||||
matchupData,
|
|
||||||
}: {
|
|
||||||
player: NFLPlayer | null;
|
|
||||||
matchupData: NFLMatchupState | null;
|
|
||||||
}) {
|
|
||||||
const getScoreForPlayer = () => {
|
|
||||||
const rosterPosition = matchupData?.starters.findIndex(
|
|
||||||
(v) => v === player?.player_id
|
|
||||||
);
|
|
||||||
|
|
||||||
return matchupData?.starters_points[rosterPosition!] || 0;
|
|
||||||
};
|
|
||||||
const truncatedName = () => {
|
|
||||||
if (player) {
|
|
||||||
const firstName = player?.full_name.split(" ")[0];
|
|
||||||
const shortened =
|
|
||||||
firstName[0].toUpperCase() + "." + " " + player.last_name;
|
|
||||||
|
|
||||||
return shortened;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
export default function PlayerCell({ player }: { player: NFLPlayer | null }) {
|
||||||
if (player && player.full_name) {
|
if (player && player.full_name) {
|
||||||
return (
|
return (
|
||||||
<div className="flex-wrap flex space-x-2">
|
<div className="flex-wrap flex space-x-2">
|
||||||
<div>
|
<div>
|
||||||
<h1 className="font-semibold text-1xl">{truncatedName()}</h1>
|
<h1 className="font-semibold text-1xl">{player.abv_name}</h1>
|
||||||
<p>
|
<p>
|
||||||
{player?.position} · {player?.team} {player?.injury_status && "·"}{" "}
|
{player?.position} · {player?.team} {player?.injury_status && "·"}{" "}
|
||||||
{player?.injury_status && (
|
{player?.injury_status && (
|
||||||
@@ -39,7 +16,7 @@ export default function PlayerCell({
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<p className="flex justify-center items-center">
|
<p className="flex justify-center items-center">
|
||||||
<span className="font-semibold">{getScoreForPlayer()}</span>
|
<span className="font-semibold">{player.points}</span>
|
||||||
</p>
|
</p>
|
||||||
<div className="inline-block min-h-[1em] w-0.5 self-stretch bg-neutral-100 dark:bg-white/30"></div>
|
<div className="inline-block min-h-[1em] w-0.5 self-stretch bg-neutral-100 dark:bg-white/30"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+4
-4
@@ -16,11 +16,9 @@ interface NFLAPIData {
|
|||||||
users: SleeperUser[];
|
users: SleeperUser[];
|
||||||
}
|
}
|
||||||
interface NFLMatchupState {
|
interface NFLMatchupState {
|
||||||
owner: SleeperUser;
|
|
||||||
points: number;
|
points: number;
|
||||||
players: string[];
|
owner: SleeperUser;
|
||||||
playerInfo: NFLPlayer[];
|
starters: NFLPlayer[];
|
||||||
starters: string[];
|
|
||||||
starters_points: number[];
|
starters_points: number[];
|
||||||
players_points: object;
|
players_points: object;
|
||||||
}
|
}
|
||||||
@@ -32,10 +30,12 @@ interface NFLState {
|
|||||||
interface NFLPlayer {
|
interface NFLPlayer {
|
||||||
last_name: string;
|
last_name: string;
|
||||||
injury_status: string | null;
|
injury_status: string | null;
|
||||||
|
abv_name: string;
|
||||||
position: string;
|
position: string;
|
||||||
full_name: string;
|
full_name: string;
|
||||||
team: string;
|
team: string;
|
||||||
player_id: string;
|
player_id: string;
|
||||||
|
points: number;
|
||||||
}
|
}
|
||||||
interface SleeperUser {
|
interface SleeperUser {
|
||||||
avatar: string;
|
avatar: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user