From 87f018a5d7acf29b6f729fb4f8011055e98ae230 Mon Sep 17 00:00:00 2001 From: Silberengel Date: Thu, 9 Apr 2026 18:30:17 +0200 Subject: [PATCH] bug-fixes --- src/components/AudioPlayer/index.tsx | 25 +- .../MediaPlayer/LazyMediaTapPlaceholder.tsx | 109 +++++-- src/components/MediaPlayer/index.tsx | 175 +++++++++-- .../NoteOptions/EditOrCloneEventDialog.tsx | 22 +- src/components/PostEditor/PostContent.tsx | 282 +++++++++--------- .../PostTextarea/ClipboardAndDropHandler.ts | 2 +- src/components/VideoPlayer/index.tsx | 29 +- src/lib/draft-event.ts | 102 ++++++- 8 files changed, 514 insertions(+), 232 deletions(-) diff --git a/src/components/AudioPlayer/index.tsx b/src/components/AudioPlayer/index.tsx index eccbce2a..3a8dc54f 100644 --- a/src/components/AudioPlayer/index.tsx +++ b/src/components/AudioPlayer/index.tsx @@ -11,9 +11,11 @@ import logger from '@/lib/logger' interface AudioPlayerProps { src: string className?: string + /** Fires when enough data is buffered to play (e.g. to swap out a blurhash placeholder). */ + onReady?: () => void } -export default function AudioPlayer({ src, className }: AudioPlayerProps) { +export default function AudioPlayer({ src, className, onReady }: AudioPlayerProps) { const audioRef = useRef(null) const [isPlaying, setIsPlaying] = useState(false) const [currentTime, setCurrentTime] = useState(0) @@ -22,6 +24,25 @@ export default function AudioPlayer({ src, className }: AudioPlayerProps) { const seekTimeoutRef = useRef() const isSeeking = useRef(false) + useEffect(() => { + if (!onReady) return + const audio = audioRef.current + if (!audio) return + const notify = () => onReady() + if (audio.readyState >= HTMLMediaElement.HAVE_FUTURE_DATA) { + notify() + return + } + audio.addEventListener('canplay', notify, { once: true }) + return () => audio.removeEventListener('canplay', notify) + }, [src, onReady]) + + useEffect(() => { + if (error) { + onReady?.() + } + }, [error, onReady]) + useEffect(() => { const audio = audioRef.current if (!audio) return @@ -104,7 +125,7 @@ export default function AudioPlayer({ src, className }: AudioPlayerProps) { )} onClick={(e) => e.stopPropagation()} > -