From 8809dbdb1a57ee8b15b672b25c3adb640bca4bb1 Mon Sep 17 00:00:00 2001 From: cfngc4594 Date: Sat, 12 Apr 2025 13:38:57 +0800 Subject: [PATCH] feat(run-code): activate Submissions panel after running code --- src/components/run-code.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/run-code.tsx b/src/components/run-code.tsx index 7847fcd..3bfc9e6 100644 --- a/src/components/run-code.tsx +++ b/src/components/run-code.tsx @@ -11,6 +11,7 @@ import { useState } from "react"; import { judge } from "@/actions/judge"; import { Button } from "@/components/ui/button"; import { useProblem } from "@/hooks/use-problem"; +import { useDockviewStore } from "@/stores/dockview"; import { LoaderCircleIcon, PlayIcon } from "lucide-react"; import { showStatusToast } from "@/hooks/show-status-toast"; @@ -22,6 +23,7 @@ export function RunCode({ className, ...props }: RunCodeProps) { + const { api } = useDockviewStore(); const { currentLang, editor, problemId } = useProblem(); const [isLoading, setIsLoading] = useState(false); @@ -34,6 +36,10 @@ export function RunCode({ try { const result = await judge(currentLang, code, problemId); showStatusToast({ status: result.status }); + const panel = api?.getPanel("Submissions"); + if (panel && !panel.api.isActive) { + panel.api.setActive(); + } } catch (error) { console.error("Error occurred while judging the code:"); console.error(error); @@ -51,7 +57,7 @@ export function RunCode({ variant="secondary" className={cn("h-8 px-3 py-1.5", className)} onClick={handleJudge} - disabled={isLoading} + disabled={isLoading || !api?.getPanel("Submissions")} > {isLoading ? (