diff --git a/src/components/AudioSpeedControl.tsx b/src/components/AudioSpeedControl.tsx index a6c82102..15c53eff 100644 --- a/src/components/AudioSpeedControl.tsx +++ b/src/components/AudioSpeedControl.tsx @@ -1,9 +1,8 @@ "use client"; -import { EditRecipe } from "@/lib/types" -import { SPEED_STEPS } from "@/lib/constants"; -import { Volume2, VolumeX, Gauge, AlertTriangle } from "lucide-react"; -import { cn } from "@/lib/utils"; +import { useState, useEffect } from "react"; +import { EditRecipe, SPEED_STEPS } from "@/lib/types"; +import { Volume2, VolumeX, Gauge, RotateCcw } from "lucide-react"; interface Props { recipe: EditRecipe; @@ -11,148 +10,92 @@ interface Props { } export default function AudioSpeedControl({ recipe, onChange }: Props) { - const speedIndex = SPEED_STEPS.indexOf(recipe.speed as (typeof SPEED_STEPS)[number]); - - const getSpeedDescription = (speed: number) => { - if (speed <= 0.5) return "Very Slow"; - if (speed < 1) return "Slow"; - if (speed === 1) return "Normal"; - if (speed <= 1.5) return "Fast"; - return "Very Fast"; - }; + const parentSpeedIndex = SPEED_STEPS.indexOf(recipe.speed as (typeof SPEED_STEPS)[number]); + const safeParentIndex = parentSpeedIndex === -1 ? 3 : parentSpeedIndex; - const isModified = recipe.speed !== 1 || !recipe.keepAudio; + const [localSpeedIndex, setLocalSpeedIndex] = useState(safeParentIndex); + + useEffect(() => { + setLocalSpeedIndex(safeParentIndex); + }, [safeParentIndex]); + + const isSpeedChanged = recipe.speed !== 1; return (
- {isModified && ( -
- -
- )} -
-
onChange({ speed: SPEED_STEPS[Number(e.target.value)] })} - aria-labelledby="speed-label" - aria-describedby="speed-description" - aria-valuetext={`${recipe.speed}x speed, ${getSpeedDescription(recipe.speed)}`} - className="w-full h-11 accent-film-600 cursor-pointer" + value={localSpeedIndex} + onChange={(e) => { + setLocalSpeedIndex(Number(e.target.value)); + }} + onPointerUp={(e) => { + onChange({ speed: SPEED_STEPS[Number(e.currentTarget.value)] }); + }} + onKeyUp={(e) => { + if (['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'].includes(e.key)) { + onChange({ speed: SPEED_STEPS[Number(e.currentTarget.value)] }); + } + }} + className="w-full accent-film-600 cursor-pointer" /> -
+
{SPEED_STEPS.map((s) => ( - - {s}x - + {s}x ))}
- {recipe.keepAudio && ( +
- )} - - {recipe.keepAudio && (recipe.trimStart !== 0 || recipe.trimEnd !== null) && ( -
-
- )} +
); -} \ No newline at end of file +}