import { useCallback, useEffect, useState } from "react" import { twMerge } from "tailwind-merge" import { AppSection } from "./AppSection" import { WSIndicator } from "./WSIndicator" import { app } from "./api" import { buttonStyle } from "./styles" import { useWS } from "./useWS" type ButtonAsyncProps = { onClick: () => Promise<{ error?: unknown }> stateLabels: { idle: string loading?: string error?: string success?: string } } const ButtonAsync = ({ onClick, stateLabels: stateLabelsProp, }: ButtonAsyncProps) => { const stateLabels = { error: "Error", loading: "Loading...", success: "Success", ...stateLabelsProp, } const [state, setState] = useState<"idle" | "loading" | "error" | "success">( "idle", ) useEffect(() => { if (state !== "loading" && state !== "idle") { const timeout = setTimeout(() => setState("idle"), 2000) return () => { clearTimeout(timeout) } } }, [state]) const handleClick = async () => { if (state !== "idle") return setState("loading") const { error } = await onClick() if (error) { setState("error") return } setState("success") } return ( ) } export function Terminal() { const [content, setContent] = useState("") const ws = useWS({ subscribe: useCallback(() => app.ws.subscribe(), []), onMessage: useCallback((event) => setContent(event.data), []), }) return ( ( <>

TypedAssistant

app["force-sync-with-github"].get()} stateLabels={{ idle: "Force sync with remote", loading: "Syncing...", success: "Successfully synced with remote", }} /> app["restart-app"].get()} stateLabels={{ idle: "Restart app", loading: "Restarting app...", success: "App restarted", }} /> app["restart-addon"].get()} stateLabels={{ idle: "Restart addon", loading: "Restarting addon...", success: "Addon restarted", }} />
)} >
    
  )
}