From dcbb507174573ea7994865c398bcc9c2612605bb Mon Sep 17 00:00:00 2001 From: julius Date: Sun, 26 Jan 2025 17:52:31 +0100 Subject: [PATCH] feat: load `Chemisty` and `MVP` with fetched players and selected user --- src/App.css | 2 +- src/Rankings.tsx | 71 ++++++++++++------------------------------------ 2 files changed, 18 insertions(+), 55 deletions(-) diff --git a/src/App.css b/src/App.css index d1dc86a..693859c 100644 --- a/src/App.css +++ b/src/App.css @@ -1,5 +1,5 @@ body { - background-color: ghostwhite; + background-color: aliceblue; position: relative; z-index: 0; color: black; diff --git a/src/Rankings.tsx b/src/Rankings.tsx index f9ff012..cbd03dd 100644 --- a/src/Rankings.tsx +++ b/src/Rankings.tsx @@ -24,7 +24,7 @@ function PlayerList(props: PlayerListProps) { ); } -interface PlayerStateProps { +interface SelectUserProps { user: Player[]; setUser: Dispatch>; players: Player[]; @@ -36,7 +36,7 @@ export function SelectUser({ setUser, players, setPlayers, -}: PlayerStateProps) { +}: SelectUserProps) { return ( <>
@@ -76,7 +76,7 @@ export function SelectUser({ @@ -94,9 +94,17 @@ export function SelectUser({ ); } -export function Chemistry() { +interface PlayerInfoProps { + user: Player[]; + players: Player[]; +} + +export function Chemistry({ user, players }: PlayerInfoProps) { + const index = players.indexOf(user[0]); + var otherPlayers = players.slice(); + otherPlayers.splice(index, 1); const [playersLeft, setPlayersLeft] = useState([]); - const [playersMiddle, setPlayersMiddle] = useState([]); + const [playersMiddle, setPlayersMiddle] = useState(otherPlayers); const [playersRight, setPlayersRight] = useState([]); const [dialog, setDialog] = useState("dialog"); @@ -176,25 +184,12 @@ export function Chemistry() { ); } -export function MVP() { - const [user, setUser] = useState([]); - const [availablePlayers, setAvailablePlayers] = useState([]); +export function MVP({ user, players }: PlayerInfoProps) { + const [availablePlayers, setAvailablePlayers] = useState(players); const [rankedPlayers, setRankedPlayers] = useState([]); const [dialog, setDialog] = useState("dialog"); - async function loadPlayers() { - const response = await fetch(`${baseUrl}player/list`, { - method: "GET", - }); - const data = await response.json(); - setAvailablePlayers(data as Player[]); - } - - useEffect(() => { - loadPlayers(); - }, []); - async function handleSubmit() { const dialog = document.querySelector("dialog[id='MVPDialog']"); (dialog as HTMLDialogElement).showModal(); @@ -212,38 +207,6 @@ export function MVP() { return ( <> -
- your name? - {user.length < 1 ? ( - <> -
drag your name here - - ) : ( - <> - { - setUser([]); - }} - > - {" ✕"} - -
- - )} - -

🥏🏃

@@ -366,10 +329,10 @@ export default function Rankings() {
- +
- +
)}