diff --git a/apps/web/src/pages/viral-video/ViralVideoPage.tsx b/apps/web/src/pages/viral-video/ViralVideoPage.tsx index 5913fa9b5..bd8309789 100644 --- a/apps/web/src/pages/viral-video/ViralVideoPage.tsx +++ b/apps/web/src/pages/viral-video/ViralVideoPage.tsx @@ -1233,40 +1233,58 @@ const ViralVideoPage: React.FC = () => { const [editingField, setEditingField] = useState(null) const editTaRef = useRef(null) - const updateShot = (idx: number, patch: Partial) => { - if (!task.storyboard) return - const shots = task.storyboard.shots.map((s, i) => (i === idx ? { ...s, ...patch } : s)) - setTask({ storyboard: { ...task.storyboard, shots } }) - } - const updateStoryboard = (patch: Partial) => { - if (!task.storyboard) return - setTask({ storyboard: { ...task.storyboard, ...patch } }) - } - const updateOverview = (patch: Partial) => { - if (!task.storyboard) return - setTask({ - storyboard: { ...task.storyboard, overview: { ...task.storyboard.overview, ...patch } }, + const updateShot = useCallback((idx: number, patch: Partial) => { + setTask((t) => { + if (!t.storyboard) return t + const shots = t.storyboard.shots.map((s, i) => (i === idx ? { ...s, ...patch } : s)) + return { ...t, storyboard: { ...t.storyboard, shots } } }) - } - const updateConstraints = ( - list: "hard_constraints" | "negative_prompts", - idx: number, - v: string, - ) => { - if (!task.storyboard) return - const arr = [...task.storyboard[list]] - arr[idx] = v - setTask({ storyboard: { ...task.storyboard, [list]: arr } }) - } - const addConstraint = (list: "hard_constraints" | "negative_prompts") => { - if (!task.storyboard) return - setTask({ storyboard: { ...task.storyboard, [list]: [...task.storyboard[list], ""] } }) - } - const removeConstraint = (list: "hard_constraints" | "negative_prompts", idx: number) => { - if (!task.storyboard) return - const arr = task.storyboard[list].filter((_, i) => i !== idx) - setTask({ storyboard: { ...task.storyboard, [list]: arr } }) - } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []) + const updateStoryboard = useCallback((patch: Partial) => { + setTask((t) => (t.storyboard ? { ...t, storyboard: { ...t.storyboard, ...patch } } : t)) + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []) + const updateOverview = useCallback((patch: Partial) => { + setTask((t) => + t.storyboard + ? { + ...t, + storyboard: { ...t.storyboard, overview: { ...t.storyboard.overview, ...patch } }, + } + : t, + ) + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []) + const updateConstraints = useCallback( + (list: "hard_constraints" | "negative_prompts", idx: number, v: string) => { + setTask((t) => { + if (!t.storyboard) return t + const arr = [...t.storyboard[list]] + arr[idx] = v + return { ...t, storyboard: { ...t.storyboard, [list]: arr } } + }) + }, + [], // eslint-disable-line react-hooks/exhaustive-deps + ) + const addConstraint = useCallback((list: "hard_constraints" | "negative_prompts") => { + setTask((t) => + t.storyboard + ? { ...t, storyboard: { ...t.storyboard, [list]: [...t.storyboard[list], ""] } } + : t, + ) + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []) + const removeConstraint = useCallback( + (list: "hard_constraints" | "negative_prompts", idx: number) => { + setTask((t) => { + if (!t.storyboard) return t + const arr = t.storyboard[list].filter((_, i) => i !== idx) + return { ...t, storyboard: { ...t.storyboard, [list]: arr } } + }) + }, + [], // eslint-disable-line react-hooks/exhaustive-deps + ) /* 内联编辑 helper —— 点击文本 → textarea,blur/Enter 保存 */ const handleInlineCommit = useCallback(() => { @@ -1290,7 +1308,7 @@ const ViralVideoPage: React.FC = () => { } } setEditingField(null) - }, []) + }, [updateShot, updateOverview, updateStoryboard]) const renderCopyResult = () => { if (task.uiStep === "step2_generating") {