"use client"; import { Button } from "@/components/ui/button"; import Tab from "@/components/ui/tab"; import { closeTerminal, createTerminal } from "@/lib/terminal"; import { Terminal } from "@xterm/xterm"; import { Loader2, Plus, SquareTerminal, TerminalSquare } from "lucide-react"; import { Socket } from "socket.io-client"; import { toast } from "sonner"; import EditorTerminal from "./terminal"; export default function Terminals({ terminals, setTerminals, activeTerminalId, setActiveTerminalId, socket, activeTerminal, creatingTerminal, setCreatingTerminal, closingTerminal, setClosingTerminal, }: { terminals: { id: string; terminal: Terminal | null }[]; setTerminals: React.Dispatch< React.SetStateAction< { id: string; terminal: Terminal | null; }[] > >; activeTerminalId: string; setActiveTerminalId: React.Dispatch>; socket: Socket; activeTerminal: | { id: string; terminal: Terminal | null; } | undefined; creatingTerminal: boolean; setCreatingTerminal: React.Dispatch>; closingTerminal: string; setClosingTerminal: React.Dispatch>; }) { return ( <>
{terminals.map((term) => ( setActiveTerminalId(term.id)} onClose={() => closeTerminal({ term, terminals, setTerminals, setActiveTerminalId, setClosingTerminal, socket, activeTerminalId, }) } closing={closingTerminal === term.id} selected={activeTerminalId === term.id} > Shell ))}
{socket && activeTerminal ? (
{terminals.map((term) => ( { setTerminals((prev) => prev.map((term) => term.id === activeTerminalId ? { ...term, terminal: t } : term ) ); }} visible={activeTerminalId === term.id} /> ))}
) : (
No terminals open.
)} ); }