mirror of
https://github.com/massbug/judge4c.git
synced 2025-05-17 23:12:23 +00:00
refactor(details): move panel cleanup logic into useEffect
This commit is contained in:
parent
ce4a0e64c9
commit
fbf563dfdf
@ -1,6 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
import { useEffect } from "react";
|
||||||
import { ArrowLeftIcon } from "lucide-react";
|
import { ArrowLeftIcon } from "lucide-react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { useProblem } from "@/hooks/use-problem";
|
import { useProblem } from "@/hooks/use-problem";
|
||||||
@ -15,14 +16,17 @@ export default function DetailsPage() {
|
|||||||
const { api, submission } = useDockviewStore();
|
const { api, submission } = useDockviewStore();
|
||||||
const { editorLanguageConfigs, problemId } = useProblem();
|
const { editorLanguageConfigs, problemId } = useProblem();
|
||||||
|
|
||||||
if (!api || !problemId || !submission?.id) return null;
|
useEffect(() => {
|
||||||
|
if (!api || !problemId || !submission?.id) return;
|
||||||
if (problemId !== submission.problemId) {
|
if (problemId !== submission.problemId) {
|
||||||
const detailsPanel = api.getPanel("Details");
|
const detailsPanel = api.getPanel("Details");
|
||||||
if (detailsPanel) {
|
if (detailsPanel) {
|
||||||
api.removePanel(detailsPanel);
|
api.removePanel(detailsPanel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}, [api, problemId, submission])
|
||||||
|
|
||||||
|
if (!api || !problemId || !submission?.id) return null;
|
||||||
|
|
||||||
const createdAt = new Date(submission.createdAt);
|
const createdAt = new Date(submission.createdAt);
|
||||||
const submittedDisplay = isBefore(createdAt, subDays(new Date(), 1))
|
const submittedDisplay = isBefore(createdAt, subDays(new Date(), 1))
|
||||||
|
Loading…
Reference in New Issue
Block a user