From fa8cc1705f2273037b795ab2d46fa68fb24dadea Mon Sep 17 00:00:00 2001 From: imeepos Date: Thu, 25 Dec 2025 18:32:56 +0800 Subject: [PATCH] fix: bug --- app/(tabs)/generate.tsx | 2 +- app/(tabs)/index.tsx | 5 +++-- app/(tabs)/message.tsx | 2 +- app/generateVideo.tsx | 2 +- app/generationRecord.tsx | 2 +- hooks/actions/use-template-interaction.ts | 4 ++-- hooks/data/use-categories.ts | 9 ++++++++- hooks/data/use-favorite-templates.ts | 8 +++----- hooks/data/use-public-templates.ts | 9 +++++++-- hooks/data/use-recommended-templates.ts | 4 +++- hooks/data/use-tags.ts | 9 ++++++++- hooks/data/use-template-detail.ts | 2 +- hooks/data/use-template-generation-detail.ts | 2 +- hooks/data/use-template-generations.ts | 6 +++++- hooks/data/use-templates.ts | 9 ++++++++- storage.native.ts | 15 +++++++++++++++ storage.ts | 16 ++++++++++++++++ tsconfig.json | 3 ++- 18 files changed, 86 insertions(+), 23 deletions(-) create mode 100644 storage.native.ts create mode 100644 storage.ts diff --git a/app/(tabs)/generate.tsx b/app/(tabs)/generate.tsx index eda16b8..d108548 100644 --- a/app/(tabs)/generate.tsx +++ b/app/(tabs)/generate.tsx @@ -354,7 +354,7 @@ export default function Index() { }, [selectedCategoryId]) const displayTemplates = useMemo(() => { - const recommended = recommendedTemplates.data?.recommendedTemplates || [] + const recommended = recommendedTemplates.data?.templates || [] const regular = templates.data?.templates || [] const all = selectedCategoryId diff --git a/app/(tabs)/index.tsx b/app/(tabs)/index.tsx index 7f4775d..8d673a3 100644 --- a/app/(tabs)/index.tsx +++ b/app/(tabs)/index.tsx @@ -15,6 +15,7 @@ import { useUserBalance } from '@/hooks/core/use-user-balance' import { useTemplates } from '@/hooks/data/use-templates' import { usePublicTemplates } from '@/hooks/data/use-public-templates' import { useFavoriteTemplates } from '@/hooks/data/use-favorite-templates' +import type { GetUserFavoritesResponse } from '@repo/sdk' import { useAigcTask } from '@/hooks/actions/use-aigc-task' import { useTemplateInteraction } from '@/hooks/actions/use-template-interaction' @@ -369,7 +370,7 @@ export default function Sync() { setHasMore(false) return } - newItems = data.favorites.filter((fav) => fav.template && !fav.template.isDeleted).map((fav) => transformTemplateToMediaItem(fav.template!)) + newItems = data.favorites.filter((fav: GetUserFavoritesResponse['favorites'][number]) => fav.template && !fav.template.isDeleted).map((fav: GetUserFavoritesResponse['favorites'][number]) => transformTemplateToMediaItem(fav.template!)) } else if (activeTab === 'new') { if (isAuthenticated) { const { data, error } = await loadTemplates({ limit, page: 1, sortBy: 'createdAt', sortOrder: 'desc' }) @@ -450,7 +451,7 @@ export default function Sync() { setHasMore(false) return } - newItems = data.favorites.filter((fav) => fav.template && !fav.template.isDeleted).map((fav) => transformTemplateToMediaItem(fav.template!)) + newItems = data.favorites.filter((fav: GetUserFavoritesResponse['favorites'][number]) => fav.template && !fav.template.isDeleted).map((fav: GetUserFavoritesResponse['favorites'][number]) => transformTemplateToMediaItem(fav.template!)) } else if (activeTab === 'new') { if (!isAuthenticated) { setHasMore(false) diff --git a/app/(tabs)/message.tsx b/app/(tabs)/message.tsx index 709ac3d..7683951 100644 --- a/app/(tabs)/message.tsx +++ b/app/(tabs)/message.tsx @@ -19,7 +19,7 @@ export default function MessageScreen() { const { load, loading, error, data } = useActivities() useEffect(() => { - load({ isActive: true }) + load({ page: 1, limit: 20, orderBy: 'createdAt', order: 'desc' }) }, []) const activities = data?.activities || [] diff --git a/app/generateVideo.tsx b/app/generateVideo.tsx index 8e74c4f..e11e0cf 100644 --- a/app/generateVideo.tsx +++ b/app/generateVideo.tsx @@ -147,7 +147,7 @@ export default function GenerateVideoScreen() { const { generation, error: createError } = await createGeneration({ templateId: String(templateData.id), - type: 'video', + type: 'VIDEO', resultUrl: videoUrls, originalUrl: uploadedImageUrl, status: 'completed', diff --git a/app/generationRecord.tsx b/app/generationRecord.tsx index 361d4c4..2bd2e8e 100644 --- a/app/generationRecord.tsx +++ b/app/generationRecord.tsx @@ -98,7 +98,7 @@ export default function GenerationRecordScreen() { const { generation: newGeneration, error: createError } = await createGeneration({ templateId: generation.templateId, - type: 'video', + type: 'VIDEO', resultUrl: videoUrls, originalUrl: generation.originalUrl || '', status: 'completed', diff --git a/hooks/actions/use-template-interaction.ts b/hooks/actions/use-template-interaction.ts index 077a1d6..a0e36b9 100644 --- a/hooks/actions/use-template-interaction.ts +++ b/hooks/actions/use-template-interaction.ts @@ -44,7 +44,7 @@ export const useTemplateInteraction = () => { const checkLiked = useCallback(async (templateId: string) => { const templateSocial = root.get(TemplateSocialController) - const { data, error } = await useError(async () => await templateSocial.checkLiked({ query: { templateId } })) + const { data, error } = await useError(async () => await templateSocial.checkLiked({ templateId })) if (error) { return { liked: false, error } @@ -89,7 +89,7 @@ export const useTemplateInteraction = () => { const checkFavorited = useCallback(async (templateId: string) => { const templateSocial = root.get(TemplateSocialController) - const { data, error } = await useError(async () => await templateSocial.checkFavorited({ query: { templateId } })) + const { data, error } = await useError(async () => await templateSocial.checkFavorited({ templateId })) if (error) { return { favorited: false, error } diff --git a/hooks/data/use-categories.ts b/hooks/data/use-categories.ts index 1744013..7acef9b 100644 --- a/hooks/data/use-categories.ts +++ b/hooks/data/use-categories.ts @@ -22,7 +22,14 @@ export const useCategories = () => { try { setLoading(true) const category = root.get(CategoryController) - const { data, error } = await useError(async () => await category.list({ ...params, ownerId: OWNER_ID })) + const { data, error } = await useError(async () => await category.list({ + page: params?.page || 1, + limit: params?.limit || 20, + orderBy: 'createdAt', + order: 'desc', + ...params, + ownerId: OWNER_ID + })) if (error) { setError(error) diff --git a/hooks/data/use-favorite-templates.ts b/hooks/data/use-favorite-templates.ts index 81863ee..0f531cc 100644 --- a/hooks/data/use-favorite-templates.ts +++ b/hooks/data/use-favorite-templates.ts @@ -19,11 +19,9 @@ export const useFavoriteTemplates = () => { setError(null) const templateSocial = root.get(TemplateSocialController) - const { data, error } = await useError(async () => await templateSocial.favorites({ - query: { - page: params?.page?.toString() || '1', - limit: params?.limit?.toString() || '20' - } + const { data, error } = await useError(async () => await templateSocial.getUserFavorites({ + page: params?.page || 1, + limit: params?.limit || 20 })) if (error) { diff --git a/hooks/data/use-public-templates.ts b/hooks/data/use-public-templates.ts index 74b1902..3bc00e5 100644 --- a/hooks/data/use-public-templates.ts +++ b/hooks/data/use-public-templates.ts @@ -1,9 +1,12 @@ import { ApiError } from "@/lib/types" import { useState, useCallback } from "react" import { root } from '@repo/core' -import { RecommendedTemplateController, ListPublicRecommendedTemplatesResult } from "@repo/sdk" +import { RecommendedTemplateController } from "@repo/sdk" import { useError } from "./use-error" +type ApiListResult = Awaited> +type ListPublicRecommendedTemplatesResult = NonNullable + interface UsePublicTemplatesParams { limit?: number sortBy?: 'sortOrder' | 'likeCount' | 'viewCount' | 'createdAt' | 'updatedAt' @@ -21,7 +24,9 @@ export const usePublicTemplates = () => { const recommendedTemplate = root.get(RecommendedTemplateController) const { data, error } = await useError(async () => await recommendedTemplate.listPublic({ - limit: params?.limit || 20 + limit: params?.limit || 20, + sortBy: params?.sortBy || 'sortOrder', + sortOrder: params?.sortOrder || 'desc' })) if (error) { diff --git a/hooks/data/use-recommended-templates.ts b/hooks/data/use-recommended-templates.ts index f9e1e8f..6ff9af8 100644 --- a/hooks/data/use-recommended-templates.ts +++ b/hooks/data/use-recommended-templates.ts @@ -25,7 +25,9 @@ export const useRecommendedTemplates = () => { const recommendedTemplate = root.get(RecommendedTemplateController) const { data, error } = await useError(async () => await recommendedTemplate.listPublic({ - limit: params?.limit || 20 + limit: params?.limit || 20, + sortBy: 'sortOrder', + sortOrder: 'desc' })) if (error) { diff --git a/hooks/data/use-tags.ts b/hooks/data/use-tags.ts index 08dfbee..96f55e5 100644 --- a/hooks/data/use-tags.ts +++ b/hooks/data/use-tags.ts @@ -19,7 +19,14 @@ export const useTags = () => { try { setLoading(true) const tag = root.get(TagController) - const { data, error } = await useError(async () => await tag.list({ ...params, ownerId: OWNER_ID })) + const { data, error } = await useError(async () => await tag.list({ + page: params?.page || 1, + limit: params?.limit || 20, + orderBy: 'createdAt', + order: 'desc', + ...params, + ownerId: OWNER_ID + })) if (error) { setError(error) diff --git a/hooks/data/use-template-detail.ts b/hooks/data/use-template-detail.ts index cc38ccb..06d76b1 100644 --- a/hooks/data/use-template-detail.ts +++ b/hooks/data/use-template-detail.ts @@ -18,7 +18,7 @@ export const useTemplateDetail = () => { setError(null) const template = root.get(TemplateController) - const { data, error } = await useError(async () => await template.get({ query: params })) + const { data, error } = await useError(async () => await template.get(params.id)) if (error) { setError(error) diff --git a/hooks/data/use-template-generation-detail.ts b/hooks/data/use-template-generation-detail.ts index f95bbc0..c2246d0 100644 --- a/hooks/data/use-template-generation-detail.ts +++ b/hooks/data/use-template-generation-detail.ts @@ -19,7 +19,7 @@ export const useTemplateGenerationDetail = () => { setError(null) const templateGeneration = root.get(TemplateGenerationController) - const { data, error } = await useError(async () => await templateGeneration.get({ query: params })) + const { data, error } = await useError(async () => await templateGeneration.get(params.id)) if (error) { setError(error) diff --git a/hooks/data/use-template-generations.ts b/hooks/data/use-template-generations.ts index c656381..1055e86 100644 --- a/hooks/data/use-template-generations.ts +++ b/hooks/data/use-template-generations.ts @@ -27,7 +27,11 @@ export const useTemplateGenerations = () => { setError(null) const templateGeneration = root.get(TemplateGenerationController) - const { data, error } = await useError(async () => await templateGeneration.list(params || {})) + const { data, error } = await useError(async () => await templateGeneration.list({ + page: params?.page || 1, + limit: params?.limit || 20, + ...params + })) if (error) { setError(error) diff --git a/hooks/data/use-templates.ts b/hooks/data/use-templates.ts index de5c520..2c5ba22 100644 --- a/hooks/data/use-templates.ts +++ b/hooks/data/use-templates.ts @@ -25,7 +25,14 @@ export const useTemplates = () => { setError(null) const template = root.get(TemplateController) - const { data, error } = await useError(async () => await template.list({ ...params, ownerId: OWNER_ID })) + const { data, error } = await useError(async () => await template.list({ + page: params?.page || 1, + limit: params?.limit || 20, + sortBy: params?.sortBy || 'createdAt', + sortOrder: params?.sortOrder || 'desc', + ...params, + ownerId: OWNER_ID + })) if (error) { setError(error) setLoading(false) diff --git a/storage.native.ts b/storage.native.ts new file mode 100644 index 0000000..3f1fa28 --- /dev/null +++ b/storage.native.ts @@ -0,0 +1,15 @@ +import * as SecureStore from "expo-secure-store"; + +export const storage = { + async getItem(key: string): Promise { + return await SecureStore.getItemAsync(key); + }, + + async setItem(key: string, value: string): Promise { + await SecureStore.setItemAsync(key, value); + }, + + async removeItem(key: string): Promise { + await SecureStore.deleteItemAsync(key); + }, +}; diff --git a/storage.ts b/storage.ts new file mode 100644 index 0000000..a06f838 --- /dev/null +++ b/storage.ts @@ -0,0 +1,16 @@ +export const storage = { + async getItem(key: string): Promise { + if (typeof window === "undefined") return null; + return window.localStorage.getItem(key); + }, + + async setItem(key: string, value: string): Promise { + if (typeof window === "undefined") return; + window.localStorage.setItem(key, value); + }, + + async removeItem(key: string): Promise { + if (typeof window === "undefined") return; + window.localStorage.removeItem(key); + }, +}; diff --git a/tsconfig.json b/tsconfig.json index 0a27afa..656c45d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,10 +4,11 @@ "strict": true, "jsx": "react-native", "baseUrl": ".", + "lib": ["ES2020", "DOM"], "paths": { "@/*": ["./*"] } }, "include": ["**/*.ts", "**/*.tsx", ".expo/types/**/*.ts", "expo-env.d.ts", "nativewind-env.d.ts"], - "exclude": ["scripts/**/*"] + "exclude": ["scripts/**/*", "storage.ts"] }