Skip to content

Commit 19dc8ba

Browse files
author
Vincent Zheng
committed
rename MatchProfile to MatchDetails, stop click events from ScrimHistoryTable links from opening MatchDetails
1 parent 3cc2f2c commit 19dc8ba

File tree

7 files changed

+76
-46
lines changed

7 files changed

+76
-46
lines changed

frontend/src/App.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ import CodeOfConduct from "views/CodeOfConduct";
6060
import Client from "views/Client";
6161
import AdminTournament from "views/AdminTournament";
6262
import { adminTournamentLoader } from "api/loaders/adminTournamentLoader";
63-
import MatchProfile from "views/MatchProfile";
64-
import { matchProfileLoader } from "api/loaders/matchProfileLoader";
63+
import { matchDetailsLoader } from "api/loaders/matchDetailsLoader";
64+
import MatchDetails from "views/MatchDetails";
6565

6666
const queryClient = new QueryClient({
6767
queryCache: new QueryCache({
@@ -182,8 +182,8 @@ const router = createBrowserRouter([
182182
},
183183
{
184184
path: "match/:matchId",
185-
element: <MatchProfile />,
186-
loader: matchProfileLoader(queryClient),
185+
element: <MatchDetails />,
186+
loader: matchDetailsLoader(queryClient),
187187
},
188188
],
189189
},

frontend/src/api/_autogen/models/Submission.ts

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/* tslint:disable */
22
/* eslint-disable */
33
/**
4-
*
4+
*
55
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
66
*
77
* The version of the OpenAPI document: 0.0.0
8-
*
8+
*
99
*
1010
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
1111
* https://openapi-generator.tech
@@ -21,79 +21,79 @@ import {
2121
} from './StatusBccEnum';
2222

2323
/**
24-
*
24+
*
2525
* @export
2626
* @interface Submission
2727
*/
2828
export interface Submission {
2929
/**
30-
*
30+
*
3131
* @type {number}
3232
* @memberof Submission
3333
*/
3434
readonly id: number;
3535
/**
36-
*
36+
*
3737
* @type {StatusBccEnum}
3838
* @memberof Submission
3939
*/
4040
readonly status: StatusBccEnum;
4141
/**
42-
*
42+
*
4343
* @type {string}
4444
* @memberof Submission
4545
*/
4646
readonly logs: string;
4747
/**
48-
*
48+
*
4949
* @type {string}
5050
* @memberof Submission
5151
*/
5252
readonly episode: string;
5353
/**
54-
*
54+
*
5555
* @type {number}
5656
* @memberof Submission
5757
*/
5858
readonly team: number;
5959
/**
60-
*
60+
*
6161
* @type {string}
6262
* @memberof Submission
6363
*/
6464
readonly teamname: string;
6565
/**
66-
*
66+
*
6767
* @type {number}
6868
* @memberof Submission
6969
*/
7070
readonly user: number;
7171
/**
72-
*
72+
*
7373
* @type {string}
7474
* @memberof Submission
7575
*/
7676
readonly username: string;
7777
/**
78-
*
78+
*
7979
* @type {Date}
8080
* @memberof Submission
8181
*/
8282
readonly created: Date;
8383
/**
84-
*
84+
*
8585
* @type {boolean}
8686
* @memberof Submission
8787
*/
8888
readonly accepted: boolean;
8989
/**
90-
*
90+
*
9191
* @type {string}
9292
* @memberof Submission
9393
*/
9494
_package?: string;
9595
/**
96-
*
96+
*
9797
* @type {string}
9898
* @memberof Submission
9999
*/
@@ -128,7 +128,7 @@ export function SubmissionFromJSONTyped(json: any, ignoreDiscriminator: boolean)
128128
return json;
129129
}
130130
return {
131-
131+
132132
'id': json['id'],
133133
'status': StatusBccEnumFromJSON(json['status']),
134134
'logs': json['logs'],
@@ -152,9 +152,8 @@ export function SubmissionToJSON(value?: Submission | null): any {
152152
return null;
153153
}
154154
return {
155-
155+
156156
'package': value._package,
157157
'description': value.description,
158158
};
159159
}
160-

frontend/src/api/loaders/matchProfileLoader.ts renamed to frontend/src/api/loaders/matchDetailsLoader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { safeEnsureQueryData } from "api/helpers";
44
import type { LoaderFunction } from "react-router-dom";
55
import { isPresent } from "utils/utilTypes";
66

7-
export const matchProfileLoader =
7+
export const matchDetailsLoader =
88
(queryClient: QueryClient): LoaderFunction =>
99
({ params }) => {
1010
const { episodeId, id } = params;

frontend/src/api/team/useTeam.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import {
3535
import { buildKey } from "../helpers";
3636
import { userRatingHistoryFactory } from "api/compete/competeFactories";
3737
import { competeQueryKeys } from "api/compete/competeKeys";
38-
import { MILLIS_SECOND } from "utils/utilTypes";
38+
import { type Maybe, MILLIS_SECOND } from "utils/utilTypes";
3939

4040
// ---------- QUERY HOOKS ---------- //
4141
const SEARCH_WAIT_SECONDS = 30;
@@ -129,14 +129,17 @@ export const useCreateTeam = (
129129
export const useJoinTeam = (
130130
{ episodeId }: { episodeId: string },
131131
queryClient: QueryClient,
132-
): UseMutationResult<void, Error, TeamJoinRequest> =>
133-
useMutation({
132+
): UseMutationResult<void, Error, TeamJoinRequest> => {
133+
let err: Maybe<string> = undefined;
134+
const getErr = (): string => err ?? "Error joining team.";
135+
136+
return useMutation({
134137
mutationKey: teamMutationKeys.join({ episodeId }),
135138
mutationFn: async (teamJoinRequest: TeamJoinRequest) => {
136139
await toast.promise(joinTeam({ episodeId, teamJoinRequest }), {
137140
loading: "Joining team...",
138141
success: "Joined team!",
139-
error: "Error joining team.",
142+
error: getErr,
140143
});
141144
},
142145
onSuccess: async () => {
@@ -153,7 +156,12 @@ export const useJoinTeam = (
153156
queryKey: competeQueryKeys.scrimBase.key({ episodeId }),
154157
});
155158
},
159+
onError: (error) => {
160+
err = `${error.name}: ${error.message}`;
161+
console.log(err);
162+
},
156163
});
164+
};
157165

158166
/**
159167
* Leave the user's current team in a given episode.

frontend/src/components/MatchReplayButton.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ const MatchReplayButton: React.FC<MatchReplayButtonProps> = ({
3232
<Button
3333
disabled={disabled || !isPresent(clientUrl)}
3434
label="Replay!"
35-
onClick={() => {
35+
onClick={(e) => {
3636
if (isPresent(clientUrl)) {
3737
window.open(clientUrl);
3838
}
39+
e.stopPropagation();
3940
}}
4041
/>
4142
);

frontend/src/components/compete/TeamWithRating.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ const TeamWithRating: React.FC<TeamWithRatingProps> = ({
5252

5353
return (
5454
<>
55-
<NavLink to={`/${episodeId}/team/${teamId}`} className="hover:underline">
55+
<NavLink
56+
to={`/${episodeId}/team/${teamId}`}
57+
className="hover:underline"
58+
onClick={(e) => {
59+
e.stopPropagation();
60+
}}
61+
>
5662
{includeTeamName && <span>{teamName}</span>}
5763
{ratingComponent}
5864
</NavLink>
Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,63 @@ import type React from "react";
22

33
import { NavLink, useParams } from "react-router-dom";
44

5-
import { useMatchInfo, useSubmissionInfo } from "api/compete/useCompete";
5+
import { useMatchInfo } from "api/compete/useCompete";
66
import { useEpisodeId } from "contexts/EpisodeContext";
77

88
import { PageTitle } from "components/elements/BattlecodeStyle";
99
import SectionCard from "components/SectionCard";
1010

11-
import type { Submission } from "api/_autogen";
11+
import type { Match, TeamPrivate } from "api/_autogen";
1212
import { useUserTeam } from "api/team/useTeam";
1313
import { isPresent } from "utils/utilTypes";
1414
import PageNotFound from "./PageNotFound";
15-
import type { UseQueryResult } from "@tanstack/react-query";
15+
import { useQuery, type UseQueryResult } from "@tanstack/react-query";
1616
import { dateTime } from "utils/dateTime";
17+
import { buildKey } from "api/helpers";
18+
import { submissionInfoFactory } from "api/compete/competeFactories";
1719

18-
const MatchProfile: React.FC = () => {
20+
const MatchDetails: React.FC = () => {
1921
const { episodeId } = useEpisodeId();
2022
const { matchId } = useParams();
2123
const teamData = useUserTeam({ episodeId });
2224
const match = useMatchInfo({ episodeId, id: matchId ?? "" });
2325

24-
const getUserSubmission = (): UseQueryResult<Submission> | undefined => {
25-
if (!isPresent(match.data?.participants) || !isPresent(teamData.data))
26-
return undefined;
26+
const getUserSubmissionId = (
27+
match: UseQueryResult<Match>,
28+
team: UseQueryResult<TeamPrivate>,
29+
): string => {
30+
if (!isPresent(match.data?.participants) || !isPresent(team.data))
31+
return "";
2732

28-
const id = match.data?.participants
29-
.find((participant) => participant.team === teamData.data?.id)
30-
?.submission.toString();
31-
32-
if (!isPresent(id)) return undefined;
33-
34-
return useSubmissionInfo({ episodeId, id });
33+
return (
34+
match.data?.participants
35+
.find((participant) => participant.team === team.data?.id)
36+
?.submission.toString() ?? ""
37+
);
3538
};
3639

37-
const submission = getUserSubmission();
40+
const id = getUserSubmissionId(match, teamData);
41+
42+
const submission = useQuery({
43+
queryKey: buildKey(submissionInfoFactory.queryKey, {
44+
episodeId,
45+
id,
46+
}),
47+
queryFn: async () =>
48+
await submissionInfoFactory.queryFn({
49+
episodeId,
50+
id,
51+
}),
52+
enabled: id.length !== 0,
53+
});
3854

3955
if (match.isError) {
4056
return <PageNotFound />;
4157
}
4258

4359
return (
4460
<div className="p-6">
45-
<PageTitle>Match Profile</PageTitle>
61+
<PageTitle>Match Details</PageTitle>
4662
<div className="flex h-full w-full flex-col overflow-auto">
4763
<SectionCard title="Submission" loading={match.isLoading}>
4864
{isPresent(submission) && submission.isSuccess && (
@@ -80,4 +96,4 @@ const MatchProfile: React.FC = () => {
8096
);
8197
};
8298

83-
export default MatchProfile;
99+
export default MatchDetails;

0 commit comments

Comments
 (0)