-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
173 lines (158 loc) · 6.18 KB
/
index.js
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
165
166
167
168
169
170
171
172
173
import React, { useState } from 'react';
import { Slider } from '@/components/ui/slider';
import { Button } from '@/components/ui/button';
import { Card, CardHeader, CardContent } from '@/components/ui/card';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
const categories = ['Travelling', 'Buckness', 'Storytelling', 'Character', 'Basics', 'Liveness', 'Musicality'];
const KrumperScoreCard = ({ krumper, judgeNumber, onScoreChange, scores }) => {
const handleSliderChange = (category, value) => {
onScoreChange(`judge${judgeNumber}`, krumper, category, value[0]);
};
return (
<Card className="mb-4">
<CardHeader>Judge {judgeNumber} - Krumper {krumper}</CardHeader>
<CardContent>
{categories.map((category) => (
<div key={category} className="mb-4">
<label className="block mb-2">{category}: {scores[category] || 0}</label>
<Slider
min={0}
max={5}
step={1}
value={[scores[category] || 0]}
onValueChange={(value) => handleSliderChange(category, value)}
/>
</div>
))}
</CardContent>
</Card>
);
};
const KrumpJudgingApp = () => {
const [rounds, setRounds] = useState(1);
const [currentRound, setCurrentRound] = useState(1);
const [scores, setScores] = useState({
1: { A: { judge1: {}, judge2: {}, judge3: {} }, B: { judge1: {}, judge2: {}, judge3: {} } },
2: { A: { judge1: {}, judge2: {}, judge3: {} }, B: { judge1: {}, judge2: {}, judge3: {} } },
3: { A: { judge1: {}, judge2: {}, judge3: {} }, B: { judge1: {}, judge2: {}, judge3: {} } },
});
const [winner, setWinner] = useState(null);
const [finalScores, setFinalScores] = useState({ A: 0, B: 0 });
const [isJudgingComplete, setIsJudgingComplete] = useState(false);
const handleScoreChange = (judge, krumper, category, value) => {
setScores((prevScores) => ({
...prevScores,
[currentRound]: {
...prevScores[currentRound],
[krumper]: {
...prevScores[currentRound][krumper],
[judge]: {
...prevScores[currentRound][krumper][judge],
[category]: value,
},
},
},
}));
};
const calculateTotalScore = (roundScores) => {
return Object.values(roundScores).reduce((total, judgeScores) => {
return total + Object.values(judgeScores).reduce((sum, score) => sum + Object.values(score).reduce((catSum, catScore) => catSum + (catScore || 0), 0), 0);
}, 0);
};
const determineWinner = () => {
let totalScores = { A: 0, B: 0 };
for (let round = 1; round <= rounds; round++) {
totalScores.A += calculateTotalScore(scores[round].A);
totalScores.B += calculateTotalScore(scores[round].B);
}
setFinalScores(totalScores);
if (totalScores.A > totalScores.B) {
setWinner('Krumper A');
} else if (totalScores.B > totalScores.A) {
setWinner('Krumper B');
} else {
setWinner('Tie');
}
setIsJudgingComplete(true);
};
const nextRound = () => {
if (currentRound < rounds) {
setCurrentRound(currentRound + 1);
} else {
determineWinner();
}
};
const resetJudging = () => {
setCurrentRound(1);
setScores({
1: { A: { judge1: {}, judge2: {}, judge3: {} }, B: { judge1: {}, judge2: {}, judge3: {} } },
2: { A: { judge1: {}, judge2: {}, judge3: {} }, B: { judge1: {}, judge2: {}, judge3: {} } },
3: { A: { judge1: {}, judge2: {}, judge3: {} }, B: { judge1: {}, judge2: {}, judge3: {} } },
});
setWinner(null);
setFinalScores({ A: 0, B: 0 });
setIsJudgingComplete(false);
};
return (
<div className="p-4">
<h1 className="text-2xl font-bold mb-4">Krump Judging App</h1>
{!isJudgingComplete && (
<>
<div className="mb-4">
<label className="block mb-2">Number of Rounds:</label>
<Select onValueChange={(value) => setRounds(parseInt(value))}>
<SelectTrigger className="w-32">
<SelectValue placeholder="Rounds" />
</SelectTrigger>
<SelectContent>
<SelectItem value="1">1</SelectItem>
<SelectItem value="2">2</SelectItem>
<SelectItem value="3">3</SelectItem>
</SelectContent>
</Select>
</div>
<h2 className="text-xl font-semibold mb-4">Round {currentRound}</h2>
<Tabs defaultValue="judge1">
<TabsList>
<TabsTrigger value="judge1">Judge 1</TabsTrigger>
<TabsTrigger value="judge2">Judge 2</TabsTrigger>
<TabsTrigger value="judge3">Judge 3</TabsTrigger>
</TabsList>
{['judge1', 'judge2', 'judge3'].map((judge, index) => (
<TabsContent key={judge} value={judge}>
<div className="flex space-x-4">
<KrumperScoreCard
krumper="A"
judgeNumber={index + 1}
onScoreChange={handleScoreChange}
scores={scores[currentRound].A[judge]}
/>
<KrumperScoreCard
krumper="B"
judgeNumber={index + 1}
onScoreChange={handleScoreChange}
scores={scores[currentRound].B[judge]}
/>
</div>
</TabsContent>
))}
</Tabs>
<Button onClick={nextRound} className="mt-4">
{currentRound < rounds ? 'Next Round' : 'Finish and Determine Winner'}
</Button>
</>
)}
{isJudgingComplete && (
<div className="mt-4">
<h2 className="text-xl font-semibold mb-2">Final Results</h2>
<p className="mb-2">Krumper A Total Score: {finalScores.A}</p>
<p className="mb-2">Krumper B Total Score: {finalScores.B}</p>
<h3 className="text-lg font-semibold mb-4">Winner: {winner}</h3>
<Button onClick={resetJudging} className="mt-2">Start New Judging</Button>
</div>
)}
</div>
);
};
export default KrumpJudgingApp;