feat: 对接 templateDetail 页面后端接口

- 创建 hooks/use-error.ts 统一错误处理
- 创建 hooks/use-template-detail.ts 获取模板详情
- 创建 hooks/use-template-generations.ts 获取模板生成记录
- 更新 hooks 使用 handleError 统一错误处理
- 优化 SearchResultsGrid 组件,复用 TemplateGeneration 类型
- 删除不必要的类型转换和重复代码

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
imeepos
2026-01-16 11:56:38 +08:00
parent fb719c6ea2
commit ae120f24d3
9 changed files with 487 additions and 92 deletions

View File

@@ -1,17 +1,38 @@
import { OWNER_ID } from "@/lib/auth"
import { ApiError } from "@/lib/types"
import { root } from '@repo/core'
import { ActivityController, ListActivitiesResult } from "@repo/sdk"
import { useState } from "react"
import { ActivityController, type ListActivitiesInput, type ListActivitiesResult } from '@repo/sdk'
import { useState } from 'react'
import { type ApiError } from '@/lib/types'
import { handleError } from './use-error'
const OWNER_ID = process.env.EXPO_PUBLIC_OWNER_ID || ''
export const useActivates = () => {
const [loading, setLoading] = useState<boolean>(false)
const [error, setError] = useState<ApiError | null>(null)
const [data, setData] = useState<ListActivitiesResult>()
const load = async () => {
const load = async (params?: ListActivitiesInput) => {
try {
setLoading(true)
const c = root.get(ActivityController)
const data = await c.list({ page: 1, limit: 10, isActive: true, orderBy: 'sortOrder', order: 'desc', ownerId: OWNER_ID })
const activity = root.get(ActivityController)
const { data, error } = await handleError(
async () =>
await activity.list({
page: 1,
limit: 10,
isActive: true,
orderBy: 'sortOrder',
order: 'desc',
ownerId: OWNER_ID,
...params,
}),
)
if (error) {
setError(error)
return
}
setData(data)
} catch (e) {
setError(e as ApiError)
@@ -24,6 +45,6 @@ export const useActivates = () => {
load,
loading,
error,
data
data,
}
}
}