Start development server when run button is clicked.

This commit is contained in:
James Murdza 2024-07-31 17:49:59 -07:00
parent a74f7bf71a
commit 6a31161c0a
3 changed files with 7 additions and 3 deletions

View File

@ -36,7 +36,7 @@ export default function RunButtonModal({
console.log('Opening Preview Window'); console.log('Opening Preview Window');
if (terminals.length < 4) { if (terminals.length < 4) {
createNewTerminal(); createNewTerminal("yarn install && yarn start");
} else { } else {
toast.error("You reached the maximum # of terminals."); toast.error("You reached the maximum # of terminals.");
console.error('Maximum number of terminals reached.'); console.error('Maximum number of terminals reached.');

View File

@ -13,7 +13,7 @@ interface TerminalContextType {
setActiveTerminalId: React.Dispatch<React.SetStateAction<string>>; setActiveTerminalId: React.Dispatch<React.SetStateAction<string>>;
creatingTerminal: boolean; creatingTerminal: boolean;
setCreatingTerminal: React.Dispatch<React.SetStateAction<boolean>>; setCreatingTerminal: React.Dispatch<React.SetStateAction<boolean>>;
createNewTerminal: () => void; createNewTerminal: (command?: string) => Promise<void>;
closeTerminal: (id: string) => void; closeTerminal: (id: string) => void;
setUserAndSandboxId: (userId: string, sandboxId: string) => void; setUserAndSandboxId: (userId: string, sandboxId: string) => void;
} }
@ -50,7 +50,7 @@ export const TerminalProvider: React.FC<{ children: React.ReactNode }> = ({ chil
} }
}, [userId, sandboxId]); }, [userId, sandboxId]);
const createNewTerminal = async () => { const createNewTerminal = async (command?: string): Promise<void> => {
if (!socket) return; if (!socket) return;
setCreatingTerminal(true); setCreatingTerminal(true);
try { try {
@ -58,6 +58,7 @@ export const TerminalProvider: React.FC<{ children: React.ReactNode }> = ({ chil
setTerminals, setTerminals,
setActiveTerminalId, setActiveTerminalId,
setCreatingTerminal, setCreatingTerminal,
command,
socket, socket,
}); });
} catch (error) { } catch (error) {

View File

@ -8,6 +8,7 @@ export const createTerminal = ({
setTerminals, setTerminals,
setActiveTerminalId, setActiveTerminalId,
setCreatingTerminal, setCreatingTerminal,
command,
socket, socket,
}: { }: {
setTerminals: React.Dispatch<React.SetStateAction<{ setTerminals: React.Dispatch<React.SetStateAction<{
@ -16,6 +17,7 @@ export const createTerminal = ({
}[]>>; }[]>>;
setActiveTerminalId: React.Dispatch<React.SetStateAction<string>>; setActiveTerminalId: React.Dispatch<React.SetStateAction<string>>;
setCreatingTerminal: React.Dispatch<React.SetStateAction<boolean>>; setCreatingTerminal: React.Dispatch<React.SetStateAction<boolean>>;
command?: string;
socket: Socket; socket: Socket;
}) => { }) => {
@ -29,6 +31,7 @@ export const createTerminal = ({
setTimeout(() => { setTimeout(() => {
socket.emit("createTerminal", id, () => { socket.emit("createTerminal", id, () => {
setCreatingTerminal(false); setCreatingTerminal(false);
if (command) socket.emit("terminalData", id, command + "\n");
}); });
}, 1000); }, 1000);
}; };