diff --git a/src/components/TrimControl.tsx b/src/components/TrimControl.tsx index efe6bf47..6097139b 100644 --- a/src/components/TrimControl.tsx +++ b/src/components/TrimControl.tsx @@ -20,6 +20,7 @@ export default function TrimControl({ recipe, onChange, duration, file }: Props) const [startErrorMsg, setStartErrorMsg] = useState(""); const [endErrorMsg, setEndErrorMsg] = useState(""); const [startInput, setStartInput] = useState(recipe.trimStart.toString()); + const [endInput, setEndInput] = useState(recipe.trimEnd !== null ? recipe.trimEnd.toString() : ""); const { waveform, isLoading: waveformLoading } = useAudioWaveform(file); const hasAudio = waveform.length > 0; @@ -28,6 +29,10 @@ export default function TrimControl({ recipe, onChange, duration, file }: Props) setStartInput(recipe.trimStart.toString()); }, [recipe.trimStart]); + useEffect(() => { + setEndInput(recipe.trimEnd !== null ? recipe.trimEnd.toString() : ""); + }, [recipe.trimEnd]); + const clipLength = (recipe.trimEnd ?? duration) - recipe.trimStart; const handleStart = (val: string) => { @@ -74,9 +79,12 @@ export default function TrimControl({ recipe, onChange, duration, file }: Props) }; const handleEnd = (val: string) => { + setEndInput(val); + if (val === "") { onChange({ trimEnd: null }); setEnd(false); + setEndErrorMsg(""); return; } @@ -181,7 +189,7 @@ export default function TrimControl({ recipe, onChange, duration, file }: Props) min={0} max={duration > 0 ? duration : undefined} step={0.1} - value={recipe.trimEnd ?? ""} + value={endInput} spellCheck={false} onChange={(e) => handleEnd(e.target.value)} aria-label="Trim end time in seconds"