feat: 选择视频库后自动触发 AI 智能匹配 (#1256 前端部分)
CI/CD Pipeline / Validate - Code Quality (push) Successful in 5m12s
CI/CD Pipeline / Validate - Type Check (mypy) (push) Successful in 1m12s
CI/CD Pipeline / Validate - Migration (alembic) (push) Successful in 51s
CI/CD Pipeline / Unit Tests (push) Successful in 11m26s
CI/CD Pipeline / Integration Tests (push) Successful in 3m51s
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 7m38s
CI/CD Pipeline / Build Staging API Image (push) Successful in 7m46s
CI/CD Pipeline / Build Staging Web Image (push) Successful in 3m3s
CI/CD Pipeline / Build Staging Worker Image (push) Failing after 7m47s
CI/CD Pipeline / Production Browser E2E (push) Failing after 955h30m56s
CI/CD Pipeline / Deploy Production (push) Failing after 955h30m57s
CI/CD Pipeline / CI Gate (push) Failing after 955h30m58s
CI/CD Pipeline / Build Production Web Image (push) Failing after 955h30m58s
CI/CD Pipeline / Build Production API Image (push) Failing after 955h30m58s
CI/CD Pipeline / Staging API Integration Tests (push) Failing after 955h34m37s
CI/CD Pipeline / Staging E2E Tests (push) Failing after 955h34m37s
CI/CD Pipeline / PR Build Worker Image (push) Failing after 955h42m24s
CI/CD Pipeline / PR Build Web Image (push) Failing after 955h42m24s
CI/CD Pipeline / Frontend Lint (push) Failing after 955h42m26s
CI/CD Pipeline / Check if frontend-only change (push) Failing after 955h42m27s
CI/CD Pipeline / Canary Release to Production (push) Failing after 956h4m16s
CI/CD Pipeline / Build Production Worker Image (push) Failing after 956h4m18s
CI/CD Pipeline / ACR Image Cleanup (push) Failing after 956h7m56s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Failing after 956h7m58s
CI/CD Pipeline / PR Build API Image (push) Failing after 956h15m45s

- useStep2Materials 添加 useEffect,auto 模式下选择视频库自动调用 handleSmartMatch
- 触发条件:auto 模式 + 视频库已选 + 素材加载完成 + 素材数>0
- 离开 auto 模式时重置 autoTriggeredRef,确保模式切换后重新触发
- handleSmartMatch 由 useCallback 包装,引用稳定,安全加入依赖项
- 用户不再需要手动点击「让AI帮你选」按钮

Related to #1256
This commit is contained in:
xiaoxia
2026-08-07 19:18:38 +08:00
parent 749a1aae7e
commit ec12db15c7
@@ -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) => {