mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-17 23:13:51 +01:00
A bunch of fixes
This commit is contained in:
@@ -4,7 +4,18 @@ import { atom, useAtomValue } from 'jotai';
|
||||
export const environmentsBreakdownAtom = atom((get) => {
|
||||
const allEnvironments = get(environmentsAtom);
|
||||
const baseEnvironments = allEnvironments.filter((e) => e.parentModel === 'workspace') ?? [];
|
||||
const subEnvironments = allEnvironments.filter((e) => e.parentModel === 'environment') ?? [];
|
||||
|
||||
const subEnvironments =
|
||||
allEnvironments
|
||||
.filter((e) => e.parentModel === 'environment')
|
||||
?.sort((a, b) => {
|
||||
if (a.sortPriority === b.sortPriority) {
|
||||
return a.updatedAt > b.updatedAt ? 1 : -1;
|
||||
} else {
|
||||
return a.sortPriority - b.sortPriority;
|
||||
}
|
||||
}) ?? [];
|
||||
|
||||
const folderEnvironments =
|
||||
allEnvironments.filter((e) => e.parentModel === 'folder' && e.parentId != null) ?? [];
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import { useEffect, useMemo } from 'react';
|
||||
import { jotaiStore } from '../lib/jotai';
|
||||
import { getKeyValue, setKeyValue } from '../lib/keyValueStore';
|
||||
import { activeCookieJarAtom } from './useActiveCookieJar';
|
||||
import { activeWorkspaceIdAtom } from './useActiveWorkspace';
|
||||
import { useKeyValue } from './useKeyValue';
|
||||
|
||||
const kvKey = (workspaceId: string) => 'recent_cookie_jars::' + workspaceId;
|
||||
@@ -13,9 +12,8 @@ const fallback: string[] = [];
|
||||
|
||||
export function useRecentCookieJars() {
|
||||
const cookieJars = useAtomValue(cookieJarsAtom);
|
||||
const activeWorkspaceId = useAtomValue(activeWorkspaceIdAtom);
|
||||
const kv = useKeyValue<string[]>({
|
||||
key: kvKey(activeWorkspaceId ?? 'n/a'),
|
||||
key: kvKey(cookieJars[0]?.workspaceId ?? 'n/a'),
|
||||
namespace,
|
||||
fallback,
|
||||
});
|
||||
@@ -31,18 +29,16 @@ export function useRecentCookieJars() {
|
||||
export function useSubscribeRecentCookieJars() {
|
||||
useEffect(() => {
|
||||
return jotaiStore.sub(activeCookieJarAtom, async () => {
|
||||
const activeWorkspaceId = jotaiStore.get(activeWorkspaceIdAtom);
|
||||
const activeCookieJarId = jotaiStore.get(activeCookieJarAtom)?.id ?? null;
|
||||
if (activeWorkspaceId == null) return;
|
||||
if (activeCookieJarId == null) return;
|
||||
const activeCookieJar = jotaiStore.get(activeCookieJarAtom);
|
||||
if (activeCookieJar == null) return;
|
||||
|
||||
const key = kvKey(activeWorkspaceId);
|
||||
const key = kvKey(activeCookieJar.workspaceId);
|
||||
|
||||
const recentIds = getKeyValue<string[]>({ namespace, key, fallback });
|
||||
if (recentIds[0] === activeCookieJarId) return; // Short-circuit
|
||||
if (recentIds[0] === activeCookieJar.id) return; // Short-circuit
|
||||
|
||||
const withoutActiveId = recentIds.filter((id) => id !== activeCookieJarId);
|
||||
const value = [activeCookieJarId, ...withoutActiveId];
|
||||
const withoutActiveId = recentIds.filter((id) => id !== activeCookieJar.id);
|
||||
const value = [activeCookieJar.id, ...withoutActiveId];
|
||||
await setKeyValue({ namespace, key, value });
|
||||
});
|
||||
}, []);
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { useEffect, useMemo } from 'react';
|
||||
import { jotaiStore } from '../lib/jotai';
|
||||
import { getKeyValue, setKeyValue } from '../lib/keyValueStore';
|
||||
import { activeEnvironmentIdAtom } from './useActiveEnvironment';
|
||||
import { activeWorkspaceAtom, activeWorkspaceIdAtom } from './useActiveWorkspace';
|
||||
import { activeEnvironmentAtom } from './useActiveEnvironment';
|
||||
import { useEnvironmentsBreakdown } from './useEnvironmentsBreakdown';
|
||||
import { useKeyValue } from './useKeyValue';
|
||||
|
||||
@@ -12,10 +10,9 @@ const namespace = 'global';
|
||||
const fallback: string[] = [];
|
||||
|
||||
export function useRecentEnvironments() {
|
||||
const { subEnvironments } = useEnvironmentsBreakdown();
|
||||
const activeWorkspace = useAtomValue(activeWorkspaceAtom);
|
||||
const { subEnvironments, allEnvironments } = useEnvironmentsBreakdown();
|
||||
const kv = useKeyValue<string[]>({
|
||||
key: kvKey(activeWorkspace?.id ?? 'n/a'),
|
||||
key: kvKey(allEnvironments[0]?.workspaceId ?? 'n/a'),
|
||||
namespace,
|
||||
fallback,
|
||||
});
|
||||
@@ -30,19 +27,16 @@ export function useRecentEnvironments() {
|
||||
|
||||
export function useSubscribeRecentEnvironments() {
|
||||
useEffect(() => {
|
||||
return jotaiStore.sub(activeEnvironmentIdAtom, async () => {
|
||||
const activeWorkspaceId = jotaiStore.get(activeWorkspaceIdAtom);
|
||||
const activeEnvironmentId = jotaiStore.get(activeEnvironmentIdAtom);
|
||||
if (activeWorkspaceId == null) return;
|
||||
if (activeEnvironmentId == null) return;
|
||||
|
||||
const key = kvKey(activeWorkspaceId);
|
||||
return jotaiStore.sub(activeEnvironmentAtom, async () => {
|
||||
const activeEnvironment = jotaiStore.get(activeEnvironmentAtom);
|
||||
if (activeEnvironment == null) return;
|
||||
|
||||
const key = kvKey(activeEnvironment.workspaceId);
|
||||
const recentIds = getKeyValue<string[]>({ namespace, key, fallback });
|
||||
if (recentIds[0] === activeEnvironmentId) return; // Short-circuit
|
||||
if (recentIds[0] === activeEnvironment.id) return; // Short-circuit
|
||||
|
||||
const withoutActiveId = recentIds.filter((id) => id !== activeEnvironmentId);
|
||||
const value = [activeEnvironmentId, ...withoutActiveId];
|
||||
const withoutActiveId = recentIds.filter((id) => id !== activeEnvironment.id);
|
||||
const value = [activeEnvironment.id, ...withoutActiveId];
|
||||
await setKeyValue({ namespace, key, value });
|
||||
});
|
||||
}, []);
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { useEffect, useMemo } from 'react';
|
||||
import { jotaiStore } from '../lib/jotai';
|
||||
import { getKeyValue, setKeyValue } from '../lib/keyValueStore';
|
||||
import { activeRequestIdAtom } from './useActiveRequestId';
|
||||
import { activeWorkspaceIdAtom } from './useActiveWorkspace';
|
||||
import { useKeyValue } from './useKeyValue';
|
||||
import { useAllRequests } from './useAllRequests';
|
||||
import { activeRequestAtom } from './useActiveRequest';
|
||||
|
||||
const kvKey = (workspaceId: string) => 'recent_requests::' + workspaceId;
|
||||
const namespace = 'global';
|
||||
@@ -13,10 +11,9 @@ const fallback: string[] = [];
|
||||
|
||||
export function useRecentRequests() {
|
||||
const requests = useAllRequests();
|
||||
const activeWorkspaceId = useAtomValue(activeWorkspaceIdAtom);
|
||||
|
||||
const { set: setRecentRequests, value: recentRequests } = useKeyValue<string[]>({
|
||||
key: kvKey(activeWorkspaceId ?? 'n/a'),
|
||||
key: kvKey(requests[0]?.workspaceId ?? 'n/a'),
|
||||
namespace,
|
||||
fallback,
|
||||
});
|
||||
@@ -31,19 +28,17 @@ export function useRecentRequests() {
|
||||
|
||||
export function useSubscribeRecentRequests() {
|
||||
useEffect(() => {
|
||||
return jotaiStore.sub(activeRequestIdAtom, async () => {
|
||||
const activeWorkspaceId = jotaiStore.get(activeWorkspaceIdAtom);
|
||||
const activeRequestId = jotaiStore.get(activeRequestIdAtom);
|
||||
if (activeWorkspaceId == null) return;
|
||||
if (activeRequestId == null) return;
|
||||
return jotaiStore.sub(activeRequestAtom, async () => {
|
||||
const activeRequest = jotaiStore.get(activeRequestAtom);
|
||||
if (activeRequest == null) return;
|
||||
|
||||
const key = kvKey(activeWorkspaceId);
|
||||
const key = kvKey(activeRequest.workspaceId);
|
||||
|
||||
const recentIds = getKeyValue<string[]>({ namespace, key, fallback });
|
||||
if (recentIds[0] === activeRequestId) return; // Short-circuit
|
||||
if (recentIds[0] === activeRequest.id) return; // Short-circuit
|
||||
|
||||
const withoutActiveId = recentIds.filter((id) => id !== activeRequestId);
|
||||
const value = [activeRequestId, ...withoutActiveId];
|
||||
const withoutActiveId = recentIds.filter((id) => id !== activeRequest.id);
|
||||
const value = [activeRequest.id, ...withoutActiveId];
|
||||
await setKeyValue({ namespace, key, value });
|
||||
});
|
||||
}, []);
|
||||
|
||||
Reference in New Issue
Block a user