From 630986d49c66b1502c9be8b071f2ab6cdd57f93c Mon Sep 17 00:00:00 2001 From: julius Date: Thu, 13 Mar 2025 13:11:52 +0100 Subject: [PATCH] feat: rewrite of tabs component --- src/App.css | 15 ++++++-- src/Rankings.tsx | 99 +++++++++++++++++++----------------------------- 2 files changed, 51 insertions(+), 63 deletions(-) diff --git a/src/App.css b/src/App.css index f1cfd2e..b32ff23 100644 --- a/src/App.css +++ b/src/App.css @@ -321,11 +321,20 @@ button, opacity: 0.75; } -.tablink { - color: white; - cursor: pointer; +.tab-button { flex: 1; + background-color: grey; + border: none; margin: 4px auto; + cursor: pointer; + opacity: 50%; +} + +.tab-button.active { + opacity: unset; + font-weight: bold; + background-color: black; + color: white; } .navbar { diff --git a/src/Rankings.tsx b/src/Rankings.tsx index 974a165..179e6f9 100644 --- a/src/Rankings.tsx +++ b/src/Rankings.tsx @@ -1,4 +1,4 @@ -import { useEffect, useState } from "react"; +import { createRef, useEffect, useState } from "react"; import { ReactSortable, ReactSortableProps } from "react-sortablejs"; import { apiAuth, User } from "./api"; import { useSession } from "./Session"; @@ -190,7 +190,7 @@ export function MVP({ user, players }: PlayerInfoProps) { export default function Rankings() { const { user } = useSession(); - const [players, setPlayers] = useState([]); + const [players, setPlayers] = useState(null); const [openTab, setOpenTab] = useState("Chemistry"); async function loadPlayers() { @@ -205,67 +205,46 @@ export default function Rankings() { 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); - } + const tabs = [ + { id: "Chemistry", label: "๐Ÿงช Chemistry" }, + { id: "MVP", label: "๐Ÿ† MVP" }, + ]; return ( <> -
- - -
- - - assign as many or as few players as you want -
- and don't forget to submit (๐Ÿ’พ) when you're done :) -
- -
- {user && } -
-
- {user && } -
+ {user && players && ( +
+
+ {tabs.map((tab) => ( + + ))} +
+ + assign as many or as few players as you want +
+ and don't forget to submit ๐Ÿ’พ when you're done :) +
+ {tabs.map((tab) => { + if (openTab !== tab.id) return null; + switch (tab.id) { + case "Chemistry": + return ; + case "MVP": + return ; + default: + return null; + } + })} +
+ )} ); }