feat: 收口 Rust Web 3000 主链
This commit is contained in:
@@ -50,15 +50,6 @@ export function useSidebarData(initialData: SidebarInitialData): SidebarDataResu
|
||||
const convexSidebar = useConvexSidebarData(workspaceId);
|
||||
const shouldUseHttpFallback =
|
||||
!convexSidebar.hasLiveSubscription && convexSidebar.canUseHttpFallback;
|
||||
const [manualSnapshotState, setManualSnapshotState] = useState<{
|
||||
workspaceId: string;
|
||||
data: SidebarInitialData | null;
|
||||
baseSyncKey: string | null;
|
||||
}>({
|
||||
workspaceId,
|
||||
data: null,
|
||||
baseSyncKey: null,
|
||||
});
|
||||
|
||||
const httpQuery = useQuery({
|
||||
queryKey: ["sidebar", workspaceId],
|
||||
@@ -68,43 +59,8 @@ export function useSidebarData(initialData: SidebarInitialData): SidebarDataResu
|
||||
enabled: shouldUseHttpFallback,
|
||||
});
|
||||
|
||||
const manualSnapshot =
|
||||
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 manualSnapshotSyncKey = useMemo(
|
||||
() => (manualSnapshot ? buildSidebarDataSyncKey(manualSnapshot) : null),
|
||||
[manualSnapshot],
|
||||
);
|
||||
const liveData = useMemo(() => {
|
||||
if (!manualSnapshot) {
|
||||
return baseLiveData;
|
||||
}
|
||||
if (
|
||||
manualSnapshotBaseSyncKey === baseLiveDataSyncKey &&
|
||||
manualSnapshotSyncKey &&
|
||||
manualSnapshotSyncKey !== baseLiveDataSyncKey
|
||||
) {
|
||||
return manualSnapshot;
|
||||
}
|
||||
return baseLiveData;
|
||||
}, [
|
||||
baseLiveData,
|
||||
baseLiveDataSyncKey,
|
||||
manualSnapshot,
|
||||
manualSnapshotBaseSyncKey,
|
||||
manualSnapshotSyncKey,
|
||||
]);
|
||||
const liveData = baseLiveData;
|
||||
const isLoading =
|
||||
convexSidebar.hasLiveSubscription
|
||||
? convexSidebar.isLoading
|
||||
@@ -135,18 +91,6 @@ export function useSidebarData(initialData: SidebarInitialData): SidebarDataResu
|
||||
}, [httpQuery]);
|
||||
|
||||
const refetch = useCallback(async () => {
|
||||
if (workspaceId) {
|
||||
try {
|
||||
const refreshedSnapshot = await requestSidebarData(workspaceId);
|
||||
setManualSnapshotState({
|
||||
workspaceId,
|
||||
data: refreshedSnapshot,
|
||||
baseSyncKey: buildSidebarDataSyncKey(liveDataRef.current),
|
||||
});
|
||||
return refreshedSnapshot;
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
if (convexSidebar.hasLiveSubscription) {
|
||||
await convexRefetchRef.current();
|
||||
return liveDataRef.current;
|
||||
|
||||
Reference in New Issue
Block a user