diff --git a/src/App.jsx b/src/App.jsx index 75c2e825..4c549719 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -22,6 +22,7 @@ function App() { port: 22, }); const [isLaunchpadOpen, setIsLaunchpadOpen] = useState(false); + const [splitTabIds, setSplitTabIds] = useState([]); // Handle keypress for opening launchpad useEffect(() => { @@ -50,8 +51,7 @@ function App() { password: form.password, port: Number(form.port), }, - isSplit: false, - terminalRef: null, // Reference to the terminal instance + terminalRef: null, }; setTerminals([...terminals, newTerminal]); setActiveTab(nextId); @@ -67,6 +67,7 @@ function App() { const closeTab = (id) => { const newTerminals = terminals.filter((t) => t.id !== id); setTerminals(newTerminals); + setSplitTabIds(prev => prev.filter(tabId => tabId !== id)); if (activeTab === id) { setActiveTab(newTerminals[0]?.id || null); } @@ -74,21 +75,29 @@ function App() { // Toggle split for a specific tab const toggleSplit = (id) => { - setTerminals(terminals.map(t => - t.id === id ? { ...t, isSplit: !t.isSplit } : t - )); + setSplitTabIds(prev => { + if (prev.includes(id)) { + return prev.filter(tabId => tabId !== id); + } else { + if (prev.length >= 1) return prev; // Limit to 1 split + return [...prev, id, activeTab].filter((tabId, index, self) => self.indexOf(tabId) === index); + } + }); }; - // Get the split terminals - const splitTerminals = terminals.filter(t => t.isSplit); - const mainTerminal = terminals.find(t => t.id === activeTab); + // Get grid layout class based on split count + const getGridLayout = (count) => { + if (count === 1) return 'grid-cols-1'; + if (count === 2) return 'grid-cols-2'; + return 'grid-cols-1'; + }; return (
{/* Topbar */} -
+
Termix Icon

Termix

@@ -102,6 +111,7 @@ function App() { setActiveTab={setActiveTab} closeTab={closeTab} toggleSplit={toggleSplit} + splitTabIds={splitTabIds} theme={theme} />
@@ -144,35 +154,39 @@ function App() { {/* Terminal Views */}
- {splitTerminals.length > 0 ? ( -
- {splitTerminals.map((terminal) => ( -
- { - if (ref && !terminal.terminalRef) { - // Store the terminal instance reference - setTerminals(prev => prev.map(t => - t.id === terminal.id ? { ...t, terminalRef: ref } : t - )); - } - }} - /> -
- ))} + {splitTabIds.length > 0 ? ( +
+ {splitTabIds.map(id => { + const terminal = terminals.find(t => t.id === id); + return terminal ? ( +
+ { + if (ref && !terminal.terminalRef) { + setTerminals(prev => prev.map(t => + t.id === terminal.id ? { ...t, terminalRef: ref } : t + )); + } + }} + /> +
+ ) : null; + })}
) : (
- {mainTerminal && ( + {terminals.find(t => t.id === activeTab) && (
t.id === activeTab).hostConfig} ref={(ref) => { - if (ref && !mainTerminal.terminalRef) { - // Store the terminal instance reference + const terminal = terminals.find(t => t.id === activeTab); + if (ref && terminal && !terminal.terminalRef) { setTerminals(prev => prev.map(t => - t.id === mainTerminal.id ? { ...t, terminalRef: ref } : t + t.id === activeTab ? { ...t, terminalRef: ref } : t )); } }} @@ -184,7 +198,7 @@ function App() {
- {/* Modal for adding a host */} + {/* Modals */} - - {/* Launchpad Component */} {isLaunchpadOpen && setIsLaunchpadOpen(false)} />}
diff --git a/src/TabList.jsx b/src/TabList.jsx index 28dd666e..c9d1a3c5 100644 --- a/src/TabList.jsx +++ b/src/TabList.jsx @@ -1,14 +1,15 @@ import { Button, ButtonGroup } from "@mui/joy"; import PropTypes from "prop-types"; -function TabList({ terminals, activeTab, setActiveTab, closeTab, toggleSplit, theme }) { +function TabList({ terminals, activeTab, setActiveTab, closeTab, toggleSplit, splitTabIds, theme }) { return (
{terminals.map((terminal, index) => (