mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-28 04:11:45 +01:00
Request actions (#65)
This commit is contained in:
@@ -1,20 +0,0 @@
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { useActiveEnvironment } from './useActiveEnvironment';
|
||||
import { useCopy } from './useCopy';
|
||||
|
||||
export function useCopyAsCurl(requestId: string) {
|
||||
const copy = useCopy();
|
||||
const [environment] = useActiveEnvironment();
|
||||
return useMutation({
|
||||
mutationKey: ['copy_as_curl', requestId],
|
||||
mutationFn: async () => {
|
||||
const cmd: string = await invokeCmd('cmd_request_to_curl', {
|
||||
requestId,
|
||||
environmentId: environment?.id,
|
||||
});
|
||||
copy(cmd);
|
||||
return cmd;
|
||||
},
|
||||
});
|
||||
}
|
||||
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