diff --git a/src/assets/main.css b/src/assets/main.css index 46554a3..a66cdbf 100644 --- a/src/assets/main.css +++ b/src/assets/main.css @@ -7,6 +7,17 @@ body { font-family: 'Pathway Gothic One', sans-serif; overflow: hidden; + + ::-webkit-scrollbar { + width:50px; + height:10px; + border-radius: var(--radius-lg); + background-color:white; + } + ::-webkit-scrollbar-thumb { + background-color:gray; + border-radius: var(--radius-lg); + } } @keyframes scroll { diff --git a/src/components/FantasyStatus.tsx b/src/components/FantasyStatus.tsx new file mode 100644 index 0000000..531edc8 --- /dev/null +++ b/src/components/FantasyStatus.tsx @@ -0,0 +1,79 @@ +import { useEffect, useState } from "react"; +import PlayerCell from "./fantasy/PlayerCell"; +import { + type NFLRosterState, + type NFLPlayer, + NFLState, + NFLMatchupState, +} from "../utils/types"; + +export default function FantasyStatus() { + const USER_ID = "1263620186439696384"; + 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 [roster, setRoster] = useState(null); + const [players, setPlayers] = useState(null); + const [nflState, setNflState] = useState(null); + const [matchup, setMatchup] = useState(null); + + useEffect(() => { + fetch(NFL_STATE_URL).then(async (res) => { + if (res.ok) { + const data = await res.json(); + setNflState(data); + } + }); + fetch(LEAGUE_BASE_URL).then(async (res) => { + if (res.ok) { + const data = await res.json(); + setRoster( + data.filter((v: NFLRosterState) => v.owner_id === USER_ID)[0] + ); + } + }); + }, []); + useEffect(() => { + if (roster) { + const players = roster.starters.join(","); + + fetch( + "https://api.alexav.gg/v4/football/players?players=" + players + ).then(async (res) => { + if (res.ok) { + const data = await res.json(); + setPlayers(data.playerInfo); + } + }); + } + }, [roster]); + useEffect(() => { + if (nflState && !matchup) { + fetch(MATCHUPS_URL + nflState.display_week).then(async (res) => { + if (res.ok) { + const data = await res.json(); + setMatchup(data[1]); + } + }); + } + }, [nflState]); + + return ( +
+

Fantasy

+ +
+ {players?.map((v, k) => { + return ( +
+ +
+ ); + })} +
+
+ ); +} diff --git a/src/components/Layout.tsx b/src/components/Layout.tsx index 5411e83..6a600cb 100644 --- a/src/components/Layout.tsx +++ b/src/components/Layout.tsx @@ -1,7 +1,6 @@ import { useState, useEffect, type ReactNode } from "react"; import { Flashlight, FlashlightOff } from "lucide-react"; import SplatterImage from "../assets/splatter.png"; -import Countdown from "./Countdown"; export default function Layout({ children }: { children: ReactNode }) { const [pointerPosition, setPointerPosition] = useState({ x: 500, y: 500 }); @@ -140,7 +139,6 @@ export default function Layout({ children }: { children: ReactNode }) {

welcome !

- {children} diff --git a/src/components/fantasy/PlayerCell.tsx b/src/components/fantasy/PlayerCell.tsx new file mode 100644 index 0000000..658ce33 --- /dev/null +++ b/src/components/fantasy/PlayerCell.tsx @@ -0,0 +1,48 @@ +import type { NFLMatchupState, 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; + } + }; + + if (player && player.full_name) { + return ( +
+
+

{truncatedName()}

+

+ {player?.position} · {player?.team} {player?.injury_status && "·"}{" "} + {player?.injury_status && ( + + {player?.injury_status} + + )} +

+
+

+ {getScoreForPlayer()} +

+
+
+ ); + } +} diff --git a/src/pages/App.tsx b/src/pages/App.tsx index 3eacf7c..25287fe 100644 --- a/src/pages/App.tsx +++ b/src/pages/App.tsx @@ -3,10 +3,14 @@ import MusicComponent from "../components/MusicComponent"; import TVComponent from "../components/TVComponent"; import GameComponent from "../components/GameComponent"; import RandomLyric from "../components/RandomLyric"; +import FantasyStatus from "../components/FantasyStatus"; +import Countdown from "../components/Countdown"; export default function App() { return ( + +
diff --git a/src/utils/types.ts b/src/utils/types.ts index 22f1d82..4fb1a16 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -12,4 +12,39 @@ type LastFMImageObject = { "#text": string; }; -export type { LastFMMusicObject, LastFMImageObject }; +// nfl stuff +interface NFLState { + week: number; + season_type: "pre" | "post" | "regular"; + display_week: number; +} +interface NFLRosterState { + league_id: string; + owner_id: string; + players: string[]; + starters: string[]; +} +interface NFLMatchupState { + points: number; + players: string[]; + starters: string[]; + starters_points: number[]; + players_points: object; +} +interface NFLPlayer { + last_name: string; + injury_status: string | null; + position: string; + full_name: string; + team: string; + player_id: string; +} + +export type { + LastFMMusicObject, + LastFMImageObject, + NFLState, + NFLRosterState, + NFLPlayer, + NFLMatchupState, +};