Skip to content

Commit 2e55a2f

Browse files
committed
Format code :^)
1 parent 19bf99a commit 2e55a2f

File tree

3 files changed

+59
-37
lines changed

3 files changed

+59
-37
lines changed

app/api/orgs/[orgId]/contests/[contestId]/problems/service.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ export async function removeProblemFromContest(
5555
return await db.transaction(async (tx) => {
5656
// First, find the problem ID from the problem code
5757
const problem = await tx.query.problems.findFirst({
58-
where: and(
59-
eq(problems.orgId, orgId),
60-
eq(problems.code, problemCode)
61-
),
58+
where: and(eq(problems.orgId, orgId), eq(problems.code, problemCode)),
6259
});
6360

6461
if (!problem) {
@@ -71,8 +68,8 @@ export async function removeProblemFromContest(
7168
.where(
7269
and(
7370
eq(contestProblems.contestId, contestId),
74-
eq(contestProblems.problemId, problem.id)
75-
)
71+
eq(contestProblems.problemId, problem.id),
72+
),
7673
)
7774
.returning();
7875

components/code-editor.tsx

+53-30
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ export function CodeEditor({ problem }: CodeEditorProps) {
102102
const [executionError, setExecutionError] = useState<string | null>(null);
103103

104104
// Add this state to track test case results
105-
const [testCaseResults, setTestCaseResults] = useState<Record<number, TestCaseResult>>({});
105+
const [testCaseResults, setTestCaseResults] = useState<
106+
Record<number, TestCaseResult>
107+
>({});
106108

107109
const languageVersions = {
108110
javascript: "18.15.0",
@@ -140,7 +142,9 @@ export function CodeEditor({ problem }: CodeEditorProps) {
140142
}
141143
};
142144

143-
const runCode = async (testCaseInput: string): Promise<{success: boolean, output: string}> => {
145+
const runCode = async (
146+
testCaseInput: string,
147+
): Promise<{ success: boolean; output: string }> => {
144148
console.log("Starting code execution...");
145149
setIsRunning(true);
146150
setOutput("");
@@ -201,56 +205,61 @@ export function CodeEditor({ problem }: CodeEditorProps) {
201205
// Add this function to run a specific test case
202206
const runTestCase = async (testCase: TestCase, index: number) => {
203207
if (isRunning) return;
204-
208+
205209
const result = await runCode(testCase.input);
206-
210+
207211
// Update the results for this specific test case
208-
setTestCaseResults(prev => ({
212+
setTestCaseResults((prev) => ({
209213
...prev,
210214
[index]: {
211215
output: result.output,
212-
success: result.output.trim() === testCase.output.trim()
213-
}
216+
success: result.output.trim() === testCase.output.trim(),
217+
},
214218
}));
215-
219+
216220
// Update the overall output summary
217221
const updatedResults = {
218222
...testCaseResults,
219223
[index]: {
220224
output: result.output,
221-
success: result.output.trim() === testCase.output.trim()
222-
}
225+
success: result.output.trim() === testCase.output.trim(),
226+
},
223227
};
224-
228+
225229
const totalCases = problem.testCases?.length || 0;
226-
const passedCases = Object.values(updatedResults).filter(r => r.success).length;
227-
230+
const passedCases = Object.values(updatedResults).filter(
231+
(r) => r.success,
232+
).length;
233+
228234
setOutput(`Passed ${passedCases} of ${totalCases} test cases`);
229235
};
230236

231237
// Add a function to run all test cases
232238
const runAllTestCases = async () => {
233-
if (isRunning || !problem.testCases || problem.testCases.length === 0) return;
234-
239+
if (isRunning || !problem.testCases || problem.testCases.length === 0)
240+
return;
241+
235242
setIsRunning(true);
236243
const newResults: Record<number, TestCaseResult> = {};
237244
let passedCount = 0;
238-
245+
239246
for (let i = 0; i < problem.testCases.length; i++) {
240247
const testCase = problem.testCases[i];
241248
const result = await runCode(testCase.input);
242249
const isSuccess = result.output.trim() === testCase.output.trim();
243-
250+
244251
newResults[i] = {
245252
output: result.output,
246-
success: isSuccess
253+
success: isSuccess,
247254
};
248-
255+
249256
if (isSuccess) passedCount++;
250257
}
251-
258+
252259
setTestCaseResults(newResults);
253-
setOutput(`Passed ${passedCount} of ${problem.testCases.length} test cases`);
260+
setOutput(
261+
`Passed ${passedCount} of ${problem.testCases.length} test cases`,
262+
);
254263
setIsRunning(false);
255264
};
256265

@@ -380,13 +389,15 @@ export function CodeEditor({ problem }: CodeEditorProps) {
380389
<div key={index} className="space-y-2">
381390
<div className="flex items-center justify-between gap-2 px-2 py-1">
382391
<div className="flex items-center gap-2">
383-
<div className={`h-2 w-2 rounded-full ${testCaseResults[index]?.success ? 'bg-green-500' : testCaseResults[index] ? 'bg-red-500' : 'bg-muted'}`}></div>
392+
<div
393+
className={`h-2 w-2 rounded-full ${testCaseResults[index]?.success ? "bg-green-500" : testCaseResults[index] ? "bg-red-500" : "bg-muted"}`}
394+
></div>
384395
<span className="text-sm text-foreground">
385396
Case {index + 1}
386397
</span>
387398
</div>
388-
<Button
389-
variant="outline"
399+
<Button
400+
variant="outline"
390401
size="sm"
391402
onClick={() => runTestCase(testCase, index)}
392403
disabled={isRunning}
@@ -397,22 +408,34 @@ export function CodeEditor({ problem }: CodeEditorProps) {
397408
</div>
398409
<div className="space-y-1">
399410
<div className="bg-muted rounded p-2">
400-
<div className="text-xs text-muted-foreground mb-1">Input:</div>
411+
<div className="text-xs text-muted-foreground mb-1">
412+
Input:
413+
</div>
401414
<div className="text-sm font-mono">
402-
<span className="text-foreground">{testCase.input}</span>
415+
<span className="text-foreground">
416+
{testCase.input}
417+
</span>
403418
</div>
404419
</div>
405420
<div className="bg-muted rounded p-2">
406-
<div className="text-xs text-muted-foreground mb-1">Expected Output:</div>
421+
<div className="text-xs text-muted-foreground mb-1">
422+
Expected Output:
423+
</div>
407424
<div className="text-sm font-mono">
408-
<span className="text-foreground">{testCase.output}</span>
425+
<span className="text-foreground">
426+
{testCase.output}
427+
</span>
409428
</div>
410429
</div>
411430
{testCaseResults[index] && (
412431
<div className="bg-muted rounded p-2">
413-
<div className="text-xs text-muted-foreground mb-1">Output:</div>
432+
<div className="text-xs text-muted-foreground mb-1">
433+
Output:
434+
</div>
414435
<div className="text-sm font-mono">
415-
<span className={`${testCaseResults[index]?.success ? 'text-green-500' : 'text-red-500'}`}>
436+
<span
437+
className={`${testCaseResults[index]?.success ? "text-green-500" : "text-red-500"}`}
438+
>
416439
{testCaseResults[index]?.output}
417440
</span>
418441
</div>

lib/validations.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ export const createProblemSchema = z.object({
118118
allowedLanguages: z.array(z.string()),
119119
});
120120

121-
export const updateProblemSchema = createProblemSchema.partial().omit({ code: true });
121+
export const updateProblemSchema = createProblemSchema
122+
.partial()
123+
.omit({ code: true });
122124

123125
export const problemSchema = z.object({
124126
id: z.number().int().positive(),

0 commit comments

Comments
 (0)