mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-24 01:38:26 +02:00
More tweaking
This commit is contained in:
29
apps/yaak-proxy/components/ActionIconButton.tsx
Normal file
29
apps/yaak-proxy/components/ActionIconButton.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
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}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user