Files
expo-popcore-app/hooks/use-template-actions.ts
imeepos 4d1e901032 fix: 修复所有 TypeScript 类型错误
- 修复 webpPreviewUrl -> previewUrl 字段名错误
- 修复 video.tsx 中的 useTemplates 参数类型问题
- 修复 video.tsx 中 position 重复定义问题
- 修复 searchResults.tsx 中的 SearchResultItem 类型不匹配
- 修复 SearchResultsGrid.tsx 中不存在的 scrollContent 样式
- 修复 use-templates.ts 中 page 可能是 undefined 的类型问题
- 添加 tsconfig.json 的 exclude 配置
- 修复 use-template-actions.ts 中 null 不能赋值给 ApiError 的问题

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

36 lines
1.0 KiB
TypeScript

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