4-10 树域 Rust 家族化

This commit is contained in:
lix-2026
2026-04-24 06:10:18 +08:00
parent 41e958769e
commit 94631f3636
49 changed files with 5751 additions and 557 deletions
+16 -19
View File
@@ -1,9 +1,6 @@
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useQuery } from "@tanstack/react-query";
import {
buildSidebarDataSyncKey,
getSidebarDataFreshness,
} from "@/components/sidebar/sidebar-sync";
import { buildSidebarDataSyncKey } from "@/components/sidebar/sidebar-sync";
import type { SidebarInitialData } from "@/components/sidebar/types";
import { useConvexSidebarData } from "@/hooks/use-convex-sidebar-data";
@@ -56,9 +53,11 @@ export function useSidebarData(initialData: SidebarInitialData): SidebarDataResu
const [manualSnapshotState, setManualSnapshotState] = useState<{
workspaceId: string;
data: SidebarInitialData | null;
baseSyncKey: string | null;
}>({
workspaceId,
data: null,
baseSyncKey: null,
});
const httpQuery = useQuery({
@@ -73,40 +72,37 @@ export function useSidebarData(initialData: SidebarInitialData): SidebarDataResu
manualSnapshotState.workspaceId === workspaceId
? manualSnapshotState.data
: null;
const manualSnapshotBaseSyncKey =
manualSnapshotState.workspaceId === workspaceId
? manualSnapshotState.baseSyncKey
: null;
const baseLiveData = convexSidebar.data ?? httpQuery.data ?? initialData;
const baseLiveDataSyncKey = useMemo(
() => buildSidebarDataSyncKey(baseLiveData),
[baseLiveData],
);
const baseLiveDataFreshness = useMemo(
() => getSidebarDataFreshness(baseLiveData),
[baseLiveData],
);
const manualSnapshotSyncKey = useMemo(
() => (manualSnapshot ? buildSidebarDataSyncKey(manualSnapshot) : null),
[manualSnapshot],
);
const manualSnapshotFreshness = useMemo(
() => (manualSnapshot ? getSidebarDataFreshness(manualSnapshot) : Number.NEGATIVE_INFINITY),
[manualSnapshot],
);
const liveData = useMemo(() => {
if (!manualSnapshot) {
return baseLiveData;
}
if (manualSnapshotSyncKey === baseLiveDataSyncKey) {
return baseLiveData;
if (
manualSnapshotBaseSyncKey === baseLiveDataSyncKey &&
manualSnapshotSyncKey &&
manualSnapshotSyncKey !== baseLiveDataSyncKey
) {
return manualSnapshot;
}
return manualSnapshotFreshness >= baseLiveDataFreshness
? manualSnapshot
: baseLiveData;
return baseLiveData;
}, [
baseLiveData,
baseLiveDataFreshness,
baseLiveDataSyncKey,
manualSnapshot,
manualSnapshotFreshness,
manualSnapshotBaseSyncKey,
manualSnapshotSyncKey,
]);
const isLoading =
@@ -145,6 +141,7 @@ export function useSidebarData(initialData: SidebarInitialData): SidebarDataResu
setManualSnapshotState({
workspaceId,
data: refreshedSnapshot,
baseSyncKey: buildSidebarDataSyncKey(liveDataRef.current),
});
return refreshedSnapshot;
} catch {