Skip to content

Commit

Permalink
Update ui for mock problems in problems page
Browse files Browse the repository at this point in the history
  • Loading branch information
aahnik committed Dec 4, 2024
1 parent afdf7ee commit 1f834ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 47 deletions.
14 changes: 7 additions & 7 deletions app/[orgId]/problems/mockProblems.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export interface Problem {
id: number;
nameId: string; // 5 character alphanumeric code
title: string;
description: string;
allowedLanguages: string[];
createdAt: string;
orgId: number;
Expand All @@ -10,26 +10,26 @@ export interface Problem {
export const mockProblems: Problem[] = [
{
id: 1,
title: "Two Sum",
description:
nameId: "2SUM1",
title:
"Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.",
allowedLanguages: ["python", "javascript", "java"],
createdAt: "2024-01-01",
orgId: 1,
},
{
id: 2,
title: "String Reversal",
description:
nameId: "REVST",
title:
"Write a function that reverses a string. The input string is given as an array of characters.",
allowedLanguages: ["python", "cpp", "javascript"],
createdAt: "2024-01-02",
orgId: 1,
},
{
id: 3,
title: "Binary Search",
description:
nameId: "BSRCH",
title:
"Implement a binary search algorithm to find a target value in a sorted array.",
allowedLanguages: ["python", "typescript", "java", "cpp"],
createdAt: "2024-01-03",
Expand Down
44 changes: 4 additions & 40 deletions app/[orgId]/problems/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,23 @@ import { useToast } from "@/hooks/use-toast";
import { GenericListing, ColumnDef } from "@/mint/generic-listing";
import { GenericEditor, Field } from "@/mint/generic-editor";
import { useEffect, useState } from "react";
import { createProblemSchema } from "@/lib/validations";

// interface Problem {
// id: number;
// title: string;
// description: string;
// allowedLanguages: string[];
// createdAt: Date;
// orgId: number;
// }
import { z } from "zod";

const columns: ColumnDef<Problem>[] = [
{ header: "Problem Code", accessorKey: "nameId", sortable: true },
{ header: "Title", accessorKey: "title", sortable: true },
{ header: "Description", accessorKey: "description" },
{ header: "Allowed Languages", accessorKey: "allowedLanguages" },
{ header: "Created At", accessorKey: "createdAt", sortable: true },
];

const fields: Field[] = [
{ name: "title", label: "Title", type: "text" },
{ name: "description", label: "Description", type: "text" },
{
name: "allowedLanguages",
label: "Allowed Languages",
type: "select",
options: [
{ value: "python", label: "Python" },
{ value: "javascript", label: "JavaScript" },
{ value: "typescript", label: "TypeScript" },
{ value: "java", label: "Java" },
{ value: "cpp", label: "C++" },
],
},
];

export default function ProblemsPage({
params,
}: {
params: { orgId: string };
}) {
const [problems, setProblems] = useState<Problem[]>([]);
const [selectedProblem, setSelectedProblem] = useState<Problem | null>(null);
const [isEditorOpen, setIsEditorOpen] = useState(false);
// const [isEditorOpen, setIsEditorOpen] = useState(false);

const { toast } = useToast();

Expand Down Expand Up @@ -134,23 +108,13 @@ export default function ProblemsPage({
data={problems}
columns={columns}
title="Problems"
searchableFields={["title", "description"]}
searchableFields={["nameId", "title"]}
onAdd={handleAdd}
onEdit={handleEdit}
onDelete={handleDelete}
allowDownload={true}
addPage="new"
/>

<GenericEditor
data={selectedProblem}
isOpen={isEditorOpen}
onClose={() => setIsEditorOpen(false)}
onSave={handleSave}
schema={createProblemSchema}
fields={fields}
title="Problems"
/>
</>
);
}

0 comments on commit 1f834ff

Please sign in to comment.