mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-26 11:21:16 +01:00
Move workspace menu, better env mgmt, QoL
This commit is contained in:
@@ -1,18 +1,34 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { invoke } from '@tauri-apps/api';
|
||||
import type { Environment } from '../lib/models';
|
||||
import { environmentsQueryKey } from './useEnvironments';
|
||||
import { environmentsQueryKey, useEnvironments } from './useEnvironments';
|
||||
import { useActiveWorkspaceId } from './useActiveWorkspaceId';
|
||||
import { useAppRoutes } from './useAppRoutes';
|
||||
import { usePrompt } from './usePrompt';
|
||||
import { useWorkspaces } from './useWorkspaces';
|
||||
|
||||
export function useCreateEnvironment() {
|
||||
const routes = useAppRoutes();
|
||||
const prompt = usePrompt();
|
||||
const workspaceId = useActiveWorkspaceId();
|
||||
const queryClient = useQueryClient();
|
||||
const routes = useAppRoutes();
|
||||
const environments = useEnvironments();
|
||||
const workspaces = useWorkspaces();
|
||||
|
||||
return useMutation<Environment, unknown, Pick<Environment, 'name'>>({
|
||||
mutationFn: (patch) => {
|
||||
return invoke('create_environment', { ...patch, workspaceId });
|
||||
return useMutation<Environment, unknown, void>({
|
||||
mutationFn: async () => {
|
||||
const name = await prompt({
|
||||
name: 'name',
|
||||
title: 'Create Environment',
|
||||
description: 'Enter a name for the new environment',
|
||||
label: 'Name',
|
||||
defaultValue: 'My Environment',
|
||||
});
|
||||
const variables =
|
||||
environments.length === 0 && workspaces.length === 1
|
||||
? [{ name: 'first_variable', value: 'some reusable value' }]
|
||||
: [];
|
||||
return invoke('create_environment', { name, variables, workspaceId });
|
||||
},
|
||||
onSuccess: async (environment) => {
|
||||
if (workspaceId == null) return;
|
||||
|
||||
Reference in New Issue
Block a user