diff --git a/src/components/ContainerInfo.tsx b/src/components/ContainerInfo.tsx index 808f06c..ddf0d13 100644 --- a/src/components/ContainerInfo.tsx +++ b/src/components/ContainerInfo.tsx @@ -8,6 +8,7 @@ export default function ContainerInfo() { useEffect(() => { const updateInfo = async () => { const stats = await fetch(`https://api.ssh.surf/info`, { + // @ts-ignore headers: { "x-ssh-auth": localStorage.getItem("key") }, }); diff --git a/src/components/Login.tsx b/src/components/Login.tsx index 8d39ed6..395f763 100644 --- a/src/components/Login.tsx +++ b/src/components/Login.tsx @@ -9,6 +9,7 @@ export default function Login() { const data = Object.fromEntries(formData); const hello = await fetch(`https://api.ssh.surf/hello`, { + // @ts-ignore headers: { "x-ssh-auth": data.key }, }); diff --git a/src/components/WebTerminal.tsx b/src/components/WebTerminal.tsx index af85c52..8dde262 100644 --- a/src/components/WebTerminal.tsx +++ b/src/components/WebTerminal.tsx @@ -58,7 +58,7 @@ export default function WebTerminal() { terminal.dispose(); }; } - }, []); + }, [container]); return
; } diff --git a/src/main.tsx b/src/main.tsx index f4ddaf4..a394e9a 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -8,6 +8,7 @@ import TerminalPage from "./pages/container/terminal.tsx"; async function loader() { const info = await fetch(`https://api.ssh.surf/info`, { + // @ts-ignore headers: { "x-ssh-auth": localStorage.getItem("key") }, }); diff --git a/src/pages/container/index.tsx b/src/pages/container/index.tsx index 1acb497..1c5f377 100644 --- a/src/pages/container/index.tsx +++ b/src/pages/container/index.tsx @@ -6,15 +6,15 @@ import ContainerInfo from "../../components/ContainerInfo"; export default function ContainerPage() { let container = useLoaderData(); + const revalidator = useRevalidator(); + const [isPowerStateLocked, setPowerStateLocked] = useState(); + if (!container.data) { return "Container not found"; } container = container.data as InfoData; - const revalidator = useRevalidator(); - const [isPowerStateLocked, setPowerStateLocked] = useState(); - return ( diff --git a/src/pages/container/terminal.tsx b/src/pages/container/terminal.tsx index 2767903..fd319ce 100644 --- a/src/pages/container/terminal.tsx +++ b/src/pages/container/terminal.tsx @@ -1,32 +1,25 @@ import { useLoaderData } from "react-router"; -import { Container } from "../../types"; +import { InfoData } from "../../types"; import { Paper, Typography } from "@mui/material"; import WebTerminal from "../../components/WebTerminal"; -export async function Loader() { - const info = await fetch(`https://api.ssh.surf/info`, { - headers: { "x-ssh-auth": localStorage["key"] }, - }); - - const data = await info.json(); - return data; -} - export default function TerminalPage() { - const container = useLoaderData() as Container & { statusCode: number }; + let container = useLoaderData(); - if (container.statusCode === 404) { - return "Container not found"; - } + if (!container.data) { + return "Container not found"; + } - return ( - - - - Terminal: {container.name} - - - - - ); + container = container.data as InfoData; + + return ( + + + + Terminal: {container.name} + + + + + ); }