Files
expo-popcore-app/hooks/use-template-actions.ts
imeepos fce99a57bf fix: 修复所有 TypeScript 类型错误
- 修复 useTemplates hook 中缺失的必需参数 (page, limit)
- 修复 searchResults 中 execute 和 refetch 的参数类型
- 修复 aspectRatio 类型从 string 转换为 number
- 修复 loadTags 中缺失的必需参数
- 移除 useTags 中不存在的 isActive 属性
- 修复 useTemplateActions 返回值类型

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-16 14:14:05 +08:00

38 lines
1.0 KiB
TypeScript

import { root } from '@repo/core'
import { type RunTemplateInput, TemplateController } from '@repo/sdk'
import { useCallback, useState } from 'react'
import { type ApiError } from '@/lib/types'
import { handleError } from './use-error'
export const useTemplateActions = () => {
const [loading, setLoading] = useState(false)
const [error, setError] = useState<ApiError | null>(null)
const runTemplate = useCallback(async (params: RunTemplateInput): Promise<{ generationId?: string; error?: ApiError }> => {
setLoading(true)
setError(null)
const template = root.get(TemplateController)
const { data, error } = await handleError(async () => await template.run({
templateId: params.templateId,
data: params.data || {},
}))
setLoading(false)
if (error) {
setError(error)
return { error }
}
return { generationId: data?.generationId }
}, [])
return {
loading,
error,
runTemplate,
}
}