'use client'; import { useQueryClient } from '@tanstack/react-query'; import api from '@/lib/api'; import type { BuildProgress } from '@/components/build-progress-modal'; import { useDeployProgressStore } from '@/lib/deploy-progress-store'; /** Open deploy progress UI immediately and warm build-progress cache. */ export function useDeployProgressActions() { const queryClient = useQueryClient(); const startDeploy = useDeployProgressStore((s) => s.startDeploy); const notifyDeployStarted = (appId: string, appName?: string) => { startDeploy(appId, appName); void queryClient.invalidateQueries({ queryKey: ['applications'] }); void queryClient.invalidateQueries({ queryKey: ['application', appId] }); void queryClient.invalidateQueries({ queryKey: ['deployments', appId] }); void queryClient.prefetchQuery({ queryKey: ['build-progress', appId], queryFn: () => api .get<{ progress: BuildProgress | null }>(`/deployments/applications/${appId}/build-progress`) .then((r) => r.data.progress), staleTime: 0, }); }; return { notifyDeployStarted }; }