mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-17 00:56:37 +01:00
25 lines
853 B
TypeScript
25 lines
853 B
TypeScript
import type { EnvironmentVariable } from '@yaakapp-internal/models';
|
|
import { useAtomValue } from 'jotai';
|
|
import { useMemo } from 'react';
|
|
import { activeEnvironmentAtom } from './useActiveEnvironment';
|
|
import { useEnvironmentsBreakdown } from './useEnvironmentsBreakdown';
|
|
|
|
export function useActiveEnvironmentVariables() {
|
|
const { baseEnvironment } = useEnvironmentsBreakdown();
|
|
const activeEnvironment = useAtomValue(activeEnvironmentAtom);
|
|
return useMemo(() => {
|
|
const varMap: Record<string, EnvironmentVariable> = {};
|
|
const allVariables = [
|
|
...(baseEnvironment?.variables ?? []),
|
|
...(activeEnvironment?.variables ?? []),
|
|
];
|
|
|
|
for (const v of allVariables) {
|
|
if (!v.enabled || !v.name) continue;
|
|
varMap[v.name] = v;
|
|
}
|
|
|
|
return Object.values(varMap);
|
|
}, [activeEnvironment, baseEnvironment]);
|
|
}
|