This commit is contained in:
Gregory Schier
2024-12-20 23:49:48 -08:00
committed by GitHub
parent 51a11b6495
commit ecabe9b6ef
83 changed files with 511 additions and 551 deletions

View File

@@ -1,6 +1,5 @@
import { useSearch } from '@tanstack/react-router';
import { getRouteApi, useSearch } from '@tanstack/react-router';
import { useCallback, useMemo } from 'react';
import { Route } from '../routes/workspaces/$workspaceId';
import { useEnvironments } from './useEnvironments';
export function useActiveEnvironment() {
@@ -15,14 +14,18 @@ export function useActiveEnvironment() {
export const QUERY_ENVIRONMENT_ID = 'environment_id';
const routeApi = getRouteApi('/workspaces/$workspaceId/');
function useActiveEnvironmentId() {
// NOTE: This query param is accessed from Rust side, so do not change
const navigate = Route.useNavigate();
const { environmentId: id } = useSearch({ strict: false });
const navigate = routeApi.useNavigate();
const setId = useCallback(
(environment_id: string | null) =>
navigate({ search: (prev) => ({ ...prev, environment_id: environment_id ?? undefined }) }),
navigate({
search: (prev) => ({ ...prev, environment_id: environment_id ?? undefined }),
}),
[navigate],
);