mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-20 16:44:06 +01:00
Performance sweep (#147)
This commit is contained in:
@@ -7,6 +7,7 @@ import type {
|
||||
} from '@yaakapp-internal/plugin';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { usePluginsKey } from './usePlugins';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
export type CallableHttpRequestAction = Pick<HttpRequestAction, 'key' | 'label' | 'icon'> & {
|
||||
call: (httpRequest: HttpRequest) => Promise<void>;
|
||||
@@ -15,32 +16,35 @@ export type CallableHttpRequestAction = Pick<HttpRequestAction, 'key' | 'label'
|
||||
export function useHttpRequestActions() {
|
||||
const pluginsKey = usePluginsKey();
|
||||
|
||||
const httpRequestActions = useQuery({
|
||||
const actionsResult = useQuery<CallableHttpRequestAction[]>({
|
||||
queryKey: ['http_request_actions', pluginsKey],
|
||||
queryFn: async () => {
|
||||
const responses = (await invokeCmd(
|
||||
const responses = await invokeCmd<GetHttpRequestActionsResponse[]>(
|
||||
'cmd_http_request_actions',
|
||||
)) as GetHttpRequestActionsResponse[];
|
||||
return responses;
|
||||
);
|
||||
|
||||
return responses.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 });
|
||||
},
|
||||
})),
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
const actions: CallableHttpRequestAction[] =
|
||||
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 });
|
||||
},
|
||||
})),
|
||||
) ?? [];
|
||||
const actions = useMemo(() => {
|
||||
return actionsResult.data ?? [];
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [JSON.stringify(actionsResult.data)]);
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user