fix: local debug

This commit is contained in:
naiba
2024-12-09 23:11:17 +08:00
parent baf611ea94
commit d1fba95484
5 changed files with 52 additions and 57 deletions

23
src/hooks/useTerminal.ts Normal file
View File

@@ -0,0 +1,23 @@
import { createTerminal } from "@/api/terminal";
import { ModelCreateTerminalResponse } from "@/types";
import { useState, useEffect } from "react";
export default function useTerminal(serverId?: number) {
const [terminal, setTerminal] = useState<ModelCreateTerminalResponse | null>(null);
async function fetchTerminal() {
try {
const response = await createTerminal(serverId!);
setTerminal(response);
} catch (error) {
console.error("Failed to fetch terminal:", error);
}
}
useEffect(() => {
if (!serverId) return;
fetchTerminal();
}, [serverId]);
return terminal;
}