Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/components/TrimControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import { EditRecipe } from "@/lib/types";

const MIN_CLIP_DURATION = 0.1;

interface Props {
recipe: EditRecipe;
onChange: (patch: Partial<EditRecipe>) => void;
Expand All @@ -13,14 +15,14 @@ export default function TrimControl({ recipe, onChange, duration }: Props) {
const n = parseFloat(val);
if (isNaN(n) || n < 0) return;
if (duration > 0 && n >= duration) return;
if (recipe.trimEnd !== null && n >= recipe.trimEnd) return;
if (recipe.trimEnd !== null && n >= recipe.trimEnd - MIN_CLIP_DURATION) return;
onChange({ trimStart: n });
};

const handleEnd = (val: string) => {
if (val === "") { onChange({ trimEnd: null }); return; }
const n = parseFloat(val);
if (isNaN(n) || n <= 0 || n <= recipe.trimStart) return;
if (isNaN(n) || n <= 0 || n <= recipe.trimStart + MIN_CLIP_DURATION) return;
if (duration > 0 && n > duration) return;
onChange({ trimEnd: n });
};
Expand Down Expand Up @@ -67,6 +69,12 @@ export default function TrimControl({ recipe, onChange, duration }: Props) {
Duration: {duration.toFixed(1)}s
</p>
)}
{recipe.trimEnd !== null &&
recipe.trimEnd - recipe.trimStart < MIN_CLIP_DURATION && (
<p className="text-[10px] text-red-500 font-heading">
Clip must be at least 0.1 seconds long.
</p>
)}
</div>
);
}