mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-26 19:31:12 +01:00
Start on plugin ctx API (#64)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { useEffect, useMemo } from 'react';
|
||||
import { getKeyValue } from '../lib/keyValueStore';
|
||||
import { useActiveEnvironmentId } from './useActiveEnvironmentId';
|
||||
import { useActiveWorkspaceId } from './useActiveWorkspaceId';
|
||||
import { useActiveEnvironment } from './useActiveEnvironment';
|
||||
import { useActiveWorkspace } from './useActiveWorkspace';
|
||||
import { useEnvironments } from './useEnvironments';
|
||||
import { useKeyValue } from './useKeyValue';
|
||||
|
||||
@@ -11,10 +11,10 @@ const fallback: string[] = [];
|
||||
|
||||
export function useRecentEnvironments() {
|
||||
const environments = useEnvironments();
|
||||
const activeWorkspaceId = useActiveWorkspaceId();
|
||||
const activeEnvironmentId = useActiveEnvironmentId();
|
||||
const activeWorkspace = useActiveWorkspace();
|
||||
const [activeEnvironment] = useActiveEnvironment();
|
||||
const kv = useKeyValue<string[]>({
|
||||
key: kvKey(activeWorkspaceId ?? 'n/a'),
|
||||
key: kvKey(activeWorkspace?.id ?? 'n/a'),
|
||||
namespace,
|
||||
fallback,
|
||||
});
|
||||
@@ -22,12 +22,12 @@ export function useRecentEnvironments() {
|
||||
// Set history when active request changes
|
||||
useEffect(() => {
|
||||
kv.set((currentHistory: string[]) => {
|
||||
if (activeEnvironmentId === null) return currentHistory;
|
||||
const withoutCurrentEnvironment = currentHistory.filter((id) => id !== activeEnvironmentId);
|
||||
return [activeEnvironmentId, ...withoutCurrentEnvironment];
|
||||
if (activeEnvironment === null) return currentHistory;
|
||||
const withoutCurrentEnvironment = currentHistory.filter((id) => id !== activeEnvironment.id);
|
||||
return [activeEnvironment.id, ...withoutCurrentEnvironment];
|
||||
}).catch(console.error);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [activeEnvironmentId]);
|
||||
}, [activeEnvironment?.id]);
|
||||
|
||||
const onlyValidIds = useMemo(
|
||||
() => kv.value?.filter((id) => environments.some((e) => e.id === id)) ?? [],
|
||||
|
||||
Reference in New Issue
Block a user