Skip to content

Commit 3cecea6

Browse files
Add ViewMatchesModal component and integrate it into CompHeaderCard
1 parent c062c78 commit 3cecea6

3 files changed

Lines changed: 153 additions & 2 deletions

File tree

components/ViewMatchesModal.tsx

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import { Match, Report } from "@/lib/Types";
2+
import Card from "./Card";
3+
import { User } from "../lib/Types";
4+
import { match } from "assert";
5+
import { report } from "process";
6+
import Checkbox from "./forms/Checkboxes";
7+
import { CheckmarkIcon } from "react-hot-toast";
8+
import { useState } from "react";
9+
10+
type MatchData = {
11+
number: number;
12+
url: string;
13+
message: string;
14+
completed: boolean;
15+
subjective: boolean;
16+
};
17+
18+
function ViewMatchCard(props: MatchData) {
19+
return (
20+
<Card title={"Match " + props.number}>
21+
{props.message}
22+
<a
23+
href={props.url}
24+
className={`btn btn-sm ${props.completed ? `btn-ghost` : props.subjective ? `btn-secondary` : `btn-primary`}`}
25+
>
26+
{props.completed ? "Submitted" : "Click to scout"}
27+
</a>
28+
</Card>
29+
);
30+
}
31+
export default function ViewMatchesModal(props: {
32+
close: () => void;
33+
matches: Match[];
34+
reports: Report[];
35+
user: User;
36+
matchPathway: string;
37+
}) {
38+
const reportsById: { [id: string]: Report } = {};
39+
const myMatches: MatchData[] = [];
40+
const [showSubmittedReports, setShowSubmittedReports] = useState(false);
41+
42+
async function toggleShowSubmittedReports() {
43+
setShowSubmittedReports(!showSubmittedReports);
44+
}
45+
46+
for (const report of props.reports) {
47+
reportsById[report._id?.toString()!] = report;
48+
}
49+
50+
for (const match of props.matches) {
51+
if (match.subjectiveScouter == props.user._id?.toString()) {
52+
myMatches.push({
53+
number: match.number,
54+
url: props.matchPathway + `/${match._id}/subjective`,
55+
message: "You are subjective scouting match " + match.number + ".",
56+
completed: match.assignedSubjectiveScouterHasSubmitted,
57+
subjective: true,
58+
});
59+
}
60+
61+
for (const report of match.reports) {
62+
if (reportsById[report]?.user == props.user._id?.toString()) {
63+
myMatches.push({
64+
number: match.number,
65+
url: props.matchPathway + `/${report.toString()}`,
66+
message:
67+
"You are scouting team " +
68+
reportsById[report].robotNumber +
69+
" in match " +
70+
match.number +
71+
".",
72+
completed: reportsById[report].submitted,
73+
subjective: false,
74+
});
75+
}
76+
}
77+
}
78+
79+
return (
80+
<dialog
81+
open={true}
82+
className="modal"
83+
>
84+
<Card title="My Matches">
85+
<div className="absolute right-2 top-2 flex gap-4 items-center">
86+
<div className="flex gap-2">
87+
<div>Show Submitted Reports</div>
88+
<input
89+
type="checkbox"
90+
onChange={toggleShowSubmittedReports}
91+
className="checkbox checkbox-primary"
92+
/>
93+
</div>
94+
<button
95+
className="btn btn-sm btn-circle btn-ghost "
96+
onClick={props.close}
97+
>
98+
99+
</button>
100+
</div>
101+
<div className="overflow-y-scroll h-[650px]">
102+
{myMatches
103+
.filter((matchData) => showSubmittedReports || !matchData.completed)
104+
.map((matchData) => (
105+
<ViewMatchCard {...matchData} />
106+
))}
107+
</div>
108+
</Card>
109+
</dialog>
110+
);
111+
}

components/competition/CompHeaderCard.tsx

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
11
import { NotLinkedToTba } from "@/lib/client/ClientUtils";
2-
import { Competition } from "@/lib/Types";
2+
import { Competition, Match, Report } from "@/lib/Types";
3+
import { useState } from "react";
34
import { BiExport } from "react-icons/bi";
5+
import { FaCalendarDay } from "react-icons/fa";
46
import { MdAutoGraph, MdQueryStats, MdCoPresent } from "react-icons/md";
7+
import ViewMatchesModal from "../ViewMatchesModal";
8+
import { User } from "../../lib/Types";
59

610
export default function CompHeaderCard({
711
comp,
12+
matches,
13+
reports,
14+
user,
15+
matchPathway,
816
}: {
917
comp: Competition | undefined;
18+
matches: Match[];
19+
reports: Report[];
20+
user: User | null;
21+
matchPathway: string;
1022
}) {
23+
const [viewMatches, setViewMatches] = useState(false);
24+
25+
async function toggleViewMatches() {
26+
setViewMatches(!viewMatches);
27+
}
28+
1129
return (
1230
<div className="w-full card bg-base-200 shadow-xl">
1331
<div className="card-body">
@@ -36,8 +54,24 @@ export default function CompHeaderCard({
3654
>
3755
Pit Stats <MdCoPresent size={30} />
3856
</a>
57+
<div className="divider divider-horizontal"></div>
58+
<button
59+
className="max-sm:w-full btn btn-primary"
60+
onClick={toggleViewMatches}
61+
>
62+
My Matches <FaCalendarDay size={30} />
63+
</button>
3964
</div>
4065
</div>
66+
{viewMatches && user && (
67+
<ViewMatchesModal
68+
close={toggleViewMatches}
69+
matches={matches}
70+
reports={reports}
71+
user={user}
72+
matchPathway={matchPathway}
73+
/>
74+
)}
4175
</div>
4276
);
4377
}

pages/[teamSlug]/[seasonSlug]/[competitonSlug]/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,13 @@ export default function CompetitionIndex({
405405
>
406406
<div className="min-h-screen w-full flex flex-col sm:flex-row flex-grow justify-center sm:space-x-6 my-4">
407407
<div className="w-full sm:w-2/5 flex flex-col items-center flex-grow justify-center space-y-4 h-full">
408-
<CompHeaderCard comp={comp} />
408+
<CompHeaderCard
409+
comp={comp}
410+
reports={reports}
411+
matches={matches}
412+
user={session?.user}
413+
matchPathway={`/${team?.slug}/${season?.slug}/${comp?.slug}`}
414+
/>
409415
<InsightsAndSettingsCard
410416
isManager={isManager}
411417
comp={comp}

0 commit comments

Comments
 (0)