feat: rewrite of tabs component
This commit is contained in:
parent
4f30888c5c
commit
630986d49c
15
src/App.css
15
src/App.css
@ -321,11 +321,20 @@ button,
|
|||||||
opacity: 0.75;
|
opacity: 0.75;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tablink {
|
.tab-button {
|
||||||
color: white;
|
|
||||||
cursor: pointer;
|
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
background-color: grey;
|
||||||
|
border: none;
|
||||||
margin: 4px auto;
|
margin: 4px auto;
|
||||||
|
cursor: pointer;
|
||||||
|
opacity: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tab-button.active {
|
||||||
|
opacity: unset;
|
||||||
|
font-weight: bold;
|
||||||
|
background-color: black;
|
||||||
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
.navbar {
|
.navbar {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { createRef, useEffect, useState } from "react";
|
||||||
import { ReactSortable, ReactSortableProps } from "react-sortablejs";
|
import { ReactSortable, ReactSortableProps } from "react-sortablejs";
|
||||||
import { apiAuth, User } from "./api";
|
import { apiAuth, User } from "./api";
|
||||||
import { useSession } from "./Session";
|
import { useSession } from "./Session";
|
||||||
@ -190,7 +190,7 @@ export function MVP({ user, players }: PlayerInfoProps) {
|
|||||||
|
|
||||||
export default function Rankings() {
|
export default function Rankings() {
|
||||||
const { user } = useSession();
|
const { user } = useSession();
|
||||||
const [players, setPlayers] = useState<User[]>([]);
|
const [players, setPlayers] = useState<User[] | null>(null);
|
||||||
const [openTab, setOpenTab] = useState("Chemistry");
|
const [openTab, setOpenTab] = useState("Chemistry");
|
||||||
|
|
||||||
async function loadPlayers() {
|
async function loadPlayers() {
|
||||||
@ -205,67 +205,46 @@ export default function Rankings() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadPlayers();
|
loadPlayers();
|
||||||
}, []);
|
}, []);
|
||||||
|
const tabs = [
|
||||||
useEffect(() => {
|
{ id: "Chemistry", label: "🧪 Chemistry" },
|
||||||
openPage(openTab, "aliceblue");
|
{ id: "MVP", label: "🏆 MVP" },
|
||||||
}, [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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="container navbar">
|
{user && players && (
|
||||||
<button
|
<div>
|
||||||
className="tablink"
|
<div className="container navbar">
|
||||||
id="ChemistryButton"
|
{tabs.map((tab) => (
|
||||||
onClick={() => openPage("Chemistry", "aliceblue")}
|
<button
|
||||||
>
|
key={tab.id}
|
||||||
🧪 Chemistry
|
className={
|
||||||
</button>
|
openTab === tab.id ? "tab-button active" : "tab-button"
|
||||||
<button
|
}
|
||||||
className="tablink"
|
onClick={() => setOpenTab(tab.id)}
|
||||||
id="MVPButton"
|
>
|
||||||
onClick={() => openPage("MVP", "aliceblue")}
|
{tab.label}
|
||||||
>
|
</button>
|
||||||
🏆 MVP
|
))}
|
||||||
</button>
|
</div>
|
||||||
</div>
|
<span className="grey">
|
||||||
|
assign as many or as few players as you want
|
||||||
<span className="grey">
|
<br />
|
||||||
assign as many or as few players as you want
|
and don't forget to <b>submit</b> 💾 when you're done :)
|
||||||
<br />
|
</span>
|
||||||
and don't forget to <b>submit</b> (💾) when you're done :)
|
{tabs.map((tab) => {
|
||||||
</span>
|
if (openTab !== tab.id) return null;
|
||||||
|
switch (tab.id) {
|
||||||
<div id="Chemistry" className="tabcontent">
|
case "Chemistry":
|
||||||
{user && <Chemistry {...{ user, players }} />}
|
return <Chemistry key={tab.id} {...{ user, players }} />;
|
||||||
</div>
|
case "MVP":
|
||||||
<div id="MVP" className="tabcontent">
|
return <MVP key={tab.id} {...{ user, players }} />;
|
||||||
{user && <MVP {...{ user, players }} />}
|
default:
|
||||||
</div>
|
return null;
|
||||||
|
}
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user