mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-25 10:51:26 +01:00
Request actions (#65)
This commit is contained in:
37
src-web/hooks/useHttpRequestActions.ts
Normal file
37
src-web/hooks/useHttpRequestActions.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import type {
|
||||
CallHttpRequestActionRequest,
|
||||
GetHttpRequestActionsResponse,
|
||||
HttpRequest,
|
||||
} from '@yaakapp/api';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
|
||||
export function useHttpRequestActions() {
|
||||
const httpRequestActions = useQuery({
|
||||
queryKey: ['http_request_actions'],
|
||||
queryFn: async () => {
|
||||
const responses = (await invokeCmd(
|
||||
'cmd_http_request_actions',
|
||||
)) as GetHttpRequestActionsResponse[];
|
||||
return responses;
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
httpRequestActions.data?.flatMap((r) =>
|
||||
r.actions.map((a) => ({
|
||||
key: a.key,
|
||||
label: a.label,
|
||||
icon: a.icon,
|
||||
call: async (httpRequest: HttpRequest) => {
|
||||
const payload: CallHttpRequestActionRequest = {
|
||||
key: a.key,
|
||||
pluginRefId: r.pluginRefId,
|
||||
args: { httpRequest },
|
||||
};
|
||||
await invokeCmd('cmd_call_http_request_action', { req: payload });
|
||||
},
|
||||
})),
|
||||
) ?? []
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user