-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpage.tsx
More file actions
71 lines (61 loc) · 1.53 KB
/
Copy pathpage.tsx
File metadata and controls
71 lines (61 loc) · 1.53 KB
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
"use client";
import { CodeEditor } from "@/components/code-editor";
import { notFound } from "next/navigation";
import { useEffect, useState } from "react";
export default function Page({
params,
}: {
params: { orgId: string; id: string; problemId: string };
}) {
const [problem, setProblem] = useState(null);
useEffect(() => {
async function getProblem(
orgId: string,
contestId: string,
problemId: string,
) {
console.log(
`ENV: ${process.env.NEXT_PUBLIC_APP_URL}`,
orgId,
contestId,
problemId,
);
try {
// Fetch the problem with contest context
const response = await fetch(
`/api/orgs/${orgId}/contests/${contestId}/problems/${problemId}`,
{
cache: "no-store",
},
);
if (!response.ok) {
throw new Error("Failed to fetch problem");
}
const problem = await response.json();
// Add the contest ID to the problem data
return {
...problem,
contestNameId: contestId,
orgId,
};
} catch (error) {
console.error("Error fetching problem:", error);
return null;
}
}
getProblem(params.orgId, params.id, params.problemId).then((result) => {
if (!result) {
notFound();
}
setProblem(result);
});
}, [params.orgId, params.id, params.problemId]);
if (!problem) {
return null;
}
return (
<>
<CodeEditor problem={problem} />
</>
);
}