Environments in URL and better rendering

This commit is contained in:
Gregory Schier
2023-10-25 11:13:00 -07:00
parent 3b660ddbd0
commit 33c406ce49
44 changed files with 226 additions and 160 deletions

View File

@@ -4,18 +4,21 @@ import type { Environment } from '../lib/models';
import { environmentsQueryKey } from './useEnvironments';
import { useActiveWorkspaceId } from './useActiveWorkspaceId';
import { useActiveEnvironmentId } from './useActiveEnvironmentId';
import { useAppRoutes } from './useAppRoutes';
export function useCreateEnvironment() {
const environmentId = useActiveEnvironmentId();
const workspaceId = useActiveWorkspaceId();
const queryClient = useQueryClient();
const [, setActiveEnvironmentId ] = useActiveEnvironmentId();
const routes = useAppRoutes();
return useMutation<Environment, unknown, Pick<Environment, 'name'>>({
mutationFn: (patch) => {
return invoke('create_environment', { ...patch, workspaceId });
},
onSuccess: async (environment) => {
if (workspaceId == null) return;
setActiveEnvironmentId(environment.id);
routes.navigate('workspace', { workspaceId, environmentId });
queryClient.setQueryData<Environment[]>(
environmentsQueryKey({ workspaceId }),
(environments) => [...(environments ?? []), environment],