aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/app/components/GolfWatchApps/GolfWatchAppGaming.tsx
blob: c4c3a5397d24a44c3343aec25cc445f6ca706fa8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import { faArrowDown } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { PlayerInfo } from "../../models/PlayerInfo";
import BorderedContainer from "../BorderedContainer";
import ExecStatusIndicatorIcon from "../ExecStatusIndicatorIcon";
import SubmitStatusLabel from "../SubmitStatusLabel";

type Props = {
	gameDisplayName: string;
	gameDurationSeconds: number;
	leftTimeSeconds: number;
	playerInfoA: PlayerInfo;
	playerInfoB: PlayerInfo;
	problemTitle: string;
	problemDescription: string;
};

export default function GolfWatchAppGaming({
	gameDisplayName,
	gameDurationSeconds,
	leftTimeSeconds,
	playerInfoA,
	playerInfoB,
}: Props) {
	const leftTime = (() => {
		const k = gameDurationSeconds + leftTimeSeconds;
		const m = Math.floor(k / 60);
		const s = k % 60;
		return `${m.toString().padStart(2, "0")}:${s.toString().padStart(2, "0")}`;
	})();

	const scoreRatio = (() => {
		const scoreA = playerInfoA.score;
		const scoreB = playerInfoB.score;
		if (scoreA === null && scoreB === null) {
			return 50;
		} else if (scoreA === null) {
			return 0;
		} else if (scoreB === null) {
			return 100;
		} else {
			return (scoreB / (scoreA + scoreB)) * 100;
		}
	})();

	return (
		<div className="min-h-screen bg-gray-100 flex flex-col">
			<div className="text-white bg-iosdc-japan grid grid-cols-3 px-4 py-2">
				<div className="font-bold flex justify-between my-auto">
					<div>
						<div className="text-gray-100">Player 1</div>
						<div className="text-2xl">{playerInfoA.displayName}</div>
					</div>
					<div className="text-6xl">{playerInfoA.score}</div>
				</div>
				<div className="font-bold text-center">
					<div className="text-gray-100">{gameDisplayName}</div>
					<div className="text-3xl">{leftTime}</div>
				</div>
				<div className="font-bold flex justify-between my-auto">
					<div className="text-6xl">{playerInfoB.score}</div>
					<div>
						<div className="text-gray-100">Player 2</div>
						<div className="text-2xl">{playerInfoB.displayName}</div>
					</div>
				</div>
			</div>
			<div className="w-full bg-purple-400">
				<div
					className="h-6 bg-orange-400"
					style={{ width: `${scoreRatio}%` }}
				></div>
			</div>
			<div className="grow grid grid-cols-10 p-4 gap-4">
				<div className="col-span-3">
					<pre className="bg-white resize-none h-full w-full rounded-lg border border-gray-300 p-2">
						<code>{playerInfoA.code}</code>
					</pre>
				</div>
				<div className="col-span-2 flex flex-col gap-4">
					<div className="flex">
						<div className="grow font-bold text-xl text-center">
							<SubmitStatusLabel status={playerInfoA.submitResult.status} />
						</div>
					</div>
					<ul className="flex flex-col gap-2">
						{playerInfoA.submitResult.execResults.map((r, idx) => (
							<li key={r.testcase_id ?? -1} className="flex gap-2">
								<div className="flex flex-col gap-2 p-2">
									<div className="w-6">
										<ExecStatusIndicatorIcon status={r.status} />
									</div>
									{idx !== playerInfoA.submitResult.execResults.length - 1 && (
										<div>
											<FontAwesomeIcon
												icon={faArrowDown}
												fixedWidth
												className="text-gray-500"
											/>
										</div>
									)}
								</div>
								<div className="grow p-2 overflow-x-scroll">
									<BorderedContainer>
										<div className="font-semibold">{r.label}</div>
										<div>
											<code>
												{r.stdout}
												{r.stderr}
											</code>
										</div>
									</BorderedContainer>
								</div>
							</li>
						))}
					</ul>
				</div>
				<div className="col-span-2 flex flex-col gap-4">
					<div className="flex">
						<div className="grow font-bold text-xl text-center">
							<SubmitStatusLabel status={playerInfoB.submitResult.status} />
						</div>
					</div>
					<ul className="flex flex-col gap-2">
						{playerInfoB.submitResult.execResults.map((r, idx) => (
							<li key={r.testcase_id ?? -1} className="flex gap-2">
								<div className="flex flex-col gap-2 p-2">
									<div className="w-6">
										<ExecStatusIndicatorIcon status={r.status} />
									</div>
									{idx !== playerInfoB.submitResult.execResults.length - 1 && (
										<div>
											<FontAwesomeIcon
												icon={faArrowDown}
												fixedWidth
												className="text-gray-500"
											/>
										</div>
									)}
								</div>
								<div className="grow p-2 overflow-x-scroll">
									<BorderedContainer>
										<div className="font-semibold">{r.label}</div>
										<div>
											<code>
												{r.stdout}
												{r.stderr}
											</code>
										</div>
									</BorderedContainer>
								</div>
							</li>
						))}
					</ul>
				</div>
				<div className="col-span-3">
					<pre className="bg-white resize-none h-full w-full rounded-lg border border-gray-300 p-2">
						<code>{playerInfoB.code}</code>
					</pre>
				</div>
			</div>
		</div>
	);
}