feat: open automatically
This commit is contained in:
parent
bb7f795175
commit
16a6814d69
@ -1,4 +1,4 @@
|
|||||||
import { Dispatch, SetStateAction, useMemo, useState } from "react";
|
import { Dispatch, SetStateAction, useEffect, useMemo, useState } from "react";
|
||||||
import { ReactSortable, ReactSortableProps } from "react-sortablejs";
|
import { ReactSortable, ReactSortableProps } from "react-sortablejs";
|
||||||
import api, { baseUrl } from "./api";
|
import api, { baseUrl } from "./api";
|
||||||
|
|
||||||
@ -268,6 +268,27 @@ export function MVP({ user, players }: PlayerInfoProps) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default function Rankings() {
|
||||||
|
const [user, setUser] = useState<Player[]>([]);
|
||||||
|
const [players, setPlayers] = useState<Player[]>([]);
|
||||||
|
const [openTab, setOpenTab] = useState("Chemistry");
|
||||||
|
|
||||||
|
async function loadPlayers() {
|
||||||
|
const response = await fetch(`${baseUrl}player/list`, {
|
||||||
|
method: "GET",
|
||||||
|
});
|
||||||
|
const data = await response.json();
|
||||||
|
setPlayers(data as Player[]);
|
||||||
|
}
|
||||||
|
|
||||||
|
useMemo(() => {
|
||||||
|
loadPlayers();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
user.length === 1 && openPage(openTab, "aliceblue");
|
||||||
|
}, [user]);
|
||||||
|
|
||||||
function openPage(pageName: string, color: string) {
|
function openPage(pageName: string, color: string) {
|
||||||
// Hide all elements with class="tabcontent" by default */
|
// Hide all elements with class="tabcontent" by default */
|
||||||
var i, tabcontent, tablinks;
|
var i, tabcontent, tablinks;
|
||||||
@ -290,24 +311,9 @@ function openPage(pageName: string, color: string) {
|
|||||||
activeButton.style.fontWeight = "bold";
|
activeButton.style.fontWeight = "bold";
|
||||||
activeButton.style.opacity = "100%";
|
activeButton.style.opacity = "100%";
|
||||||
document.body.style.backgroundColor = color;
|
document.body.style.backgroundColor = color;
|
||||||
|
setOpenTab(pageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Rankings() {
|
|
||||||
const [user, setUser] = useState<Player[]>([]);
|
|
||||||
const [players, setPlayers] = useState<Player[]>([]);
|
|
||||||
|
|
||||||
async function loadPlayers() {
|
|
||||||
const response = await fetch(`${baseUrl}player/list`, {
|
|
||||||
method: "GET",
|
|
||||||
});
|
|
||||||
const data = await response.json();
|
|
||||||
setPlayers(data as Player[]);
|
|
||||||
}
|
|
||||||
|
|
||||||
useMemo(() => {
|
|
||||||
loadPlayers();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<SelectUser {...{ user, setUser, players, setPlayers }} />
|
<SelectUser {...{ user, setUser, players, setPlayers }} />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user