mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-22 01:19:13 +01:00
Environment dropdown and actions
This commit is contained in:
@@ -3,20 +3,23 @@ import { invoke } from '@tauri-apps/api';
|
||||
import type { Environment } from '../lib/models';
|
||||
import { environmentsQueryKey } from './useEnvironments';
|
||||
import { useActiveWorkspaceId } from './useActiveWorkspaceId';
|
||||
import { useActiveEnvironmentId } from './useActiveEnvironmentId';
|
||||
|
||||
export function useCreateEnvironment() {
|
||||
const workspaceId = useActiveWorkspaceId();
|
||||
const queryClient = useQueryClient();
|
||||
const [, setActiveEnvironmentId ] = useActiveEnvironmentId();
|
||||
return useMutation<Environment, unknown, Pick<Environment, 'name'>>({
|
||||
mutationFn: (patch) => {
|
||||
return invoke('create_environment', { ...patch, workspaceId });
|
||||
},
|
||||
onSuccess: async (environment) => {
|
||||
if (workspaceId == null) return;
|
||||
queryClient.setQueryData<Environment[]>(environmentsQueryKey({ workspaceId }), (environments) => [
|
||||
...(environments ?? []),
|
||||
environment,
|
||||
]);
|
||||
setActiveEnvironmentId(environment.id);
|
||||
queryClient.setQueryData<Environment[]>(
|
||||
environmentsQueryKey({ workspaceId }),
|
||||
(environments) => [...(environments ?? []), environment],
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user