mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-17 23:13:51 +01:00
Decouple Tree from client app's hotkey system by adding getSelectedItems() to TreeHandle and having callers register hotkeys externally. Extract shared action callbacks to eliminate duplication between hotkey and context menu handlers. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
32 lines
942 B
TypeScript
32 lines
942 B
TypeScript
import { Button, type ButtonProps } from "@yaakapp-internal/ui";
|
|
import { useCallback, useState } from "react";
|
|
import type { ActionInvocation } from "@yaakapp-internal/proxy-lib";
|
|
import { useActionMetadata } from "./hooks";
|
|
import { rpc } from "./rpc";
|
|
|
|
type ActionButtonProps = Omit<ButtonProps, "onClick" | "children"> & {
|
|
action: ActionInvocation;
|
|
/** Override the label from metadata */
|
|
children?: React.ReactNode;
|
|
};
|
|
|
|
export function ActionButton({ action, children, ...props }: ActionButtonProps) {
|
|
const meta = useActionMetadata(action);
|
|
const [busy, setBusy] = useState(false);
|
|
|
|
const onClick = useCallback(async () => {
|
|
setBusy(true);
|
|
try {
|
|
await rpc("execute_action", action);
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
}, [action]);
|
|
|
|
return (
|
|
<Button {...props} disabled={props.disabled || busy} isLoading={busy} onClick={onClick}>
|
|
{children ?? meta?.label ?? "…"}
|
|
</Button>
|
|
);
|
|
}
|