chore: format frontend code
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
// Helper functions for terminal instances
|
||||
|
||||
import { createId } from "@paralleldrive/cuid2";
|
||||
import { Terminal } from "@xterm/xterm";
|
||||
import { Socket } from "socket.io-client";
|
||||
import { createId } from "@paralleldrive/cuid2"
|
||||
import { Terminal } from "@xterm/xterm"
|
||||
import { Socket } from "socket.io-client"
|
||||
|
||||
export const createTerminal = ({
|
||||
setTerminals,
|
||||
@ -11,30 +11,33 @@ export const createTerminal = ({
|
||||
command,
|
||||
socket,
|
||||
}: {
|
||||
setTerminals: React.Dispatch<React.SetStateAction<{
|
||||
id: string;
|
||||
terminal: Terminal | null;
|
||||
}[]>>;
|
||||
setActiveTerminalId: React.Dispatch<React.SetStateAction<string>>;
|
||||
setCreatingTerminal: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
command?: string;
|
||||
socket: Socket;
|
||||
|
||||
setTerminals: React.Dispatch<
|
||||
React.SetStateAction<
|
||||
{
|
||||
id: string
|
||||
terminal: Terminal | null
|
||||
}[]
|
||||
>
|
||||
>
|
||||
setActiveTerminalId: React.Dispatch<React.SetStateAction<string>>
|
||||
setCreatingTerminal: React.Dispatch<React.SetStateAction<boolean>>
|
||||
command?: string
|
||||
socket: Socket
|
||||
}) => {
|
||||
setCreatingTerminal(true);
|
||||
const id = createId();
|
||||
console.log("creating terminal, id:", id);
|
||||
setCreatingTerminal(true)
|
||||
const id = createId()
|
||||
console.log("creating terminal, id:", id)
|
||||
|
||||
setTerminals((prev) => [...prev, { id, terminal: null }]);
|
||||
setActiveTerminalId(id);
|
||||
setTerminals((prev) => [...prev, { id, terminal: null }])
|
||||
setActiveTerminalId(id)
|
||||
|
||||
setTimeout(() => {
|
||||
socket.emit("createTerminal", id, () => {
|
||||
setCreatingTerminal(false);
|
||||
if (command) socket.emit("terminalData", id, command + "\n");
|
||||
});
|
||||
}, 1000);
|
||||
};
|
||||
setCreatingTerminal(false)
|
||||
if (command) socket.emit("terminalData", id, command + "\n")
|
||||
})
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
export const closeTerminal = ({
|
||||
term,
|
||||
@ -44,32 +47,36 @@ export const closeTerminal = ({
|
||||
setClosingTerminal,
|
||||
socket,
|
||||
activeTerminalId,
|
||||
} : {
|
||||
term: {
|
||||
id: string;
|
||||
terminal: Terminal | null
|
||||
}: {
|
||||
term: {
|
||||
id: string
|
||||
terminal: Terminal | null
|
||||
}
|
||||
terminals: {
|
||||
id: string;
|
||||
terminal: Terminal | null
|
||||
terminals: {
|
||||
id: string
|
||||
terminal: Terminal | null
|
||||
}[]
|
||||
setTerminals: React.Dispatch<React.SetStateAction<{
|
||||
id: string;
|
||||
terminal: Terminal | null
|
||||
}[]>>
|
||||
setTerminals: React.Dispatch<
|
||||
React.SetStateAction<
|
||||
{
|
||||
id: string
|
||||
terminal: Terminal | null
|
||||
}[]
|
||||
>
|
||||
>
|
||||
setActiveTerminalId: React.Dispatch<React.SetStateAction<string>>
|
||||
setClosingTerminal: React.Dispatch<React.SetStateAction<string>>
|
||||
socket: Socket
|
||||
activeTerminalId: string
|
||||
}) => {
|
||||
const numTerminals = terminals.length;
|
||||
const index = terminals.findIndex((t) => t.id === term.id);
|
||||
if (index === -1) return;
|
||||
const numTerminals = terminals.length
|
||||
const index = terminals.findIndex((t) => t.id === term.id)
|
||||
if (index === -1) return
|
||||
|
||||
setClosingTerminal(term.id);
|
||||
setClosingTerminal(term.id)
|
||||
|
||||
socket.emit("closeTerminal", term.id, () => {
|
||||
setClosingTerminal("");
|
||||
setClosingTerminal("")
|
||||
|
||||
const nextId =
|
||||
activeTerminalId === term.id
|
||||
@ -78,17 +85,17 @@ export const closeTerminal = ({
|
||||
: index < numTerminals - 1
|
||||
? terminals[index + 1].id
|
||||
: terminals[index - 1].id
|
||||
: activeTerminalId;
|
||||
: activeTerminalId
|
||||
|
||||
setTerminals((prev) => prev.filter((t) => t.id !== term.id));
|
||||
setTerminals((prev) => prev.filter((t) => t.id !== term.id))
|
||||
|
||||
if (!nextId) {
|
||||
setActiveTerminalId("");
|
||||
setActiveTerminalId("")
|
||||
} else {
|
||||
const nextTerminal = terminals.find((t) => t.id === nextId);
|
||||
const nextTerminal = terminals.find((t) => t.id === nextId)
|
||||
if (nextTerminal) {
|
||||
setActiveTerminalId(nextTerminal.id);
|
||||
setActiveTerminalId(nextTerminal.id)
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
})
|
||||
}
|
||||
|
@ -1,65 +1,65 @@
|
||||
// DB Types
|
||||
|
||||
export type User = {
|
||||
id: string;
|
||||
name: string;
|
||||
email: string;
|
||||
generations: number;
|
||||
sandbox: Sandbox[];
|
||||
usersToSandboxes: UsersToSandboxes[];
|
||||
};
|
||||
id: string
|
||||
name: string
|
||||
email: string
|
||||
generations: number
|
||||
sandbox: Sandbox[]
|
||||
usersToSandboxes: UsersToSandboxes[]
|
||||
}
|
||||
|
||||
export type Sandbox = {
|
||||
id: string;
|
||||
name: string;
|
||||
type: string;
|
||||
visibility: "public" | "private";
|
||||
createdAt: Date;
|
||||
userId: string;
|
||||
usersToSandboxes: UsersToSandboxes[];
|
||||
};
|
||||
id: string
|
||||
name: string
|
||||
type: string
|
||||
visibility: "public" | "private"
|
||||
createdAt: Date
|
||||
userId: string
|
||||
usersToSandboxes: UsersToSandboxes[]
|
||||
}
|
||||
|
||||
export type UsersToSandboxes = {
|
||||
userId: string;
|
||||
sandboxId: string;
|
||||
sharedOn: Date;
|
||||
};
|
||||
userId: string
|
||||
sandboxId: string
|
||||
sharedOn: Date
|
||||
}
|
||||
|
||||
export type R2Files = {
|
||||
objects: R2FileData[];
|
||||
truncated: boolean;
|
||||
delimitedPrefixes: any[];
|
||||
};
|
||||
objects: R2FileData[]
|
||||
truncated: boolean
|
||||
delimitedPrefixes: any[]
|
||||
}
|
||||
|
||||
export type R2FileData = {
|
||||
storageClass: string;
|
||||
uploaded: string;
|
||||
checksums: any;
|
||||
httpEtag: string;
|
||||
etag: string;
|
||||
size: number;
|
||||
version: string;
|
||||
key: string;
|
||||
};
|
||||
storageClass: string
|
||||
uploaded: string
|
||||
checksums: any
|
||||
httpEtag: string
|
||||
etag: string
|
||||
size: number
|
||||
version: string
|
||||
key: string
|
||||
}
|
||||
|
||||
export type TFolder = {
|
||||
id: string;
|
||||
type: "folder";
|
||||
name: string;
|
||||
children: (TFile | TFolder)[];
|
||||
};
|
||||
id: string
|
||||
type: "folder"
|
||||
name: string
|
||||
children: (TFile | TFolder)[]
|
||||
}
|
||||
|
||||
export type TFile = {
|
||||
id: string;
|
||||
type: "file";
|
||||
name: string;
|
||||
};
|
||||
id: string
|
||||
type: "file"
|
||||
name: string
|
||||
}
|
||||
|
||||
export type TTab = TFile & {
|
||||
saved: boolean;
|
||||
};
|
||||
saved: boolean
|
||||
}
|
||||
|
||||
export type TFileData = {
|
||||
id: string;
|
||||
data: string;
|
||||
};
|
||||
id: string
|
||||
data: string
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { type ClassValue, clsx } from "clsx"
|
||||
// import { toast } from "sonner"
|
||||
import { twMerge } from "tailwind-merge"
|
||||
import { Sandbox, TFile, TFolder } from "./types"
|
||||
import fileExtToLang from "./file-extension-to-language.json"
|
||||
import { Sandbox, TFile, TFolder } from "./types"
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
|
Reference in New Issue
Block a user