Update files
This commit is contained in:
@@ -42,6 +42,7 @@ export function useCheckoutStatusQuery({ serverId, cwd }: UseCheckoutStatusQuery
|
|||||||
const desktopFileExplorerOpen = usePanelStore((state) => state.desktop.fileExplorerOpen);
|
const desktopFileExplorerOpen = usePanelStore((state) => state.desktop.fileExplorerOpen);
|
||||||
const explorerTab = usePanelStore((state) => state.explorerTab);
|
const explorerTab = usePanelStore((state) => state.explorerTab);
|
||||||
const isOpen = isMobile ? mobileView === "file-explorer" : desktopFileExplorerOpen;
|
const isOpen = isMobile ? mobileView === "file-explorer" : desktopFileExplorerOpen;
|
||||||
|
const shouldPoll = isOpen && explorerTab === "changes";
|
||||||
|
|
||||||
const query = useQuery({
|
const query = useQuery({
|
||||||
queryKey: checkoutStatusQueryKey(serverId, cwd),
|
queryKey: checkoutStatusQueryKey(serverId, cwd),
|
||||||
@@ -53,8 +54,12 @@ export function useCheckoutStatusQuery({ serverId, cwd }: UseCheckoutStatusQuery
|
|||||||
},
|
},
|
||||||
enabled: !!client && isConnected && !!cwd,
|
enabled: !!client && isConnected && !!cwd,
|
||||||
staleTime: CHECKOUT_STATUS_STALE_TIME,
|
staleTime: CHECKOUT_STATUS_STALE_TIME,
|
||||||
refetchInterval: 10_000,
|
refetchInterval: (query) => {
|
||||||
refetchIntervalInBackground: true,
|
if (!shouldPoll) return false;
|
||||||
|
const data = query.state.data as CheckoutStatusPayload | undefined;
|
||||||
|
return data?.isGit ? 10_000 : false;
|
||||||
|
},
|
||||||
|
refetchIntervalInBackground: shouldPoll,
|
||||||
refetchOnMount: "always",
|
refetchOnMount: "always",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { useEffect, useMemo, useState } from "react";
|
import { useEffect, useMemo } from "react";
|
||||||
import { useQueryClient } from "@tanstack/react-query";
|
import { useQueries } from "@tanstack/react-query";
|
||||||
import {
|
import {
|
||||||
checkoutStatusQueryKey,
|
checkoutStatusQueryKey,
|
||||||
type CheckoutStatusPayload,
|
type CheckoutStatusPayload,
|
||||||
|
CHECKOUT_STATUS_STALE_TIME,
|
||||||
} from "@/hooks/use-checkout-status-query";
|
} from "@/hooks/use-checkout-status-query";
|
||||||
import { groupAgents } from "@/utils/agent-grouping";
|
import { groupAgents } from "@/utils/agent-grouping";
|
||||||
import { useSectionOrderStore, sortProjectsByStoredOrder } from "@/stores/section-order-store";
|
import { useSectionOrderStore, sortProjectsByStoredOrder } from "@/stores/section-order-store";
|
||||||
@@ -22,32 +23,31 @@ export interface SidebarSectionData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function useSidebarAgentSections(agents: AggregatedAgent[]): SidebarSectionData[] {
|
export function useSidebarAgentSections(agents: AggregatedAgent[]): SidebarSectionData[] {
|
||||||
const queryClient = useQueryClient();
|
// Subscribe to checkout status cache entries for each visible agent so that grouping
|
||||||
const [checkoutCacheBump, setCheckoutCacheBump] = useState(0);
|
// can switch from cwd→remote as soon as checkout status is prefetched.
|
||||||
|
//
|
||||||
// Re-render when checkout status cache updates so grouping can switch from cwd→remote.
|
// This avoids a brief UI state where two separate sections can render with the
|
||||||
useEffect(() => {
|
// same icon/title while grouping is still keyed by cwd.
|
||||||
const unsubscribe = queryClient.getQueryCache().subscribe((event) => {
|
const checkoutStatusQueries = useQueries({
|
||||||
const queryKey = event?.query?.queryKey;
|
queries: agents.map((agent) => ({
|
||||||
if (!Array.isArray(queryKey) || queryKey[0] !== "checkoutStatus") {
|
queryKey: checkoutStatusQueryKey(agent.serverId, agent.cwd),
|
||||||
return;
|
queryFn: async (): Promise<CheckoutStatusPayload> => {
|
||||||
}
|
throw new Error("Checkout status query is disabled in sidebar grouping");
|
||||||
setCheckoutCacheBump((v) => v + 1);
|
},
|
||||||
});
|
enabled: false,
|
||||||
return unsubscribe;
|
staleTime: CHECKOUT_STATUS_STALE_TIME,
|
||||||
}, [queryClient]);
|
})),
|
||||||
|
});
|
||||||
|
|
||||||
const remoteUrlByAgentKey = useMemo(() => {
|
const remoteUrlByAgentKey = useMemo(() => {
|
||||||
const result = new Map<string, string | null>();
|
const result = new Map<string, string | null>();
|
||||||
for (const agent of agents) {
|
for (let idx = 0; idx < agents.length; idx++) {
|
||||||
const checkout =
|
const agent = agents[idx];
|
||||||
queryClient.getQueryData<CheckoutStatusPayload>(
|
const checkout = checkoutStatusQueries[idx]?.data ?? null;
|
||||||
checkoutStatusQueryKey(agent.serverId, agent.cwd)
|
|
||||||
) ?? null;
|
|
||||||
result.set(`${agent.serverId}:${agent.id}`, checkout?.remoteUrl ?? null);
|
result.set(`${agent.serverId}:${agent.id}`, checkout?.remoteUrl ?? null);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}, [agents, checkoutCacheBump, queryClient]);
|
}, [agents, checkoutStatusQueries]);
|
||||||
|
|
||||||
const projectOrder = useSectionOrderStore((state) => state.projectOrder);
|
const projectOrder = useSectionOrderStore((state) => state.projectOrder);
|
||||||
const setProjectOrder = useSectionOrderStore((state) => state.setProjectOrder);
|
const setProjectOrder = useSectionOrderStore((state) => state.setProjectOrder);
|
||||||
|
|||||||
Reference in New Issue
Block a user