mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-19 23:31:21 +02:00
A bunch of fixes
This commit is contained in:
@@ -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 });
|
||||
});
|
||||
}, []);
|
||||
|
||||
Reference in New Issue
Block a user