mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-23 18:01:08 +01:00
Environment dropdown and actions
This commit is contained in:
19
src-web/hooks/useActiveEnvironment.ts
Normal file
19
src-web/hooks/useActiveEnvironment.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import type { Environment } from '../lib/models';
|
||||
import { useActiveEnvironmentId } from './useActiveEnvironmentId';
|
||||
import { useEnvironments } from './useEnvironments';
|
||||
|
||||
export function useActiveEnvironment(): [Environment | null, (environment: Environment) => void] {
|
||||
const [id, setId] = useActiveEnvironmentId();
|
||||
const environments = useEnvironments();
|
||||
const environment = useMemo(
|
||||
() => environments.find((w) => w.id === id) ?? null,
|
||||
[environments, id],
|
||||
);
|
||||
|
||||
const setActiveEnvironment = useCallback((e: Environment) => {
|
||||
setId(e.id)
|
||||
}, [setId]);
|
||||
|
||||
return [environment, setActiveEnvironment];
|
||||
}
|
||||
Reference in New Issue
Block a user