Files
opencode-manager/frontend/src/hooks/useChangeWalkthrough.ts
T
Chris Scott 485ab940aa feat(ui): dock repo and session tools in a desktop side panel
Add a docked desktop tool panel with an icon rail, driven by the shared panel URL param, and keep the mobile dialogs and drawers. Extract dialog bodies into reusable content components, rename the walkthrough dialog to a sheet, and make walkthrough generation asynchronous with client polling.
2026-10-07 23:58:56 -04:00

35 lines
1.3 KiB
TypeScript

import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { generateChangeWalkthrough, getChangeWalkthrough } from '@/api/changeWalkthroughs'
import type { GenerateChangeWalkthroughRequest } from '@opencode-manager/shared/schemas'
const GENERATING_POLL_INTERVAL_MS = 2_000
export function changeWalkthroughQueryKey(sessionId: string) {
return ['change-walkthrough', sessionId] as const
}
export function useChangeWalkthrough(sessionId: string | undefined, enabled: boolean) {
return useQuery({
queryKey: changeWalkthroughQueryKey(sessionId ?? ''),
queryFn: () => getChangeWalkthrough(sessionId!),
enabled: enabled && !!sessionId,
staleTime: 30_000,
refetchInterval: (query) => (query.state.data?.generating ? GENERATING_POLL_INTERVAL_MS : false),
})
}
export function useGenerateChangeWalkthrough(sessionId: string | undefined) {
const queryClient = useQueryClient()
return useMutation({
mutationFn: async (request: GenerateChangeWalkthroughRequest) => {
const targetSessionId = sessionId!
const state = await generateChangeWalkthrough(targetSessionId, request)
return { sessionId: targetSessionId, state }
},
onSuccess: ({ sessionId: targetSessionId, state }) => {
queryClient.setQueryData(changeWalkthroughQueryKey(targetSessionId), state)
},
})
}