fix: update @repo/sdk to version 1.0.14 and adjust build scripts for production

feat: modify TemplateCard and TemplateGrid to handle optional id and filter templates
refactor: clean up use-template-filter to use CategoryTemplate type
This commit is contained in:
imeepos
2026-01-26 16:40:32 +08:00
parent 01865d94c2
commit a529dc03e1
7 changed files with 25 additions and 30 deletions

View File

@@ -4,7 +4,7 @@ import { Image } from 'expo-image'
import { LinearGradient } from 'expo-linear-gradient'
export interface TemplateCardProps {
id: string
id?: string
title: string
previewUrl?: string
webpPreviewUrl?: string
@@ -55,6 +55,11 @@ const TemplateCardComponent: React.FC<TemplateCardProps> = ({
const aspectRatio = parseAspectRatio(aspectRatioString)
const imageUri = getImageUri(webpPreviewUrl, previewUrl, coverImageUrl)
// 如果没有 id则不渲染卡片
if (!id) {
return null
}
return (
<Pressable
style={[styles.card, { width: cardWidth }]}

View File

@@ -1,18 +1,12 @@
import React, { useState, memo } from 'react'
import { View, StyleSheet, LayoutChangeEvent } from 'react-native'
import type { CategoryTemplate } from '@repo/sdk'
import { TemplateCard } from './TemplateCard'
export interface Template {
id: string
title: string
previewUrl?: string
webpPreviewUrl?: string
coverImageUrl?: string
aspectRatio?: string
}
export type Template = CategoryTemplate
export interface TemplateGridProps {
templates: Template[]
templates: CategoryTemplate[]
onTemplatePress: (id: string) => void
numColumns?: number
horizontalPadding?: number
@@ -45,8 +39,13 @@ const TemplateGridComponent: React.FC<TemplateGridProps> = ({
}) => {
const [gridWidth, setGridWidth] = useState(0)
// 过滤掉没有 id 的模板
const validTemplates = templates.filter((template): template is CategoryTemplate & { id: string } =>
!!template.id
)
// 空数据时返回 null
if (!templates || templates.length === 0) {
if (!validTemplates || validTemplates.length === 0) {
return null
}
@@ -62,7 +61,7 @@ const TemplateGridComponent: React.FC<TemplateGridProps> = ({
onLayout={handleLayout}
>
<View style={[styles.grid, { gap: cardGap }]}>
{templates.map((template) => (
{validTemplates.map((template) => (
<TemplateCard
key={template.id}
id={template.id}