From 1cd79734b8e5b465681d01bb61691545fe781b7c Mon Sep 17 00:00:00 2001 From: TheNexter Date: Wed, 19 Nov 2025 12:53:59 +0100 Subject: [PATCH] Apply suggestion made by Copilot --- web/src/components/AudioPlayer.tsx | 18 ++++++++++++------ .../MemoEditor/ActionButton/InsertMenu.tsx | 4 ++-- web/src/locales/en.json | 5 +++-- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/web/src/components/AudioPlayer.tsx b/web/src/components/AudioPlayer.tsx index a0d9277dc..c05dbc4cc 100644 --- a/web/src/components/AudioPlayer.tsx +++ b/web/src/components/AudioPlayer.tsx @@ -27,8 +27,8 @@ const AudioPlayer = ({ src, className = "" }: Props) => { const handleTimeUpdate = () => { setCurrentTime(audio.currentTime); - if (duration === 0 && audio.duration && !isNaN(audio.duration) && isFinite(audio.duration)) { - setDuration(audio.duration); + if (audio.duration && !isNaN(audio.duration) && isFinite(audio.duration)) { + setDuration((prev) => (prev === 0 ? audio.duration : prev)); } }; @@ -59,16 +59,22 @@ const AudioPlayer = ({ src, className = "" }: Props) => { }; }, []); - const togglePlayPause = () => { + const togglePlayPause = async () => { const audio = audioRef.current; if (!audio) return; if (isPlaying) { audio.pause(); + setIsPlaying(false); } else { - audio.play(); + try { + await audio.play(); + setIsPlaying(true); + } catch (error) { + console.error("Failed to play audio:", error); + setIsPlaying(false); + } } - setIsPlaying(!isPlaying); }; const handleSeek = (e: React.ChangeEvent) => { @@ -112,7 +118,7 @@ const AudioPlayer = ({ src, className = "" }: Props) => { value={currentTime} onChange={handleSeek} disabled={isLoading || !duration} - className="flex-1 h-1 bg-muted hover:bg-background/50 hover:bg-background/50 rounded-lg appearance-none cursor-pointer disabled:opacity-50 [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-3 [&::-webkit-slider-thumb]:h-3 [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-primary [&::-moz-range-thumb]:w-3 [&::-moz-range-thumb]:h-3 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:bg-primary [&::-moz-range-thumb]:border-0" + className="flex-1 h-1 bg-muted hover:bg-background/50 rounded-lg appearance-none cursor-pointer disabled:opacity-50 [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-3 [&::-webkit-slider-thumb]:h-3 [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-primary [&::-moz-range-thumb]:w-3 [&::-moz-range-thumb]:h-3 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:bg-primary [&::-moz-range-thumb]:border-0" /> diff --git a/web/src/components/MemoEditor/ActionButton/InsertMenu.tsx b/web/src/components/MemoEditor/ActionButton/InsertMenu.tsx index 949554ae8..1fea285b3 100644 --- a/web/src/components/MemoEditor/ActionButton/InsertMenu.tsx +++ b/web/src/components/MemoEditor/ActionButton/InsertMenu.tsx @@ -146,7 +146,7 @@ const InsertMenu = observer((props: Props) => {
- {new Date(audioRecorder.recordingTime * 1000).toISOString().substr(14, 5)} + {new Date(audioRecorder.recordingTime * 1000).toISOString().substring(14, 19)}