@@ -1,49 +0,0 @@
|
||||
import { useState } from "react"
|
||||
import { useQuery } from "@tanstack/react-query"
|
||||
import type { EditPlanClip } from "@/api/template-editor"
|
||||
import { getEditPlanClips } from "@/api/template-editor"
|
||||
|
||||
const QUERY_KEY = "editPlanClips"
|
||||
|
||||
interface UseEditPlanClipListResult {
|
||||
clips: EditPlanClip[]
|
||||
clipsTotal: number
|
||||
clipsLoading: boolean
|
||||
refetchClips: () => void
|
||||
selectedClipId: string | null
|
||||
setSelectedClipId: (id: string | null) => void
|
||||
selectedClip: EditPlanClip | null
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑计划片段列表 Hook
|
||||
* 封装片段列表查询、选中状态
|
||||
*/
|
||||
export function useEditPlanClipList(planId: string | undefined): UseEditPlanClipListResult {
|
||||
const {
|
||||
data: clipListData,
|
||||
isLoading: clipsLoading,
|
||||
refetch: refetchClips,
|
||||
} = useQuery({
|
||||
queryKey: [QUERY_KEY, planId],
|
||||
queryFn: () => getEditPlanClips(planId!, { limit: 500 }),
|
||||
enabled: !!planId,
|
||||
staleTime: 30_000,
|
||||
})
|
||||
|
||||
const clips: EditPlanClip[] = clipListData?.items ?? []
|
||||
const clipsTotal = clipListData?.total ?? 0
|
||||
|
||||
const [selectedClipId, setSelectedClipId] = useState<string | null>(null)
|
||||
const selectedClip = clips.find((c) => c.id === selectedClipId) ?? null
|
||||
|
||||
return {
|
||||
clips,
|
||||
clipsTotal,
|
||||
clipsLoading,
|
||||
refetchClips,
|
||||
selectedClipId,
|
||||
setSelectedClipId,
|
||||
selectedClip,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user