|
| 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 | +} |
0 commit comments