mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-01 15:03:11 +02:00
Fix performance related to having 100s of requests (#123)
This commit is contained in:
@@ -1,20 +1,9 @@
|
||||
import type { Environment } from '@yaakapp-internal/models';
|
||||
import { atom, useAtom } from 'jotai/index';
|
||||
import { useEffect } from 'react';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { useActiveWorkspace } from './useActiveWorkspace';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { atom } from 'jotai/index';
|
||||
|
||||
export const environmentsAtom = atom<Environment[]>([]);
|
||||
|
||||
export function useEnvironments() {
|
||||
const [items, setItems] = useAtom(environmentsAtom);
|
||||
const workspace = useActiveWorkspace();
|
||||
|
||||
// Fetch new requests when workspace changes
|
||||
useEffect(() => {
|
||||
if (workspace == null) return;
|
||||
invokeCmd<Environment[]>('cmd_list_environments', { workspaceId: workspace.id }).then(setItems);
|
||||
}, [setItems, workspace]);
|
||||
|
||||
return items;
|
||||
return useAtomValue(environmentsAtom);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user