diff --git a/src/renderer/src/components/popover/Popover.tsx b/src/renderer/src/components/popover/Popover.tsx index eca37c4f..6de7b087 100644 --- a/src/renderer/src/components/popover/Popover.tsx +++ b/src/renderer/src/components/popover/Popover.tsx @@ -1,6 +1,7 @@ import PopoverContent from "./PopoverContent"; import PopoverOverlay from "./PopoverOverlay"; import PopoverTrigger from "./PopoverTrigger"; +import { PopoverAnchor } from "./PopoverTrigger"; import "./styles.css"; import { computePosition, @@ -39,10 +40,10 @@ function useProviderValue(props: Props) { }); const [position, setPosition] = createSignal(null); - const [triggerRef, _setTriggerRef] = createSignal(null); + const [triggerRef, _setTriggerRef] = createSignal(null); const [contentRef, _setContentRef] = createSignal(null); - const setTriggerRef = (element: HTMLButtonElement) => { + const setTriggerRef = (element: HTMLElement) => { _setTriggerRef(element); listenResize(); }; @@ -119,6 +120,7 @@ export function usePopover(): Context { } const Popover = Object.assign(PopoverRoot, { + Anchor: PopoverAnchor, Content: PopoverContent, Trigger: PopoverTrigger, Overlay: PopoverOverlay, diff --git a/src/renderer/src/components/popover/PopoverTrigger.tsx b/src/renderer/src/components/popover/PopoverTrigger.tsx index 5eaf9164..5b18756c 100644 --- a/src/renderer/src/components/popover/PopoverTrigger.tsx +++ b/src/renderer/src/components/popover/PopoverTrigger.tsx @@ -17,4 +17,10 @@ const PopoverTrigger: Component = (props) => { ); }; +type PopoverAnchorProps = JSX.IntrinsicElements["div"]; +export const PopoverAnchor: Component = (props) => { + const state = usePopover(); + return
; +}; + export default PopoverTrigger; diff --git a/src/renderer/src/components/song/song-detail/SongControls.tsx b/src/renderer/src/components/song/song-detail/SongControls.tsx index 0fbdfc56..26587ec4 100644 --- a/src/renderer/src/components/song/song-detail/SongControls.tsx +++ b/src/renderer/src/components/song/song-detail/SongControls.tsx @@ -7,12 +7,15 @@ import { song, setVolume, volume, + setSpeed, + speed, handleMuteSong, } from "../song.utils"; import Button from "@renderer/components/button/Button"; import Slider from "@renderer/components/slider/Slider"; import { CirclePlusIcon, + GaugeIcon, PauseIcon, PlayIcon, RepeatIcon, @@ -23,7 +26,10 @@ import { Volume2Icon, VolumeXIcon, } from "lucide-solid"; -import { Component, createEffect, createSignal, Match, Show, Switch } from "solid-js"; +import { Component, createEffect, createSignal, Match, Show, Switch, For } from "solid-js"; +import Popover from "../../popover/Popover"; +import { ParentComponent } from "solid-js"; +import { Portal } from "solid-js/web"; // Add a prop to accept the averageColor type SongControlsProps = { @@ -167,9 +173,61 @@ const LeftPart = () => { ); }; +const PREDEFINED_SPEEDS: number[] = [0.25, 0.5, 1, 1.5, 2] as const; +const MIN_SPEED_AMOUNT = PREDEFINED_SPEEDS[0]; +const MAX_SPEED_AMOUNT = PREDEFINED_SPEEDS.at(-1); const RightPart = () => { + const [isPopoverOpen, setisPopoverOpen] = createSignal(false); + return ( -
+
+ + + + + + + + +

Custom Speed

+
+ + + + + + +
{Math.round(speed() * 100) / 100}x
+
+
+ + + {(amount) => {amount}} + + + + @@ -177,4 +235,18 @@ const RightPart = () => { ); }; +type SpeedOptionProps = { + amount: number; +}; +const SpeedOption: ParentComponent = (props) => { + return ( + + ); +}; + export default SongControls; diff --git a/src/renderer/src/components/song/song.utils.ts b/src/renderer/src/components/song/song.utils.ts index 3afdd5f9..0ae9e3b5 100644 --- a/src/renderer/src/components/song/song.utils.ts +++ b/src/renderer/src/components/song/song.utils.ts @@ -51,7 +51,13 @@ export const setVolume = (newValue: ZeroToOne) => { _setVolume(newValue); setValueBeforeMute(undefined); }; -export { volume }; + +const [speed, _setSpeed] = createSignal(1); +export const setSpeed = (newValue: ZeroToOne) => { + _setSpeed(newValue); + player.playbackRate = newValue; +}; +export { volume, speed }; let bgPath: Optional; @@ -295,6 +301,7 @@ window.api.listen("queue::songChanged", async (s) => { setSong(s); await window.api.request("discord::play", s); await play(); + player.playbackRate = speed(); }); player.addEventListener("ended", async () => {