This commit is contained in:
imeepos 2025-12-25 18:18:21 +08:00
parent 0a2ca9ad91
commit deaa68f048
6 changed files with 22 additions and 151 deletions

View File

@ -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}
/>
)

View File

@ -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<ApiError | null>(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)

View File

@ -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<ApiError | null>(null)
const [data, setData] = useState<UseFavoriteTemplatesResponse | undefined>()
const [data, setData] = useState<GetUserFavoritesResponse | undefined>()
const execute = useCallback(async (params?: UseFavoriteTemplatesParams) => {
setLoading(true)

View File

@ -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<ApiError | null>(null)
const [data, setData] = useState<UsePublicTemplatesResponse | undefined>()
const [data, setData] = useState<ListPublicRecommendedTemplatesResult | undefined>()
const execute = useCallback(async (params?: UsePublicTemplatesParams) => {
setLoading(true)

View File

@ -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<ApiError | null>(null)

View File

@ -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) {