mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-18 23:09:47 +02:00
Refactor desktop app into separate client and proxy apps
This commit is contained in:
29
apps/yaak-client/hooks/useActiveEnvironment.ts
Normal file
29
apps/yaak-client/hooks/useActiveEnvironment.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { useSearch } from '@tanstack/react-router';
|
||||
import type { Environment } from '@yaakapp-internal/models';
|
||||
import { environmentsAtom } from '@yaakapp-internal/models';
|
||||
import { atom, useAtomValue } from 'jotai';
|
||||
import { useEffect } from 'react';
|
||||
import { jotaiStore } from '../lib/jotai';
|
||||
|
||||
export const activeEnvironmentIdAtom = atom<string>();
|
||||
|
||||
export const activeEnvironmentAtom = atom<Environment | null>((get) => {
|
||||
const activeEnvironmentId = get(activeEnvironmentIdAtom);
|
||||
return get(environmentsAtom).find((e) => e.id === activeEnvironmentId) ?? null;
|
||||
});
|
||||
|
||||
export function useActiveEnvironment() {
|
||||
return useAtomValue(activeEnvironmentAtom);
|
||||
}
|
||||
|
||||
export function getActiveEnvironment() {
|
||||
return jotaiStore.get(activeEnvironmentAtom);
|
||||
}
|
||||
|
||||
export function useSubscribeActiveEnvironmentId() {
|
||||
const { environment_id } = useSearch({ strict: false });
|
||||
useEffect(
|
||||
() => jotaiStore.set(activeEnvironmentIdAtom, environment_id ?? undefined),
|
||||
[environment_id],
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user