fix: improve import page

This commit is contained in:
zkldi
2023-01-26 15:09:40 +00:00
parent f19c4d3895
commit 2e7f892579
2 changed files with 22 additions and 2 deletions
@@ -9,7 +9,7 @@ import Loading from "components/util/Loading";
import useApiQuery from "components/util/query/useApiQuery";
import { UserContext } from "context/UserContext";
import { TachiConfig } from "lib/config";
import React, { useContext, useState } from "react";
import React, { useContext, useEffect, useState } from "react";
import { Row } from "react-bootstrap";
import { Link } from "react-router-dom";
import {
@@ -27,6 +27,14 @@ export default function ImportPage({ user }: { user: UserDocument }) {
const [game, setGame] = useState<Game | null>(null);
const queryGame = new URLSearchParams(window.location.search).get("game");
useEffect(() => {
if (queryGame) {
setGame(queryGame as Game);
}
}, [queryGame]);
return (
<div>
<div>
@@ -50,6 +58,7 @@ export default function ImportPage({ user }: { user: UserDocument }) {
<select
className="form-control"
onChange={(e) => setGame(e.target.value === "" ? null : (e.target.value as Game))}
value={game}
>
<option value="">Please select a game.</option>
{TachiConfig.games.map((e) => (
@@ -1,6 +1,17 @@
import React from "react";
import { FormatGame, GetGameConfig } from "tachi-common";
import { TachiConfig } from "lib/config";
import MenuLink from "./MenuLink";
import MenuDropdown from "./MenuDropdown";
export default function ImportScoresLink() {
return <MenuLink to="/import" name="Import Scores"></MenuLink>;
const links = [];
for (const game of TachiConfig.games) {
const gameConfig = GetGameConfig(game);
links.push(<MenuLink key={game} name={gameConfig.name} to={`/import?game=${game}`} />);
}
return <MenuDropdown name="Import Scores">{links}</MenuDropdown>;
}