Filesystem Sync (#142)

This commit is contained in:
Gregory Schier
2025-01-03 20:41:00 -08:00
committed by GitHub
parent 6ad27c4458
commit 31440eea76
159 changed files with 4296 additions and 1016 deletions

View File

@@ -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 });
});
}, []);