feat: 选择视频库后自动触发 AI 智能匹配 (#1256 前端部分) #1269

Closed
xiaoxia wants to merge 3 commits from feat/issue-1256-auto-smart-match into develop
@@ -2,7 +2,7 @@
* Step 2 素材选择 Hook
* 组合素材库加载 + 智能匹配两个子 Hook
*/
import { useCallback } from "react"
import { useCallback, useEffect, useRef } from "react"
import { formatDuration } from "../utils/formatDuration"
import { useMaterialLibrary } from "./step2-materials/useMaterialLibrary"
import { useSmartMatch } from "./step2-materials/useSmartMatch"
@@ -34,6 +34,25 @@ export function useStep2Materials({
onSmartSelectedIdsChange,
})
/* ── 自动触发智能匹配:选择视频库后自动调用 ── */
const autoTriggeredRef = useRef<string>("")
const { handleSmartMatch } = smartMatch
useEffect(() => {
// 离开 auto 模式时重置,确保下次进入 auto 模式能重新触发
if (materialMode !== "auto") {
autoTriggeredRef.current = ""
return
}
if (!selectedLibraryId) return
if (materialsLoading) return
if (materials.items.length === 0) return
// 防止同一视频库重复触发
if (autoTriggeredRef.current === selectedLibraryId) return
autoTriggeredRef.current = selectedLibraryId
handleSmartMatch()
}, [selectedLibraryId, materialMode, materialsLoading, materials.items, handleSmartMatch])
/* ── 手动选择素材 ── */
const handleToggleMaterial = useCallback(
(materialId: string) => {