Performance sweep (#147)

This commit is contained in:
Gregory Schier
2024-12-20 17:31:15 -08:00
committed by GitHub
parent 42bf016e90
commit 27134a52ad
85 changed files with 2337 additions and 1413 deletions

View File

@@ -1,5 +1,6 @@
import { useSearch } from '@tanstack/react-router';
import { useCallback, useMemo } from 'react';
import { useSearchParams } from 'react-router-dom';
import { Route } from '../routes/workspaces/$workspaceId';
import { useEnvironments } from './useEnvironments';
export function useActiveEnvironment() {
@@ -16,22 +17,13 @@ export const QUERY_ENVIRONMENT_ID = 'environment_id';
function useActiveEnvironmentId() {
// NOTE: This query param is accessed from Rust side, so do not change
const [params, setParams] = useSearchParams();
const id = params.get(QUERY_ENVIRONMENT_ID);
const navigate = Route.useNavigate();
const { environmentId: id } = useSearch({ strict: false });
const setId = useCallback(
(id: string | null) => {
setParams((p) => {
const existing = Object.fromEntries(p);
if (id == null) {
delete existing[QUERY_ENVIRONMENT_ID];
} else {
existing[QUERY_ENVIRONMENT_ID] = id;
}
return existing;
});
},
[setParams],
(environment_id: string | null) =>
navigate({ search: (prev) => ({ ...prev, environment_id: environment_id ?? undefined }) }),
[navigate],
);
return [id, setId] as const;