StopButton
uses useState
Stops a running tcm (stopProcess), then shows the page again without it; a toast says what happened.
import { refresh } from "#codebase/tcmts/react"; import { toasts } from "#codebase/tcmts/share"; import { stopProcess } from "#codebase/tcmts/studio"; import { useState } from "react"; import { Button } from "react-aria-components"; export function StopButton({ pid }: { pid: number }) { const [busy, setBusy] = useState(false); return ( <Button className="btn small danger" isPending={busy} onPress={async () => { setBusy(true); try { toasts.add({ title: await stopProcess(pid), tone: "ok" }, { timeout: 4000 }); setTimeout(() => refresh(), 500); } catch (e) { toasts.add( { title: "Couldn't stop it", description: (e as Error).message, tone: "bad" }, { timeout: 8000 }, ); } setBusy(false); }} > {busy ? "Stopping…" : "Stop"} </Button> ); }