From b73924612966e68db198948f5c4d7b6999aa67bb Mon Sep 17 00:00:00 2001 From: julius Date: Sun, 18 May 2025 11:59:07 +0200 Subject: [PATCH] feat: load previously submitted by default --- src/Rankings.tsx | 195 +++++++++++++++++++++++------------------------ 1 file changed, 96 insertions(+), 99 deletions(-) diff --git a/src/Rankings.tsx b/src/Rankings.tsx index 80ca354..f42c2f5 100644 --- a/src/Rankings.tsx +++ b/src/Rankings.tsx @@ -1,11 +1,4 @@ -import { - ButtonHTMLAttributes, - Fragment, - ReactNode, - useEffect, - useRef, - useState, -} from "react"; +import { ButtonHTMLAttributes, useEffect, useRef, useState } from "react"; import { ReactSortable, ReactSortableProps } from "react-sortablejs"; import { apiAuth, loadPlayers, User } from "./api"; import { TeamState, useSession } from "./Session"; @@ -65,15 +58,11 @@ function ChemistryDnD({ user, teams, players }: PlayerInfoProps) { const [playersLeft, setPlayersLeft] = useState([]); const [playersMiddle, setPlayersMiddle] = useState(otherPlayers); const [playersRight, setPlayersRight] = useState([]); + const [loading, setLoading] = useState(false); useEffect(() => { - setPlayersMiddle(otherPlayers); + handleGet(); }, [players]); - useEffect(() => { - setPlayersLeft([]); - setPlayersMiddle(otherPlayers); - setPlayersRight([]); - }, [teams]); const [dialog, setDialog] = useState("dialog"); const dialogRef = useRef(null); @@ -96,6 +85,7 @@ function ChemistryDnD({ user, teams, players }: PlayerInfoProps) { } async function handleGet() { + setLoading(true); const data = await apiAuth(`chemistry/${teams.activeTeam}`, null, "GET"); if (data.detail) alert(data.detail); else { @@ -110,6 +100,7 @@ function ChemistryDnD({ user, teams, players }: PlayerInfoProps) { ); setPlayersRight(filterSort(otherPlayers, chemistry.love)); } + setLoading(false); } return ( @@ -122,46 +113,50 @@ function ChemistryDnD({ user, teams, players }: PlayerInfoProps) { setPlayersLeft([]); }} /> -
-
-

😬

- {playersLeft.length < 1 && ( - - drag people here that you'd rather not play with - - )} - + {loading ? ( + + ) : ( +
+
+

😬

+ {playersLeft.length < 1 && ( + + drag people here that you'd rather not play with + + )} + +
+
+

🤷

+ +
+
+

😍

+ {playersRight.length < 1 && ( + + drag people here that you love playing with from best to ... ok + + )} + +
-
-

🤷

- -
-
-

😍

- {playersRight.length < 1 && ( - - drag people here that you love playing with from best to ... ok - - )} - -
-
+ )}