diff --git a/@share/components/Video.tsx b/@share/components/Video.tsx index 12d203d..5cf9022 100644 --- a/@share/components/Video.tsx +++ b/@share/components/Video.tsx @@ -11,14 +11,9 @@ type Props = { const VideoBox = ({ url, poster, style, ...videoProps }: Props) => { const [paused, setPaused] = useState(true) - const videoRef = (ref: any) => { - if (ref && !paused) { - ref.seek(0) - } - } useEffect(() => { console.log('url--------', url); - + setPaused(!Boolean(url)) }, [url]) @@ -36,7 +31,6 @@ const VideoBox = ({ url, poster, style, ...videoProps }: Props) => { muted paused={paused} style={style as any} - ref={videoRef} {...videoProps} /> ) diff --git a/hooks/actions/use-template-actions.ts b/hooks/actions/use-template-actions.ts index 4801f6b..1d1c3ec 100644 --- a/hooks/actions/use-template-actions.ts +++ b/hooks/actions/use-template-actions.ts @@ -1,31 +1,14 @@ import { ApiError } from "@/lib/types" import { useState, useCallback } from "react" import { root } from '@repo/core' -import { TemplateController, TemplateGenerationController } from "@repo/sdk" +import { TemplateController, TemplateGenerationController, RunTemplateInput, CreateTemplateGenerationInput } from "@repo/sdk" import { useError } from "../data/use-error" -interface RunTemplateParams { - templateId: string - data: any - identifier?: string - originalUrl?: string -} - -interface CreateGenerationParams { - templateId: string - type: string - resultUrl?: string[] - originalUrl?: string - status?: string - creditsCost?: number - creditsTransactionId?: string -} - export const useTemplateActions = () => { const [loading, setLoading] = useState(false) const [error, setError] = useState(null) - const runTemplate = useCallback(async (params: RunTemplateParams) => { + const runTemplate = useCallback(async (params: RunTemplateInput) => { setLoading(true) setError(null) @@ -42,7 +25,7 @@ export const useTemplateActions = () => { return { generationId: data?.generationId, error: null } }, []) - const createGeneration = useCallback(async (params: CreateGenerationParams) => { + const createGeneration = useCallback(async (params: CreateTemplateGenerationInput) => { setLoading(true) setError(null) diff --git a/hooks/data/use-favorite-templates.ts b/hooks/data/use-favorite-templates.ts index 7353aa7..81863ee 100644 --- a/hooks/data/use-favorite-templates.ts +++ b/hooks/data/use-favorite-templates.ts @@ -1,7 +1,7 @@ import { ApiError } from "@/lib/types" import { useState, useCallback } from "react" import { root } from '@repo/core' -import { TemplateSocialController } from "@repo/sdk" +import { TemplateSocialController, GetUserFavoritesResponse } from "@repo/sdk" import { useError } from "./use-error" interface UseFavoriteTemplatesParams { @@ -9,52 +9,10 @@ interface UseFavoriteTemplatesParams { limit?: number } -interface Template { - id: string - userId: string - ownerId?: string | null - title: string - titleEn: string - description: string - descriptionEn: string - coverImageUrl: string - previewUrl: string - content: any - sortOrder: number - createdAt: Date - updatedAt: Date - aspectRatio: string - status: string - isDeleted: boolean - likeCount?: number - favoriteCount?: number - viewCount?: number - useCount?: number - shareCount?: number - commentCount?: number - costPrice?: number | null - price?: number | null - deletedAt?: Date | null -} - -interface Favorite { - id: string - templateId: string - createdAt: Date - template?: Template -} - -interface UseFavoriteTemplatesResponse { - favorites: Favorite[] - total: number - page: number - limit: number -} - export const useFavoriteTemplates = () => { const [loading, setLoading] = useState(false) const [error, setError] = useState(null) - const [data, setData] = useState() + const [data, setData] = useState() const execute = useCallback(async (params?: UseFavoriteTemplatesParams) => { setLoading(true) diff --git a/hooks/data/use-public-templates.ts b/hooks/data/use-public-templates.ts index 7625819..74b1902 100644 --- a/hooks/data/use-public-templates.ts +++ b/hooks/data/use-public-templates.ts @@ -1,7 +1,7 @@ import { ApiError } from "@/lib/types" import { useState, useCallback } from "react" import { root } from '@repo/core' -import { RecommendedTemplateController } from "@repo/sdk" +import { RecommendedTemplateController, ListPublicRecommendedTemplatesResult } from "@repo/sdk" import { useError } from "./use-error" interface UsePublicTemplatesParams { @@ -10,60 +10,10 @@ interface UsePublicTemplatesParams { sortOrder?: 'asc' | 'desc' } -interface Tag { - id: string - ownerId: string | null - name: string - nameEn: string - description: string - descriptionEn: string - sortOrder: number - createdAt: Date - updatedAt: Date - isDeleted: boolean - deletedAt: Date | null -} - -interface PublicTemplate { - id: string - userId: string - ownerId: string | null - title: string - titleEn: string - description: string - descriptionEn: string - coverImageUrl: string - previewUrl: string - formSchema: any - uploadSapecifications: string | null - uploadSapecificationsEn: string | null - sortOrder: number - viewCount: number - useCount: number - likeCount: number - favoriteCount: number - shareCount: number - commentCount: number - costPrice: number | null - price: number | null - keywords: string | null - createdAt: Date - updatedAt: Date - aspectRatio: string - status: string - isDeleted: boolean - deletedAt: Date | null - tags?: Tag[] -} - -interface UsePublicTemplatesResponse { - templates: PublicTemplate[] -} - export const usePublicTemplates = () => { const [loading, setLoading] = useState(false) const [error, setError] = useState(null) - const [data, setData] = useState() + const [data, setData] = useState() const execute = useCallback(async (params?: UsePublicTemplatesParams) => { setLoading(true) diff --git a/hooks/data/use-template-detail.ts b/hooks/data/use-template-detail.ts index 49711d9..cc38ccb 100644 --- a/hooks/data/use-template-detail.ts +++ b/hooks/data/use-template-detail.ts @@ -1,40 +1,13 @@ import { ApiError } from "@/lib/types" import { useState, useCallback } from "react" import { root } from '@repo/core' -import { TemplateController } from "@repo/sdk" +import { TemplateController, TemplateDetail } from "@repo/sdk" import { useError } from "./use-error" interface UseTemplateDetailParams { id: string } -interface TemplateDetail { - category: any - tags: any[] - userId: string - title: string - titleEn: string - description: string - descriptionEn: string - coverImageUrl: string - previewUrl: string - content: any - sortOrder: number - createdAt: Date - updatedAt: Date - aspectRatio: string - status: string - isDeleted: boolean - id: string - ownerId?: string | null - formSchema?: any - uploadSapecifications?: string | null - uploadSapecificationsEn?: string | null - costPrice?: number | null - price?: number | null - deletedAt?: Date | null -} - export const useTemplateDetail = () => { const [loading, setLoading] = useState(false) const [error, setError] = useState(null) diff --git a/lib/fetch-logger.ts b/lib/fetch-logger.ts index d5ea50f..95a5710 100644 --- a/lib/fetch-logger.ts +++ b/lib/fetch-logger.ts @@ -1,4 +1,5 @@ import { router } from 'expo-router' +import * as SecureStore from 'expo-secure-store' interface FetchLoggerOptions { enableLogging?: boolean; @@ -25,6 +26,18 @@ export const createFetchWithLogger = (options: FetchLoggerOptions = {}) => { const method = init?.method || 'GET'; try { + const token = await SecureStore.getItemAsync('token'); + + if (token) { + init = { + ...init, + headers: { + ...init?.headers, + 'authorization': `Bearer ${token}`, + }, + }; + } + const response = await originalFetch(input, init); if (response.status === 401) {