import { useEffect, useState } from "react"; import { ReactSortable, ReactSortableProps } from "react-sortablejs"; import { apiAuth, User } from "./api"; import { useSession } from "./Session"; type PlayerListProps = Partial> & { orderedList?: boolean; }; function PlayerList(props: PlayerListProps) { return ( {props.list?.map((item, index) => (
{props.orderedList ? index + 1 + ". " + item.display_name : item.display_name}
))}
); } interface PlayerInfoProps { user: User; players: User[]; } export function Chemistry({ user, players }: PlayerInfoProps) { const index = players.indexOf(user); var otherPlayers = players.slice(); otherPlayers.splice(index, 1); const [playersLeft, setPlayersLeft] = useState([]); const [playersMiddle, setPlayersMiddle] = useState(otherPlayers); const [playersRight, setPlayersRight] = useState([]); useEffect(() => { setPlayersMiddle(otherPlayers); }, [players]); const [dialog, setDialog] = useState("dialog"); async function handleSubmit() { const dialog = document.querySelector("dialog[id='ChemistryDialog']"); (dialog as HTMLDialogElement).showModal(); setDialog("sending..."); let left = playersLeft.map(({ id }) => id); let middle = playersMiddle.map(({ id }) => id); let right = playersRight.map(({ id }) => id); const data = { user: user.id, hate: left, undecided: middle, love: right }; const response = await apiAuth("chemistry", data, "POST"); response ? setDialog(response) : setDialog("try sending again"); } return ( <>

๐Ÿ˜ฌ

{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 )}
{ event.currentTarget.close(); }} > {dialog} ); } export function MVP({ user, players }: PlayerInfoProps) { const [availablePlayers, setAvailablePlayers] = useState(players); const [rankedPlayers, setRankedPlayers] = useState([]); const [dialog, setDialog] = useState("dialog"); useEffect(() => { setAvailablePlayers(players); }, [players]); async function handleSubmit() { const dialog = document.querySelector("dialog[id='MVPDialog']"); (dialog as HTMLDialogElement).showModal(); setDialog("sending..."); let mvps = rankedPlayers.map(({ id }) => id); const data = { user: user.id, mvps: mvps }; const response = await apiAuth("mvps", data, "POST"); response ? setDialog(response) : setDialog("try sending again"); } return ( <>

๐Ÿฅ๐Ÿƒ

{availablePlayers.length < 1 && ( all sorted ๐Ÿ‘ )}

๐Ÿ†

{rankedPlayers.length < 1 && ( carefully place as many of the Most Valuable Players{" "} (according to your humble opinion) in this box )}
{ event.currentTarget.close(); }} > {dialog} ); } export default function Rankings() { const { user } = useSession(); const [players, setPlayers] = useState([]); const [openTab, setOpenTab] = useState("Chemistry"); async function loadPlayers() { try { const data = await apiAuth("player/list", null, "GET"); setPlayers(data as User[]); } catch (error) { console.error(error); } } useEffect(() => { loadPlayers(); }, []); useEffect(() => { openPage(openTab, "aliceblue"); }, [user]); function openPage(pageName: string, color: string) { // Hide all elements with class="tabcontent" by default */ var i, tabcontent, tablinks; tabcontent = document.getElementsByClassName("tabcontent"); for (i = 0; i < tabcontent.length; i++) { (tabcontent[i] as HTMLElement).style.display = "none"; } // Remove the background color of all tablinks/buttons tablinks = document.getElementsByClassName("tablink"); for (i = 0; i < tablinks.length; i++) { let button = tablinks[i] as HTMLElement; button.style.opacity = "50%"; } // Show the specific tab content (document.getElementById(pageName) as HTMLElement).style.display = "block"; // Add the specific color to the button used to open the tab content let activeButton = document.getElementById( pageName + "Button" ) as HTMLElement; activeButton.style.fontWeight = "bold"; activeButton.style.opacity = "100%"; document.body.style.backgroundColor = color; setOpenTab(pageName); } return ( <>
assign as many or as few players as you want
and don't forget to submit (๐Ÿ’พ) when you're done :)
{user && }
{user && }
); }