mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-18 23:43:55 +01:00
Filesystem Sync (#142)
This commit is contained in:
@@ -11,13 +11,17 @@ const fallback: string[] = [];
|
||||
|
||||
export function useRecentWorkspaces() {
|
||||
const workspaces = useWorkspaces();
|
||||
const { value } = useKeyValue<string[]>({ key: kvKey(), namespace, fallback });
|
||||
const { value, isLoading } = useKeyValue<string[]>({ key: kvKey(), namespace, fallback });
|
||||
|
||||
const onlyValidIds = useMemo(
|
||||
() => value?.filter((id) => workspaces.some((w) => w.id === id)) ?? [],
|
||||
[value, workspaces],
|
||||
);
|
||||
|
||||
|
||||
console.log("HELLO", {isLoading, value})
|
||||
if (isLoading) return null;
|
||||
|
||||
return onlyValidIds;
|
||||
}
|
||||
|
||||
@@ -25,15 +29,18 @@ export function useSubscribeRecentWorkspaces() {
|
||||
useEffect(() => {
|
||||
return jotaiStore.sub(activeWorkspaceIdAtom, async () => {
|
||||
const activeWorkspaceId = jotaiStore.get(activeWorkspaceIdAtom);
|
||||
console.log("AAA");
|
||||
if (activeWorkspaceId == null) return;
|
||||
|
||||
const key = kvKey();
|
||||
|
||||
const recentIds = await getKeyValue<string[]>({ namespace, key, fallback });
|
||||
console.log("BBB", recentIds, activeWorkspaceId);
|
||||
if (recentIds[0] === activeWorkspaceId) return; // Short-circuit
|
||||
|
||||
const withoutActiveId = recentIds.filter((id) => id !== activeWorkspaceId);
|
||||
const value = [activeWorkspaceId, ...withoutActiveId];
|
||||
console.log("SET ACTIVE WORCENT", value);
|
||||
await setKeyValue({ namespace, key, value });
|
||||
});
|
||||
}, []);
|
||||
|
||||
Reference in New Issue
Block a user