refactor: create UGPT common type

This commit is contained in:
zkldi
2022-11-10 20:22:37 +00:00
parent c4b94fdd84
commit fef5e3fc01
15 changed files with 58 additions and 77 deletions
@@ -24,18 +24,14 @@ import {
} from "tachi-common";
import { GameClassSets } from "tachi-common/game-classes";
import { GPTLeaderboard, UGPTLeaderboardAdjacent } from "types/api-returns";
import { GamePT, SetState } from "types/react";
import { GamePT, SetState, UGPT } from "types/react";
interface LeaderboardsData {
stats: UGPTLeaderboardAdjacent;
leaderboard: GPTLeaderboard;
}
export default function LeaderboardsPage({
reqUser,
game,
playtype,
}: { reqUser: UserDocument } & GamePT) {
export default function LeaderboardsPage({ reqUser, game, playtype }: UGPT) {
const gameConfig = GetGameConfig(game);
useSetSubheader(
["Users", reqUser.username, "Games", gameConfig.name, playtype, "Leaderboard"],
@@ -29,7 +29,7 @@ import {
UserGameStats,
} from "tachi-common";
import { SessionReturns, UGPTHistory } from "types/api-returns";
import { GamePT, SetState } from "types/react";
import { GamePT, SetState, UGPT } from "types/react";
import { ScoreDataset } from "types/tables";
import SessionRaiseBreakdown from "components/sessions/SessionRaiseBreakdown";
import useApiQuery from "components/util/query/useApiQuery";
@@ -37,11 +37,7 @@ import ApiError from "components/util/ApiError";
import Loading from "components/util/Loading";
import Select from "components/util/Select";
export default function OverviewPage({
reqUser,
game,
playtype,
}: { reqUser: UserDocument } & GamePT) {
export default function OverviewPage({ reqUser, game, playtype }: UGPT) {
const gameConfig = GetGameConfig(game);
useSetSubheader(
["Users", reqUser.username, "Games", gameConfig.name, playtype],
@@ -58,7 +54,7 @@ export default function OverviewPage({
);
}
function LastSession({ reqUser, game, playtype }: { reqUser: UserDocument } & GamePT) {
function LastSession({ reqUser, game, playtype }: UGPT) {
return (
<AsyncLoader
promiseFn={async () => {
@@ -255,7 +251,7 @@ function RecentSessionScoreInfo({
type RankingDurations = "3mo" | "year";
function RankingInfo({ reqUser, game, playtype }: { reqUser: UserDocument } & GamePT) {
function RankingInfo({ reqUser, game, playtype }: UGPT) {
const [duration, setDuration] = useState<RankingDurations>("3mo");
const { data, error } = useApiQuery<UGPTHistory>(
@@ -26,7 +26,7 @@ import {
SongDocument,
UnsuccessfulAPIResponse,
} from "tachi-common";
import { GamePT, SetState } from "types/react";
import { GamePT, SetState, UGPT } from "types/react";
import usePreferredRanking from "components/util/usePreferredRanking";
export default function ScoresPage({
@@ -286,7 +286,7 @@ function PBsSearch({
);
}
function ScoresOverview({ reqUser, game, playtype }: { reqUser: UserDocument } & GamePT) {
function ScoresOverview({ reqUser, game, playtype }: UGPT) {
const [search, setSearch] = useState("");
const { data, error } = useFetchScores(
@@ -15,13 +15,11 @@ import { UserContext } from "context/UserContext";
import React, { useContext, useMemo, useState } from "react";
import { Badge, Button, Col, Form, Modal, Row } from "react-bootstrap";
import { Redirect, useParams } from "react-router-dom";
import { GetGameConfig, UserDocument, SessionDocument } from "tachi-common";
import { GetGameConfig, SessionDocument } from "tachi-common";
import { SessionReturns } from "types/api-returns";
import { GamePT, SetState } from "types/react";
import { SetState, UGPT } from "types/react";
type Props = { reqUser: UserDocument } & GamePT;
export default function SpecificSessionPage({ reqUser, game, playtype }: Props) {
export default function SpecificSessionPage({ reqUser, game, playtype }: UGPT) {
const { sessionID } = useParams<{ sessionID: string }>();
const { data, error } = useApiQuery<SessionReturns>(`/sessions/${sessionID}`);
@@ -49,7 +47,7 @@ export default function SpecificSessionPage({ reqUser, game, playtype }: Props)
return <SessionPage {...{ data, game, playtype, reqUser }} />;
}
function SessionPage({ data, game, playtype }: Props & { data: SessionReturns }) {
function SessionPage({ data, game, playtype }: UGPT & { data: SessionReturns }) {
const [sessionData, setSessionData] = useState(data);
const { session, user, charts, scores, songs } = sessionData;
@@ -1,4 +1,5 @@
import { APIFetchV1 } from "util/api";
import { ErrorPage } from "app/pages/ErrorPage";
import ClassBadge from "components/game/ClassBadge";
import useSetSubheader from "components/layout/header/useSetSubheader";
import Card from "components/layout/page/Card";
@@ -12,8 +13,9 @@ import Muted from "components/util/Muted";
import useApiQuery from "components/util/query/useApiQuery";
import SelectButton from "components/util/SelectButton";
import useQueryString from "components/util/useQueryString";
import { UGPTContext } from "context/UGPTContext";
import deepmerge from "deepmerge";
import { FieldArray, useFormik } from "formik";
import { useFormik } from "formik";
import { TachiConfig } from "lib/config";
import React, { useContext, useEffect, useState } from "react";
import { Button, Col, Form, Row } from "react-bootstrap";
@@ -22,18 +24,14 @@ import {
FormatGame,
GetGameConfig,
GetGamePTConfig,
UserDocument,
ShowcaseStatDetails,
TableDocument,
UGPTSettings,
UserDocument,
} from "tachi-common";
import { GamePT, SetState } from "types/react";
import { UGPTContext } from "context/UGPTContext";
import { ErrorPage } from "app/pages/ErrorPage";
import { SetState, UGPT } from "types/react";
type Props = { reqUser: UserDocument } & GamePT;
export default function UGPTSettingsPage({ reqUser, game, playtype }: Props) {
export default function UGPTSettingsPage({ reqUser, game, playtype }: UGPT) {
const query = useQueryString();
const [page, setPage] = useState<"preferences" | "showcase">(
@@ -47,7 +45,7 @@ export default function UGPTSettingsPage({ reqUser, game, playtype }: Props) {
`${reqUser.username}'s ${FormatGame(game, playtype)} Settings`
);
const props = { reqUser, game, playtype };
const UGPT = { reqUser, game, playtype };
return (
<Card header="Settings" className="col-12 offset-lg-2 col-lg-8">
@@ -67,9 +65,9 @@ export default function UGPTSettingsPage({ reqUser, game, playtype }: Props) {
<div className="col-12">
<Divider className="mt-4 mb-4" />
{page === "preferences" ? (
<PreferencesForm {...props} />
<PreferencesForm {...UGPT} />
) : (
<ShowcaseForm {...props} />
<ShowcaseForm {...UGPT} />
)}
</div>
</div>
@@ -77,7 +75,7 @@ export default function UGPTSettingsPage({ reqUser, game, playtype }: Props) {
);
}
function PreferencesForm({ reqUser, game, playtype }: Props) {
function PreferencesForm({ reqUser, game, playtype }: UGPT) {
const { loggedInData, setLoggedInData } = useContext(UGPTContext);
if (!loggedInData) {
@@ -386,7 +384,7 @@ function PreferencesForm({ reqUser, game, playtype }: Props) {
);
}
function ShowcaseForm({ reqUser, game, playtype }: Props) {
function ShowcaseForm({ reqUser, game, playtype }: UGPT) {
const { loggedInData, setLoggedInData } = useContext(UGPTContext);
if (!loggedInData) {
@@ -468,7 +466,7 @@ function RenderCurrentStats({
}: {
stats: ShowcaseStatDetails[];
setStats: SetState<ShowcaseStatDetails[]>;
} & Props) {
} & UGPT) {
function RemoveStatAtIndex(index: number) {
setStats(stats.filter((e, i) => i !== index));
}
@@ -15,11 +15,9 @@ import { UserContext } from "context/UserContext";
import React, { useContext, useMemo, useState } from "react";
import { FolderDocument, GetGamePTConfig, UserDocument } from "tachi-common";
import { FolderStatsInfo, UGPTFolderSearch } from "types/api-returns";
import { GamePT } from "types/react";
import { GamePT, UGPT } from "types/react";
type Props = { reqUser: UserDocument } & GamePT;
export default function FoldersSearch({ reqUser, game, playtype }: Props) {
export default function FoldersSearch({ reqUser, game, playtype }: UGPT) {
const [search, setSearch] = useState("");
const params = useMemo(() => new URLSearchParams({ search }), [search]);
@@ -82,7 +80,7 @@ export function FolderInfoComponent({
playtype,
folderStats,
folder,
}: Props & { folder: FolderDocument; folderStats: FolderStatsInfo }) {
}: UGPT & { folder: FolderDocument; folderStats: FolderStatsInfo }) {
const gptConfig = GetGamePTConfig(game, playtype);
const scoreBucket = useBucket(game, playtype);
@@ -3,20 +3,18 @@ import Divider from "components/util/Divider";
import Icon from "components/util/Icon";
import SelectLinkButton from "components/util/SelectLinkButton";
import useUGPTBase from "components/util/useUGPTBase";
import { UserContext } from "context/UserContext";
import { AllLUGPTStatsContext } from "context/AllLUGPTStatsContext";
import { UserContext } from "context/UserContext";
import React, { useContext } from "react";
import { Route, Switch } from "react-router-dom";
import { FormatGame, GetGameConfig, UserDocument } from "tachi-common";
import { GamePT } from "types/react";
import { FormatGame, GetGameConfig } from "tachi-common";
import { UGPT } from "types/react";
import FolderSelectPage from "./FolderSelectPage";
import FolderTablePage from "./FolderTablePage";
import RecentFoldersPage from "./RecentFoldersPage";
import SpecificFolderPage from "./SpecificFolderPage";
type Props = { reqUser: UserDocument } & GamePT;
export default function FoldersMainPage({ reqUser, game, playtype }: Props) {
export default function FoldersMainPage({ reqUser, game, playtype }: UGPT) {
const gameConfig = GetGameConfig(game);
const { user } = useContext(UserContext);
@@ -5,16 +5,12 @@ import { UserContext } from "context/UserContext";
import React, { useContext } from "react";
import { Row } from "react-bootstrap";
import { Link } from "react-router-dom";
import { FolderDocument, UserDocument, RecentlyViewedFolderDocument } from "tachi-common";
import { FolderDocument, RecentlyViewedFolderDocument } from "tachi-common";
import { FolderStatsInfo } from "types/api-returns";
import { GamePT } from "types/react";
import { UGPT } from "types/react";
import { FolderInfoComponent } from "./FolderSelectPage";
export default function RecentFoldersPage({
reqUser,
game,
playtype,
}: { reqUser: UserDocument } & GamePT) {
export default function RecentFoldersPage({ reqUser, game, playtype }: UGPT) {
const { user } = useContext(UserContext);
if (!user) {
@@ -0,0 +1,6 @@
import React from "react";
import { UGPT } from "types/react";
export default function RivalsActivityPage({ reqUser, game, playtype }: UGPT) {
return <div>RivalsActivityPage</div>;
}
@@ -9,6 +9,7 @@ import React from "react";
import { Col, Row } from "react-bootstrap";
import { Redirect, Route, Switch } from "react-router-dom";
import { FormatGame, Game, GetGameConfig, Playtype, UserDocument } from "tachi-common";
import RivalsActivityPage from "./RivalsActivityPage";
import RivalsManagePage from "./RivalsManagePage";
export default function RivalsMainPage({
@@ -63,7 +64,7 @@ export default function RivalsMainPage({
<Switch>
<Route exact path="/dashboard/users/:userID/games/:game/:playtype/rivals">
{settings?.rivals.length === 0 && <Redirect to={`${base}/rivals/manage`} />}
NOT WRITTEN YET
<RivalsActivityPage reqUser={reqUser} game={game} playtype={playtype} />
</Route>
<Route
@@ -7,12 +7,10 @@ import React from "react";
import { Col, Row } from "react-bootstrap";
import { Route, Switch } from "react-router-dom";
import { FormatGame, GetGameConfig, UserDocument } from "tachi-common";
import { GamePT } from "types/react";
import { GamePT, UGPT } from "types/react";
import GoalsPage from "./GoalsPage";
type Props = { reqUser: UserDocument } & GamePT;
export default function TargetsPage({ reqUser, game, playtype }: Props) {
export default function TargetsPage({ reqUser, game, playtype }: UGPT) {
const gameConfig = GetGameConfig(game);
useSetSubheader(
@@ -6,18 +6,16 @@ import React, { useContext } from "react";
import { useQuery } from "react-query";
import { integer, UserDocument, ShowcaseStatDetails } from "tachi-common";
import { UGPTPreferenceStatsReturn } from "types/api-returns";
import { GamePT } from "types/react";
import { GamePT, UGPT } from "types/react";
import { StatDisplay } from "./UGPTStatShowcase";
type Props = { reqUser: UserDocument } & GamePT;
export default function UGPTStatContainer({
stat,
reqUser,
game,
playtype,
shouldFetchCompareID,
}: { stat: ShowcaseStatDetails; shouldFetchCompareID?: integer } & Props) {
}: { stat: ShowcaseStatDetails; shouldFetchCompareID?: integer } & UGPT) {
const searchParams = new URLSearchParams();
searchParams.set("mode", stat.mode);
@@ -25,16 +25,12 @@ import {
SongDocument,
} from "tachi-common";
import { UGPTPreferenceStatsReturn } from "types/api-returns";
import { GamePT } from "types/react";
import { GamePT, UGPT } from "types/react";
import { Playtype } from "types/tachi";
import UGPTStatContainer from "./UGPTStatContainer";
import UGPTStatCreator from "./UGPTStatCreator";
export default function UGPTStatShowcase({
reqUser,
game,
playtype,
}: { reqUser: UserDocument } & GamePT) {
export default function UGPTStatShowcase({ reqUser, game, playtype }: UGPT) {
const { ugs } = useContext(AllLUGPTStatsContext);
const { user } = useContext(UserContext);
+2 -6
View File
@@ -1,12 +1,8 @@
import { useMemo } from "react";
import { UserDocument } from "tachi-common";
import { GamePT } from "types/react";
import { GamePT, UGPT } from "types/react";
export default function useUGPTBase({
reqUser,
game,
playtype,
}: { reqUser: UserDocument } & GamePT) {
export default function useUGPTBase({ reqUser, game, playtype }: UGPT) {
return useMemo(
() => `/dashboard/users/${reqUser.username}/games/${game}/${playtype}`,
[reqUser, game, playtype]
+8 -2
View File
@@ -9,7 +9,7 @@ import {
FormikTouched,
} from "formik";
import React, { Dispatch, SetStateAction } from "react";
import { Game, Playtypes } from "tachi-common";
import { Game, Playtype, UserDocument } from "tachi-common";
export interface JustChildren {
children: React.ReactNode;
@@ -87,5 +87,11 @@ export type UseFormik<Values> = {
export interface GamePT {
game: Game;
playtype: Playtypes[Game];
playtype: Playtype;
}
export interface UGPT {
reqUser: UserDocument;
game: Game;
playtype: Playtype;
}