Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/[orgId]/contests/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,11 @@ export default function ContestDetailsPage() {
<div className="flex flex-col space-y-2">
<div className="flex items-center text-muted-foreground">
<CalendarIcon className="mr-2 h-4 w-4" />
<span>Start: {formatDate(contestData.startTime)}</span>
<span>Starts {formatDate(contestData.startTime)}</span>
</div>
<div className="flex items-center text-muted-foreground">
<ClockIcon className="mr-2 h-4 w-4" />
<span>End: {formatDate(contestData.endTime)}</span>
<span>Ends {formatDate(contestData.endTime)}</span>
</div>
</div>

Expand Down
6 changes: 5 additions & 1 deletion app/[orgId]/problems/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useEffect, useState, useCallback } from "react";
import { formatValidationErrors } from "@/utils/error";
import { useRouter } from "next/navigation";
import { MockAlert } from "@/components/mock-alert";
import { timeAgo } from "@/lib/utils";

const columns: ColumnDef<Problem>[] = [
{ header: "Problem Code", accessorKey: "code", sortable: true },
Expand All @@ -33,6 +34,9 @@ export default function ProblemsPage({
throw new Error(formatValidationErrors(errorData));
}
const data = await response.json();
for (const problem of data) {
problem.createdAt = timeAgo(problem.createdAt);
}
setProblems(data);
setShowMockAlert(false);
} catch (error) {
Expand All @@ -49,7 +53,7 @@ export default function ProblemsPage({
const handleDelete = async (problem: Problem) => {
try {
const response = await fetch(
`/api/orgs/${params.orgId}/problems/${problem.nameId}`,
`/api/orgs/${params.orgId}/problems/${problem.code}`,
{
method: "DELETE",
},
Expand Down
17 changes: 15 additions & 2 deletions app/[orgId]/submissions/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,27 @@ export default function SubmissionsPage({
const fetchSubmissions = useCallback(async () => {
try {
const response = await fetch(`/api/orgs/${params.orgId}/submissions`);
console.log("submission", response);

if (!response.ok) {
const errorData = await response.json().catch(() => ({}));
throw new Error(formatValidationErrors(errorData));
}
const data = await response.json();
setSubmissions(data);
console.log("submission", data);

const submissions = data.map((submission: any) => ({
id: submission.id,
userNameId: submission.user.nameId,
contestNameId: submission.contest.nameId,
contestProblemNameId: submission.problem.id,
language: submission.language,
status: submission.status,
submittedAt: timeAgo(submission.submittedAt),
executionTime: submission.executionTime,
memoryUsage: submission.memoryUsage,
}));

setSubmissions(submissions);
setShowMockAlert(false);
} catch (error) {
console.error("Error fetching submissions:", error);
Expand Down
5 changes: 5 additions & 0 deletions app/[orgId]/users/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ export default function UsersPage({
throw new Error(formatValidationErrors(errorData));
}
const data: User[] = makeJoinedAtReadable(await response.json());
for (const user of data) {
if (!user.about) {
user.about = "No description";
}
}
setUsers(data);
setShowMockAlert(false);
} catch (error) {
Expand Down
1 change: 1 addition & 0 deletions app/api/orgs/[orgId]/users/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export async function getOrgUsers(orgId: number) {
id: users.id,
name: users.name,
nameId: users.nameId,
email: users.email,
avatar: users.avatar,
about: users.about,
role: memberships.role,
Expand Down
30 changes: 20 additions & 10 deletions components/code-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -330,18 +330,22 @@ export function CodeEditor({ problem }: CodeEditorProps) {
}

const result = await response.json();

// Format the submission result with verdict
const status = result.status || "pending";
const statusColor = status === "accepted" ? "text-green-500" :
status === "rejected" ? "text-red-500" :
"text-yellow-500";

const executionInfo = result.executionTime ?
`\nExecution Time: ${result.executionTime}ms | Memory: ${result.memoryUsage || 'N/A'} KB` : '';

const statusColor =
status === "accepted"
? "text-green-500"
: status === "rejected"
? "text-red-500"
: "text-yellow-500";

const executionInfo = result.executionTime
? `\nExecution Time: ${result.executionTime}ms | Memory: ${result.memoryUsage || "N/A"} KB`
: "";

setOutput(
`<span class="${statusColor} font-bold text-lg">${status.toUpperCase()}</span>${executionInfo}`
`<span class="${statusColor} font-bold text-lg">${status.toUpperCase()}</span>${executionInfo}`,
);
} catch (error) {
setOutput(`Submission error: ${(error as Error).message}`);
Expand Down Expand Up @@ -537,7 +541,13 @@ export function CodeEditor({ problem }: CodeEditorProps) {
{executionError ? (
<div className="text-red-500">{output}</div>
) : (
<div dangerouslySetInnerHTML={{ __html: output || "Run your code to see the test results..." }}></div>
<div
dangerouslySetInnerHTML={{
__html:
output ||
"Run your code to see the test results...",
}}
></div>
)}
</div>
</div>
Expand Down
12 changes: 6 additions & 6 deletions components/theme-toggler-frame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ export default function ThemeTogglerFrame({
<div className="min-h-screen">
<div className="container mx-auto p-4">
<div className="flex justify-end mb-4 items-center gap-2">
{theme === "dark" && (
<Sun className="h-4 w-4 text-muted-foreground hover:text-foreground transition-colors" />
)}
{
/* theme === "dark" && */ <Sun className="h-4 w-4 text-muted-foreground hover:text-foreground transition-colors" />
}
<Switch
checked={theme === "dark"}
onCheckedChange={(checked) => setTheme(checked ? "dark" : "light")}
/>
{theme === "light" && (
<Moon className="h-4 w-4 text-muted-foreground hover:text-foreground transition-colors" />
)}
{
/* theme === "light" && */ <Moon className="h-4 w-4 text-muted-foreground hover:text-foreground transition-colors" />
}
</div>
</div>
{children}
Expand Down
6 changes: 3 additions & 3 deletions contexts/auth-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interface AuthContextType {
) => Promise<User>;
logout: () => Promise<void>;
isAuthenticated: boolean;
setIsAuthenticated: (status: boolean) => void;
// setIsAuthenticated: (status: boolean) => void;
isLoading: boolean;
refreshUser: () => Promise<void>;
}
Expand All @@ -41,7 +41,7 @@ const defaultContext: AuthContextType = {
register: async () => Promise.reject("Not implemented"),
logout: async () => Promise.reject("Not implemented"),
isAuthenticated: false,
setIsAuthenticated: () => {},
// setIsAuthenticated: () => {},
isLoading: true,
refreshUser: async () => Promise.reject("Not implemented"),
};
Expand Down Expand Up @@ -154,7 +154,7 @@ export const AuthProvider: React.FC<{ children: ReactNode }> = ({
register,
logout,
isAuthenticated,
setIsAuthenticated,
// setIsAuthenticated,
isLoading,
refreshUser,
}}
Expand Down
11 changes: 8 additions & 3 deletions middleware/cors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export function corsMiddleware(request: NextRequest) {
return new NextResponse(null, {
status: 204,
headers: {
"Access-Control-Allow-Origin": isAllowedOrigin ? origin : allowedOrigins[0],
"Access-Control-Allow-Origin": isAllowedOrigin
? origin
: allowedOrigins[0],
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization",
"Access-Control-Max-Age": "86400",
Expand All @@ -42,7 +44,10 @@ export function corsMiddleware(request: NextRequest) {
"Access-Control-Allow-Methods",
"GET, POST, PUT, DELETE, OPTIONS",
);
response.headers.set("Access-Control-Allow-Headers", "Content-Type, Authorization");
response.headers.set(
"Access-Control-Allow-Headers",
"Content-Type, Authorization",
);

return response;
}
}
10 changes: 6 additions & 4 deletions scripts/create-superuser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ async function main() {
console.log("\n=== Create Superuser ===\n");

// First, clear the database
const shouldClear = await prompt(
"This will clear ALL data in the database. Continue? (y/n): ",
);
if (shouldClear.toLowerCase() !== "y") {
const shouldClear = await prompt<{ shouldClear: boolean }>({
type: "confirm",
name: "shouldClear",
message: "This will clear ALL data in the database. Continue? (y/n): ",
});
if (!shouldClear.shouldClear) {
console.log("Operation cancelled.");
process.exit(0);
}
Expand Down
Loading