From 89b1720dd086d6596c8edc7ffb6434fdab3a6206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Okan=20I=C5=9F=C4=B1ldar?= Date: Sun, 17 Dec 2023 17:13:34 +0300 Subject: [PATCH] chore: make audio player prettier remove some functionaliy --- components/audio-player.module.css | 13 +- components/audio-player.tsx | 184 +++++++++++++++-------------- components/episode-detail.tsx | 20 +++- 3 files changed, 115 insertions(+), 102 deletions(-) diff --git a/components/audio-player.module.css b/components/audio-player.module.css index d256db2..2749e16 100644 --- a/components/audio-player.module.css +++ b/components/audio-player.module.css @@ -1,14 +1,3 @@ -.RatingsSelect { - appearance: none; - border: 0; - text-align: center; - font-size: 0.8rem; +.IconButton:hover { background-color: transparent; - cursor: pointer; - width: 32px; -} - -.RatingsSelect:focus-visible { - border: 0; - outline: 0; } diff --git a/components/audio-player.tsx b/components/audio-player.tsx index 578852c..d5f4b27 100644 --- a/components/audio-player.tsx +++ b/components/audio-player.tsx @@ -1,14 +1,12 @@ /* eslint-disable jsx-a11y/media-has-caption -- we don't have any captions for our audio. */ 'use client'; -import type { ChangeEvent } from 'react'; -import { Flex, IconButton, Slider, Text } from '@radix-ui/themes'; +import { Box, Button, Flex, IconButton, Slider, Text } from '@radix-ui/themes'; import formatDuration from 'format-duration'; import { useRef, useState } from 'react'; -import { FaPauseCircle } from 'react-icons/fa'; +import { FaPauseCircle, FaPlay } from 'react-icons/fa'; import { FaCirclePlay } from 'react-icons/fa6'; -import { IoVolumeMuteOutline } from 'react-icons/io5'; -import { RiForward15Line, RiReplay15Fill } from 'react-icons/ri'; +import { MdForward30, MdReplay30 } from 'react-icons/md'; import styles from './audio-player.module.css'; @@ -18,68 +16,60 @@ type Props = { }; function AudioPlayerControls({ - muted, onFastForward, onPlayPause, onRewind, - onSetPlaybackRate, - playbackRate, + playerRef, playing, - setMuted, - setPlaybackRate, }: { - muted: boolean; onFastForward: () => void; onPlayPause: () => void; onRewind: () => void; - onSetPlaybackRate: (rate: number) => void; playbackRate: number; + playerRef: { current: HTMLAudioElement | null }; playing: boolean; - setMuted: (muted: boolean) => void; - setPlaybackRate: (rate: number) => void; }) { + if (!playerRef.current) { + return ( + + + + ); + } + return ( - + { - setMuted(!muted); - }} + onClick={onRewind} variant="ghost" > - + - - - - + {playing ? ( - + ) : ( - + )} - - - - - + + ); } @@ -107,33 +97,63 @@ function PlayerBar({ sm: '4', }} > - { - if (typeof value[0] !== 'number' || !playerRef.current) { - return; - } - const position = Math.floor(value[0]); - setSliderPosition(position); - playerRef.current.currentTime = position; + + + {formatDuration((playerRef.current?.currentTime ?? 0) * 1000)} + + + - + { + if (typeof value[0] !== 'number' || !playerRef.current) { + return; + } + const position = Math.floor(value[0]); + setSliderPosition(position); + playerRef.current.currentTime = position; + }} + size="1" + style={{ + width: 240, + }} + value={[sliderPosition]} + /> + + - {formatDuration((duration - sliderPosition) * 1000)} left - + + -{formatDuration((duration - sliderPosition) * 1000)} + + ); } @@ -143,15 +163,14 @@ export default function AudioPlayer({ audioUrl, duration }: Props) { const playerRef = useRef(null); const [sliderPosition, setSliderPosition] = useState(0); const [playbackRate, setPlaybackRate] = useState(1); - const [muted, setMuted] = useState(false); const onRewind = () => { if (!playerRef.current) return; - playerRef.current.currentTime = playerRef.current.currentTime - 15; + playerRef.current.currentTime = playerRef.current.currentTime - 30; }; const onFastForward = () => { if (!playerRef.current) return; - playerRef.current.currentTime = playerRef.current.currentTime + 15; + playerRef.current.currentTime = playerRef.current.currentTime + 30; }; const onPlayPause = async () => { if (!playerRef.current) return; @@ -162,11 +181,6 @@ export default function AudioPlayer({ audioUrl, duration }: Props) { } }; - const onSetPlaybackRate = (value: number) => { - if (!playerRef.current) return; - playerRef.current.playbackRate = value; - }; - return ( ); } diff --git a/components/episode-detail.tsx b/components/episode-detail.tsx index 987a455..ef273d9 100644 --- a/components/episode-detail.tsx +++ b/components/episode-detail.tsx @@ -45,8 +45,8 @@ function EpisodeDetailContent( sm: 'row', }} gap={{ - initial: '4', - xs: '5', + initial: '6', + sm: '6', }} > - + @@ -84,6 +93,9 @@ function EpisodeDetailContent( initial: '9', sm: '5', }} + style={{ + marginBottom: 10, + }} >