FetchProductionButton
uses useState
Fetch production's traces again (fetchProduction), then show them.
import { refresh } from "#codebase/tcmts/react"; import { toasts } from "#codebase/tcmts/share"; import { fetchProduction } from "#codebase/tcmts/studio"; import { useState } from "react"; import { Button } from "react-aria-components"; export function FetchProductionButton({ label }: { label: string }) { const [busy, setBusy] = useState(false); return ( <Button className="btn small" isPending={busy} onPress={async () => { setBusy(true); try { toasts.add({ title: await fetchProduction(), tone: "ok" }, { timeout: 5000 }); refresh(); } catch (e) { toasts.add( { title: "Couldn't fetch production's traces", description: (e as Error).message, tone: "bad", }, { timeout: 10000 }, ); } setBusy(false); }} > {busy ? "Fetching…" : label} </Button> ); }