11b3f83368
CI/CD Pipeline / Check if frontend-only change (push) Waiting to run
CI/CD Pipeline / Validate - Code Quality (push) Waiting to run
CI/CD Pipeline / Validate - Type Check (mypy) (push) Waiting to run
CI/CD Pipeline / Validate - Migration (alembic) (push) Waiting to run
CI/CD Pipeline / Unit Tests (push) Blocked by required conditions
CI/CD Pipeline / Integration Tests (push) Blocked by required conditions
CI/CD Pipeline / Frontend Lint (push) Waiting to run
CI/CD Pipeline / Frontend Unit Tests (push) Blocked by required conditions
CI/CD Pipeline / PR Build API Image (push) Waiting to run
CI/CD Pipeline / PR Build Web Image (push) Waiting to run
CI/CD Pipeline / PR Build Worker Image (push) Waiting to run
CI/CD Pipeline / Build Staging API Image (push) Waiting to run
CI/CD Pipeline / Build Staging Web Image (push) Waiting to run
CI/CD Pipeline / Build Staging Worker Image (push) Waiting to run
CI/CD Pipeline / Build Production API Image (push) Waiting to run
CI/CD Pipeline / Build Production Web Image (push) Waiting to run
CI/CD Pipeline / Build Production Worker Image (push) Waiting to run
CI/CD Pipeline / Deploy Production (push) Blocked by required conditions
CI/CD Pipeline / Production Browser E2E (push) Blocked by required conditions
CI/CD Pipeline / CI Gate (push) Blocked by required conditions
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Has been cancelled
CI/CD Pipeline / Staging E2E Tests (push) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (push) Has been cancelled
CI/CD Pipeline / ACR Image Cleanup (push) Has been cancelled
CI/CD Pipeline / Canary Release to Production (push) Has been cancelled
42 lines
1.1 KiB
TypeScript
Executable File
42 lines
1.1 KiB
TypeScript
Executable File
import { useState, useEffect } from "react"
|
|
import { useQuery } from "@tanstack/react-query"
|
|
import { getAssets, getAssetLibraries } from "@/api/assets"
|
|
import type { AssetItem } from "@/api/assets"
|
|
|
|
/**
|
|
* 素材库加载 Hook
|
|
* 管理素材库列表、当前选中库、素材列表加载
|
|
*/
|
|
export function useMaterialLibrary() {
|
|
/* ── 素材库数据 API ── */
|
|
const { data: libraries = [] } = useQuery({
|
|
queryKey: ["asset-libraries"],
|
|
queryFn: getAssetLibraries,
|
|
})
|
|
const [selectedLibraryId, setSelectedLibraryId] = useState<string>("")
|
|
|
|
// 自动选中第一个视频库
|
|
useEffect(() => {
|
|
if (libraries.length > 0 && !selectedLibraryId) {
|
|
setSelectedLibraryId(libraries[0].id)
|
|
}
|
|
}, [libraries, selectedLibraryId])
|
|
|
|
const { data: materials = { items: [], total: 0 }, isLoading: materialsLoading } = useQuery<{
|
|
items: AssetItem[]
|
|
total: number
|
|
}>({
|
|
queryKey: ["generate-assets", selectedLibraryId],
|
|
queryFn: () => getAssets(selectedLibraryId),
|
|
enabled: !!selectedLibraryId,
|
|
})
|
|
|
|
return {
|
|
libraries,
|
|
selectedLibraryId,
|
|
setSelectedLibraryId,
|
|
materials,
|
|
materialsLoading,
|
|
}
|
|
}
|