fix: bug
This commit is contained in:
36
hooks/use-rerun-generation.ts
Normal file
36
hooks/use-rerun-generation.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { root } from '@repo/core'
|
||||
import { TemplateController } from '@repo/sdk'
|
||||
import { useCallback, useState } from 'react'
|
||||
|
||||
import { type ApiError } from '@/lib/types'
|
||||
import { handleError } from './use-error'
|
||||
|
||||
export const useRerunGeneration = () => {
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [error, setError] = useState<ApiError | null>(null)
|
||||
|
||||
const rerun = useCallback(async (generationId: string): Promise<{ generationId?: string; error?: ApiError }> => {
|
||||
setLoading(true)
|
||||
setError(null)
|
||||
|
||||
const template = root.get(TemplateController)
|
||||
const { data, error } = await handleError(async () => await template.rerun({
|
||||
generationId,
|
||||
}))
|
||||
|
||||
setLoading(false)
|
||||
|
||||
if (error) {
|
||||
setError(error)
|
||||
return { error }
|
||||
}
|
||||
|
||||
return { generationId: data?.generationId }
|
||||
}, [])
|
||||
|
||||
return {
|
||||
rerun,
|
||||
loading,
|
||||
error,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user