From a2c4764c023ad1e6a8a8b63a5ecbc60cbc7619d8 Mon Sep 17 00:00:00 2001 From: an-lee Date: Sun, 8 Sep 2024 21:10:14 +0800 Subject: [PATCH] refactor code --- .../medias/media-current-recording.tsx | 28 ++----------------- .../media-transcription-generate-button.tsx | 9 +++--- .../context/media-player-provider.tsx | 2 ++ 3 files changed, 10 insertions(+), 29 deletions(-) diff --git a/enjoy/src/renderer/components/medias/media-current-recording.tsx b/enjoy/src/renderer/components/medias/media-current-recording.tsx index a5732ec5..7ba1b775 100644 --- a/enjoy/src/renderer/components/medias/media-current-recording.tsx +++ b/enjoy/src/renderer/components/medias/media-current-recording.tsx @@ -693,12 +693,11 @@ export const MediaCurrentRecording = () => { }; export const MediaRecordButton = () => { - const { media, isRecording, startRecording, stopRecording, recordingTime } = - useContext(MediaPlayerProviderContext); + const { media, isRecording, startRecording, stopRecording } = useContext( + MediaPlayerProviderContext + ); const { EnjoyApp } = useContext(AppSettingsProviderContext); const [access, setAccess] = useState(true); - const [active, setActive] = useState(false); - const ref = useRef(null); const askForMediaAccess = () => { EnjoyApp.system.preferences.mediaAccess("microphone").then((access) => { @@ -715,29 +714,8 @@ export const MediaRecordButton = () => { askForMediaAccess(); }, [media]); - useEffect(() => { - if (!active) return; - if (recordingTime >= 60) { - stopRecording(); - } - }, [active, recordingTime]); - - useEffect(() => { - const rect = ref.current?.getBoundingClientRect(); - if (!rect) return; - - const elementAtPoint = document.elementFromPoint( - rect.left + rect.width / 2, - rect.top + rect.height / 2 - ); - setActive( - elementAtPoint == ref.current || ref.current.contains(elementAtPoint) - ); - }, [ref, isRecording]); - return (