mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-25 19:01:38 +01:00
30 lines
905 B
TypeScript
30 lines
905 B
TypeScript
import type { ActionInvocation } from "@yaakapp-internal/proxy-lib";
|
|
import { IconButton, type IconButtonProps } from "@yaakapp-internal/ui";
|
|
import { useCallback } from "react";
|
|
import { useRpcMutation } from "../hooks/useRpcMutation";
|
|
import { useActionMetadata } from "../hooks/useActionMetadata";
|
|
|
|
type ActionIconButtonProps = Omit<IconButtonProps, "onClick" | "title"> & {
|
|
action: ActionInvocation;
|
|
title?: string;
|
|
};
|
|
|
|
export function ActionIconButton({ action, ...props }: ActionIconButtonProps) {
|
|
const meta = useActionMetadata(action);
|
|
const { mutate, isPending } = useRpcMutation("execute_action");
|
|
|
|
const onClick = useCallback(() => {
|
|
mutate(action);
|
|
}, [action, mutate]);
|
|
|
|
return (
|
|
<IconButton
|
|
{...props}
|
|
title={props.title ?? meta?.label ?? "…"}
|
|
disabled={props.disabled || isPending}
|
|
isLoading={isPending}
|
|
onClick={onClick}
|
|
/>
|
|
);
|
|
}
|