Skip to content

Commit

Permalink
feat: clear console outputs when closing block
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyphilemon committed Jan 7, 2025
1 parent 50bd460 commit 7d43157
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions components/console.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConsoleOutput>;
Expand All @@ -21,6 +22,8 @@ export function Console({ consoleOutputs, setConsoleOutputs }: ConsoleProps) {
const [isResizing, setIsResizing] = useState(false);
const consoleEndRef = useRef<HTMLDivElement>(null);

const isBlockVisible = useBlockSelector((state) => state.isVisible);

const minHeight = 100;
const maxHeight = 800;

Expand Down Expand Up @@ -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 ? (
<>
<div
Expand Down

0 comments on commit 7d43157

Please sign in to comment.