mirror of
https://github.com/massbug/judge4c.git
synced 2025-05-17 23:12:23 +00:00
feat(submissions-table): add click handler to open details panel
This commit is contained in:
parent
2d06b778e6
commit
b35ef0208a
@ -1,3 +1,5 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
@ -8,8 +10,9 @@ import {
|
|||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { Submission } from "@/generated/client";
|
import { Submission } from "@/generated/client";
|
||||||
import { getStatusColorClass } from "@/lib/status";
|
|
||||||
import { Clock4Icon, CpuIcon } from "lucide-react";
|
import { Clock4Icon, CpuIcon } from "lucide-react";
|
||||||
|
import { getStatusColorClass } from "@/lib/status";
|
||||||
|
import { useDockviewStore } from "@/stores/dockview";
|
||||||
import { EditorLanguageIcons } from "@/config/editor-language-icons";
|
import { EditorLanguageIcons } from "@/config/editor-language-icons";
|
||||||
import { formatDistanceToNow, isBefore, subDays, format } from "date-fns";
|
import { formatDistanceToNow, isBefore, subDays, format } from "date-fns";
|
||||||
|
|
||||||
@ -18,10 +21,31 @@ interface SubmissionsTableProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function SubmissionsTable({ submissions }: SubmissionsTableProps) {
|
export default function SubmissionsTable({ submissions }: SubmissionsTableProps) {
|
||||||
|
const { api, setSubmission } = useDockviewStore();
|
||||||
const sortedSubmissions = [...submissions].sort(
|
const sortedSubmissions = [...submissions].sort(
|
||||||
(a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
|
(a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleRowClick = (submission: Submission) => {
|
||||||
|
if (!api) return;
|
||||||
|
setSubmission(submission);
|
||||||
|
const panel = api.getPanel("Details");
|
||||||
|
if (panel) {
|
||||||
|
panel.api.setActive();
|
||||||
|
} else {
|
||||||
|
api.addPanel({
|
||||||
|
id: "Details",
|
||||||
|
component: "Details",
|
||||||
|
tabComponent: "Details",
|
||||||
|
title: submission.status,
|
||||||
|
position: {
|
||||||
|
referencePanel: "Submissions",
|
||||||
|
direction: "within",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Table>
|
<Table>
|
||||||
<TableHeader className="bg-transparent">
|
<TableHeader className="bg-transparent">
|
||||||
@ -48,10 +72,13 @@ export default function SubmissionsTable({ submissions }: SubmissionsTableProps)
|
|||||||
return (
|
return (
|
||||||
<TableRow
|
<TableRow
|
||||||
key={submission.id}
|
key={submission.id}
|
||||||
className={cn(
|
onClick={() => handleRowClick(submission)}
|
||||||
"border-b-0 hover:text-blue-500 hover:bg-muted",
|
className={
|
||||||
|
cn(
|
||||||
|
"border-b-0 hover:text-blue-500 hover:bg-muted hover:cursor-pointer",
|
||||||
isEven ? "" : "bg-muted/50"
|
isEven ? "" : "bg-muted/50"
|
||||||
)}
|
)
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<TableCell className="font-medium">
|
<TableCell className="font-medium">
|
||||||
{sortedSubmissions.length - index}
|
{sortedSubmissions.length - index}
|
||||||
|
Loading…
Reference in New Issue
Block a user