diff --git a/src/components/TrimControl.tsx b/src/components/TrimControl.tsx index efe6bf47..95d0baa6 100644 --- a/src/components/TrimControl.tsx +++ b/src/components/TrimControl.tsx @@ -82,8 +82,6 @@ export default function TrimControl({ recipe, onChange, duration, file }: Props) const n = parseFloat(val); - onChange({ trimEnd: n }); - if (isNaN(n)) { setEnd(true); setEndErrorMsg("Enter a valid number."); @@ -112,6 +110,7 @@ export default function TrimControl({ recipe, onChange, duration, file }: Props) setEnd(false); setEndErrorMsg(""); + onChange({ trimEnd: n }); }; const inputClass = diff --git a/src/hooks/useVideoEditor.ts b/src/hooks/useVideoEditor.ts index d894ed07..13a16e86 100644 --- a/src/hooks/useVideoEditor.ts +++ b/src/hooks/useVideoEditor.ts @@ -70,11 +70,13 @@ function validateRecipe(recipe: EditRecipe, duration: number ): string | null { "Trim start time cannot be less than 0 seconds.", ], [ - recipe.trimEnd !== null && recipe.trimEnd > duration, + recipe.trimEnd !== null && duration > 0 && recipe.trimEnd > duration, `Trim end time cannot exceed the video duration (${Math.floor(duration)}s).`, ], [ - recipe.trimStart >= (recipe.trimEnd ?? duration), + recipe.trimEnd !== null + ? recipe.trimStart >= recipe.trimEnd + : (duration > 0 && recipe.trimStart >= duration), "Trim start time must be earlier than the end time.", ], [