diff --git a/frontend/components/editor/navbar/run.tsx b/frontend/components/editor/navbar/run.tsx index 688886f..8e5a3b2 100644 --- a/frontend/components/editor/navbar/run.tsx +++ b/frontend/components/editor/navbar/run.tsx @@ -36,7 +36,7 @@ export default function RunButtonModal({ console.log('Opening Preview Window'); if (terminals.length < 4) { - createNewTerminal(); + createNewTerminal("yarn install && yarn start"); } else { toast.error("You reached the maximum # of terminals."); console.error('Maximum number of terminals reached.'); diff --git a/frontend/context/TerminalContext.tsx b/frontend/context/TerminalContext.tsx index 517a355..573a32e 100644 --- a/frontend/context/TerminalContext.tsx +++ b/frontend/context/TerminalContext.tsx @@ -13,7 +13,7 @@ interface TerminalContextType { setActiveTerminalId: React.Dispatch>; creatingTerminal: boolean; setCreatingTerminal: React.Dispatch>; - createNewTerminal: () => void; + createNewTerminal: (command?: string) => Promise; closeTerminal: (id: string) => void; setUserAndSandboxId: (userId: string, sandboxId: string) => void; } @@ -50,7 +50,7 @@ export const TerminalProvider: React.FC<{ children: React.ReactNode }> = ({ chil } }, [userId, sandboxId]); - const createNewTerminal = async () => { + const createNewTerminal = async (command?: string): Promise => { if (!socket) return; setCreatingTerminal(true); try { @@ -58,6 +58,7 @@ export const TerminalProvider: React.FC<{ children: React.ReactNode }> = ({ chil setTerminals, setActiveTerminalId, setCreatingTerminal, + command, socket, }); } catch (error) { diff --git a/frontend/lib/terminal.ts b/frontend/lib/terminal.ts index fb3200f..6f45ee8 100644 --- a/frontend/lib/terminal.ts +++ b/frontend/lib/terminal.ts @@ -8,6 +8,7 @@ export const createTerminal = ({ setTerminals, setActiveTerminalId, setCreatingTerminal, + command, socket, }: { setTerminals: React.Dispatch>; setActiveTerminalId: React.Dispatch>; setCreatingTerminal: React.Dispatch>; + command?: string; socket: Socket; }) => { @@ -29,6 +31,7 @@ export const createTerminal = ({ setTimeout(() => { socket.emit("createTerminal", id, () => { setCreatingTerminal(false); + if (command) socket.emit("terminalData", id, command + "\n"); }); }, 1000); };