Refactor desktop app into separate client and proxy apps

This commit is contained in:
Gregory Schier
2026-03-06 09:23:19 -08:00
parent e26705f016
commit 6915778c06
613 changed files with 1356 additions and 812 deletions

View File

@@ -0,0 +1,53 @@
import { cookieJarsAtom } from '@yaakapp-internal/models';
import { useAtomValue } from 'jotai';
import { useEffect, useMemo } from 'react';
import { jotaiStore } from '../lib/jotai';
import { getKeyValue, setKeyValue } from '../lib/keyValueStore';
import { activeCookieJarAtom } from './useActiveCookieJar';
import { useKeyValue } from './useKeyValue';
const kvKey = (workspaceId: string) => `recent_cookie_jars::${workspaceId}`;
const namespace = 'global';
const fallback: string[] = [];
export function useRecentCookieJars() {
const cookieJars = useAtomValue(cookieJarsAtom);
const kv = useKeyValue<string[]>({
key: kvKey(cookieJars[0]?.workspaceId ?? 'n/a'),
namespace,
fallback,
});
const onlyValidIds = useMemo(
() => kv.value?.filter((id) => cookieJars?.some((e) => e.id === id)) ?? [],
[kv.value, cookieJars],
);
return onlyValidIds;
}
export function useSubscribeRecentCookieJars() {
useEffect(() => {
return jotaiStore.sub(activeCookieJarAtom, async () => {
const activeCookieJar = jotaiStore.get(activeCookieJarAtom);
if (activeCookieJar == null) return;
const key = kvKey(activeCookieJar.workspaceId);
const recentIds = getKeyValue<string[]>({ namespace, key, fallback });
if (recentIds[0] === activeCookieJar.id) return; // Short-circuit
const withoutActiveId = recentIds.filter((id) => id !== activeCookieJar.id);
const value = [activeCookieJar.id, ...withoutActiveId];
await setKeyValue({ namespace, key, value });
});
}, []);
}
export async function getRecentCookieJars(workspaceId: string) {
return getKeyValue<string[]>({
namespace,
key: kvKey(workspaceId),
fallback,
});
}