fix: 修复所有 TypeScript 类型错误

- 修复 useTemplates hook 中缺失的必需参数 (page, limit)
- 修复 searchResults 中 execute 和 refetch 的参数类型
- 修复 aspectRatio 类型从 string 转换为 number
- 修复 loadTags 中缺失的必需参数
- 移除 useTags 中不存在的 isActive 属性
- 修复 useTemplateActions 返回值类型

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
imeepos
2026-01-16 14:14:05 +08:00
parent 4270973652
commit fce99a57bf
7 changed files with 300 additions and 196 deletions

View File

@@ -1,8 +1,9 @@
import { useState } from 'react'
import { useState, useEffect } from 'react'
import {
View,
StyleSheet,
StatusBar as RNStatusBar,
RefreshControl,
} from 'react-native'
import { StatusBar } from 'expo-status-bar'
import { SafeAreaView } from 'react-native-safe-area-context'
@@ -10,44 +11,52 @@ import { useRouter, useLocalSearchParams } from 'expo-router'
import SearchResultsGrid from '@/components/SearchResultsGrid'
import SearchBar from '@/components/SearchBar'
import type { TemplateGeneration } from '@/hooks'
const createMockResult = (id: string, height: number): TemplateGeneration & { height: number; title: string; image: any } => ({
id,
userId: 'test',
templateId: `template-${id}`,
type: 'VIDEO',
resultUrl: [],
status: 'completed',
createdAt: new Date(),
updatedAt: new Date(),
title: '猫咪圣诞写真',
image: require('@/assets/images/android-icon-background.png'),
height,
template: {
id: `template-${id}`,
title: '猫咪圣诞写真',
titleEn: 'Cat Christmas',
coverImageUrl: '',
},
})
const searchResults = [
createMockResult('1', 236),
createMockResult('2', 131),
createMockResult('3', 236),
createMockResult('4', 236),
createMockResult('5', 95),
createMockResult('6', 236),
createMockResult('7', 228),
createMockResult('8', 95),
createMockResult('9', 228),
]
import { useTemplates, useSearchHistory } from '@/hooks'
export default function SearchResultsScreen() {
const router = useRouter()
const params = useLocalSearchParams()
const [searchText, setSearchText] = useState((params.q as string) || '')
const [refreshing, setRefreshing] = useState(false)
// 使用 useTemplates hook 进行搜索
const { templates, loading, error, execute, refetch } = useTemplates()
// 使用搜索历史 hook
const { addToHistory } = useSearchHistory()
// 当搜索关键词变化时,执行搜索
useEffect(() => {
if (params.q && typeof params.q === 'string') {
const query = params.q.trim()
setSearchText(query)
if (query) {
// 执行搜索
execute({ search: query, limit: 50, sortBy: 'createdAt', sortOrder: 'desc', page: 1 })
// 添加到搜索历史
addToHistory(query)
}
}
}, [params.q, execute, addToHistory])
// 处理下拉刷新
const handleRefresh = async () => {
setRefreshing(true)
if (searchText) {
await refetch()
}
setRefreshing(false)
}
// 将模板数据转换为搜索结果格式
const searchResults = templates.map(template => ({
id: template.id,
title: template.title || template.titleEn || '',
image: { uri: template.previewUrl || template.coverImageUrl || '' },
previewUrl: template.previewUrl,
coverImageUrl: template.coverImageUrl,
aspectRatio: template.aspectRatio ? parseFloat(template.aspectRatio as string) : undefined,
}))
return (
<SafeAreaView style={styles.container} edges={['top']}>
@@ -57,7 +66,12 @@ export default function SearchResultsScreen() {
<SearchBar
searchText={searchText}
onSearchTextChange={setSearchText}
onSearch={(text) => {}}
onSearch={(text) => {
router.push({
pathname: '/searchTemplate',
params: { q: text, focus: 'true' },
})
}}
onBack={() => router.back()}
readOnly={true}
onInputPress={() => {
@@ -75,7 +89,10 @@ export default function SearchResultsScreen() {
marginBottom={12}
/>
<SearchResultsGrid results={searchResults} />
<SearchResultsGrid
results={searchResults}
loading={loading}
/>
</SafeAreaView>
)
}