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
67 changes: 21 additions & 46 deletions src/components/Tables/ProblemTables/MyProblemsTable.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ColumnDef } from "@tanstack/react-table";
import {
Check,
FileSpreadsheet,
MoreHorizontal,
Tally4,
Tally5,
Timer,
X
Check,
FileSpreadsheet,
MoreHorizontal,
Tally4,
Tally5,
Timer,
X
} from "lucide-react";
import { Link } from "react-router-dom";
import { ProgrammingLanguageOptions } from "../../../constants/ProgrammingLanguage";
Expand All @@ -16,7 +16,6 @@ import { readableDateFormat } from "../../../utilities/ReadableDateFormat";
import MyProblemDropdown from "../../Dropdowns/MyProblemDropdown";
import { DataTable } from "../Prototype/DataTable";
import DataTableSortableLayout from "../Prototype/DataTableSortableLayout";
import DifficultyBadge from "../../DifficultyBadge";

const columns: ColumnDef<ProblemPopulateTestcases>[] = [
{
Expand Down Expand Up @@ -74,30 +73,6 @@ const columns: ColumnDef<ProblemPopulateTestcases>[] = [
</div>
),
},

// {
// accessorKey: "status",
// header: "Status",
// cell: ({ row }) => {
// return (
// <div className="">
// <CheckBadge checked={row.original.solution !== ""}>
// Source Code
// </CheckBadge>
// <span className="mx-1">
// <CheckBadge checked={row.original.testcases.length > 0}>
// Testcases
// </CheckBadge>
// </span>
// <CheckBadge
// checked={checkRuntimeStatus(row.original.testcases)}
// >
// No Runtime Error
// </CheckBadge>
// </div>
// );
// },
// },
{
accessorKey: "source_code",
header: () => <div className="text-center">
Expand Down Expand Up @@ -145,9 +120,9 @@ const columns: ColumnDef<ProblemPopulateTestcases>[] = [

{
accessorKey: "allowed_languages",
header: "Allowed Languages",
header: () => <div className="text-center">Allowed Languages</div>,
cell: ({ row }) => (
<div className="font-medium">
<div className="font-medium flex justify-center">
{row.original.allowed_languages.split(",").map((lang) => (
<span className="mx-0.5">
{
Expand All @@ -160,19 +135,19 @@ const columns: ColumnDef<ProblemPopulateTestcases>[] = [
</div>
),
},
// Temporary hide this column
// {
// accessorKey: "difficulty",
// header: ({ column }) => (
// <DataTableSortableLayout onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}>
// Difficulty
// </DataTableSortableLayout>

{
accessorKey: "difficulty",
header: ({ column }) => (
<DataTableSortableLayout onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}>
Difficulty
</DataTableSortableLayout>

),
cell: ({ row }) => (
<DifficultyBadge level={row.original.difficulty}/>
),
},
// ),
// cell: ({ row }) => (
// <DifficultyBadge level={row.original.difficulty}/>
// ),
// },

{
accessorKey: "updated_date",
Expand Down
6 changes: 3 additions & 3 deletions src/components/shadcn/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const badgeVariants = cva(
variants: {
variant: {
default:
"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",
"border-transparent bg-primary text-primary-foreground cursor-default", // hover:bg-primary/80",
secondary:
"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
"border-transparent bg-secondary text-secondary-foreground", // hover:bg-secondary/80",
destructive:
"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",
"border-transparent bg-destructive text-destructive-foreground", // hover:bg-destructive/80",
outline: "text-foreground",
},
},
Expand Down
96 changes: 63 additions & 33 deletions src/router.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useContext, useEffect } from "react";
import { useContext } from "react";
import { Route, Routes } from "react-router-dom";
import { LoginContext } from "./contexts/LoginContext";
import CourseManagement from "./views/CourseManagement";
Expand Down Expand Up @@ -27,14 +27,8 @@ import ViewCourseProblem from "./views/ViewCourseProblem";
import ViewProblem from "./views/ViewProblem";

const Router = () => {

// const navigate = useNavigate();
const {isLogin} = useContext(LoginContext);
useEffect(() => {
console.log('isLogin',isLogin)
if (isLogin !== null && !isLogin) {
}
},[isLogin])
const { isLogin } = useContext(LoginContext);

return (
<Routes>
Expand All @@ -44,36 +38,72 @@ const Router = () => {
<Route path="/login" element={<Login />} />
<Route path="/register" element={<Register />} />

{(isLogin !== null && !isLogin) && (<Route path="/*" element={<Login />} />)}
{isLogin !== null && !isLogin && (
<Route path="/*" element={<Login />} />
)}

{isLogin && (
<>
<Route path="/dashboard" element={<Dashboard />} />
<Route path="/management" element={<CourseManagement />} />

<Route path="/my/problems" element={<MyProblems />} />
<Route
path="/my/problems/create"
element={<CreateProblem />}
/>
<Route
path="/my/problems/:problemId"
element={<ProblemStatistic />}
/>
<Route
path="/my/problems/:problemId/edit"
element={<EditProblem />}
/>

{isLogin && (<>
<Route path="/dashboard" element={<Dashboard />} />
<Route path="/management" element={<CourseManagement />} />
<Route path="/my/collections" element={<MyCollections />} />
<Route
path="/my/collections/create"
element={<CreateCollection />}
/>
<Route
path="/my/collections/:collectionId/edit"
element={<EditCollection />}
/>

<Route path="/my/problems" element={<MyProblems />} />
<Route path="/my/problems/create" element={<CreateProblem />} />
<Route path="/my/problems/:problemId" element={<ProblemStatistic />} />
<Route path="/my/problems/:problemId/edit" element={<EditProblem />} />
<Route path="/my/courses" element={<MyCourses />} />
<Route
path="/my/courses/create"
element={<CreateCourse />}
/>
<Route
path="/my/courses/:courseId/edit"
element={<EditCourse />}
/>

<Route path="/my/collections" element={<MyCollections />} />
<Route path="/my/collections/create" element={<CreateCollection />} />
<Route path="/my/collections/:collectionId/edit" element={<EditCollection />} />
<Route path="/my/groups" element={<MyGroups />} />
<Route path="/my/groups/create" element={<CreateGroup />} />
<Route
path="/my/groups/:groupId/edit"
element={<EditGroup />}
/>

<Route path="/my/courses" element={<MyCourses />} />
<Route path="/my/courses/create" element={<CreateCourse />} />
<Route path="/my/courses/:courseId/edit" element={<EditCourse />} />
<Route
path="/my/submissions"
element={<MyPreviousSubmissions />}
/>

<Route path="/my/groups" element={<MyGroups />} />
<Route path="/my/groups/create" element={<CreateGroup />} />
<Route path="/my/groups/:groupId/edit" element={<EditGroup />} />

<Route path="/my/submissions" element={<MyPreviousSubmissions />} />

<Route path="/problems/:problemId" element={<ViewProblem />} />
<Route path="/courses/:courseId" element={<ViewCourse />} />
<Route path="/courses/:courseId/problems/:problemId" element={<ViewCourseProblem />} />
</>)}

<Route
path="/problems/:problemId"
element={<ViewProblem />}
/>
<Route path="/courses/:courseId" element={<ViewCourse />} />
<Route
path="/courses/:courseId/problems/:problemId"
element={<ViewCourseProblem />}
/>
</>
)}
</Routes>
);
};
Expand Down
85 changes: 48 additions & 37 deletions src/views/My/Problems/EditProblem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,73 @@ import { CreateProblemRequestForm } from "../../../types/forms/CreateProblemRequ
import { ProblemPoplulateCreatorModel } from "../../../types/models/Problem.model";

const EditProblem = () => {

const accountId = String(localStorage.getItem("account_id"));

const { problemId } = useParams();
const editProblemId = String(problemId);

const [problem,setProblem] = useState<ProblemPoplulateCreatorModel>();
const [problem, setProblem] = useState<ProblemPoplulateCreatorModel>();

const [createRequest, setCreateRequest] = useState<CreateProblemRequestForm>();
const [createRequest, setCreateRequest] =
useState<CreateProblemRequestForm>();

const handleSave: OnProblemSaveCallback = (
setLoading,
createRequest
) => {
const handleSave: OnProblemSaveCallback = (setLoading, createRequest) => {
setLoading(true);

const { request,groups } = transformCreateProblemRequestForm2CreateProblemRequest(createRequest)
const { request, groups } =
transformCreateProblemRequestForm2CreateProblemRequest(
createRequest
);

ProblemService.update(
String(editProblemId),
accountId,
request
).then((response) => {
return ProblemService.updateGroupPermissions(response.data.problem_id,accountId,groups)
}).then((response) => {
console.log("Update Completed", response.data);
setLoading(false);
toast({
title: "Problem Updated",
ProblemService.update(String(editProblemId), accountId, request)
.then((response) => {
return ProblemService.updateGroupPermissions(
response.data.problem_id,
accountId,
groups
);
})
.then((response) => {
console.log("Update Completed", response.data);
setLoading(false);
toast({
title: "Problem Updated",
});
});
});
};

useEffect(() => {
ProblemService.get(accountId,editProblemId).then((response) => {
setProblem(response.data)
setCreateRequest(transformProblemPopulateAccountAndTestcasesAndProblemGroupPermissionsPopulateGroupModel2CreateProblemRequestForm(response.data));
ProblemService.get(accountId, editProblemId).then((response) => {
setProblem(response.data);
setCreateRequest(
transformProblemPopulateAccountAndTestcasesAndProblemGroupPermissionsPopulateGroupModel2CreateProblemRequestForm(
response.data
)
);
document.title = `${response.data.title} - Edit`;
});
}, []);


}, [accountId, editProblemId]);
return (
<NavbarSidebarLayout>
{createRequest && <CreateProblemForm
createRequestInitialValue={createRequest}
validatedTestcases={problem?.testcases}
onProblemSave={(
setLoading,

createRequest
) =>
handleSave(
{createRequest && (
<CreateProblemForm
createRequestInitialValue={createRequest}
validatedTestcases={problem?.testcases}
onProblemSave={(
setLoading,

createRequest
)
}
/>}
) =>
handleSave(
setLoading,

createRequest
)
}
/>
)}
</NavbarSidebarLayout>
);
};
Expand Down
Loading