From 1df01810352c8e00488e6ed022af1b81613eea66 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Wed, 8 Jan 2025 00:38:26 +0530 Subject: [PATCH] feat: clear console outputs when closing block (#676) --- components/console.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/components/console.tsx b/components/console.tsx index 403b827..18e5736 100644 --- a/components/console.tsx +++ b/components/console.tsx @@ -10,6 +10,7 @@ import { } from 'react'; import { ConsoleOutput } from './block'; import { cn } from '@/lib/utils'; +import { useBlockSelector } from '@/hooks/use-block'; interface ConsoleProps { consoleOutputs: Array; @@ -21,6 +22,8 @@ export function Console({ consoleOutputs, setConsoleOutputs }: ConsoleProps) { const [isResizing, setIsResizing] = useState(false); const consoleEndRef = useRef(null); + const isBlockVisible = useBlockSelector((state) => state.isVisible); + const minHeight = 100; const maxHeight = 800; @@ -57,6 +60,12 @@ export function Console({ consoleOutputs, setConsoleOutputs }: ConsoleProps) { consoleEndRef.current?.scrollIntoView({ behavior: 'smooth' }); }, [consoleOutputs]); + useEffect(() => { + if (!isBlockVisible) { + setConsoleOutputs([]); + } + }, [isBlockVisible, setConsoleOutputs]); + return consoleOutputs.length > 0 ? ( <>