From fedbfa5756709f850fddf49958505e46780eac82 Mon Sep 17 00:00:00 2001 From: Rye Date: Thu, 12 Mar 2026 03:40:58 +0100 Subject: [PATCH] adjusted code styling to match ours --- .../features/room/AudioMessageRecorder.tsx | 2 +- .../plugins}/voice-recorder-kit/README.md | 0 .../voice-recorder-kit/VoiceRecorder.tsx | 49 +++++------- src/app/plugins/voice-recorder-kit/icons.tsx | 76 +++++++++++++++++++ .../plugins}/voice-recorder-kit/index.ts | 0 .../plugins}/voice-recorder-kit/types.ts | 0 .../voice-recorder-kit/useVoiceRecorder.ts | 20 ++--- src/voice-recorder-kit/icons.tsx | 64 ---------------- 8 files changed, 107 insertions(+), 104 deletions(-) rename src/{ => app/plugins}/voice-recorder-kit/README.md (100%) rename src/{ => app/plugins}/voice-recorder-kit/VoiceRecorder.tsx (95%) create mode 100644 src/app/plugins/voice-recorder-kit/icons.tsx rename src/{ => app/plugins}/voice-recorder-kit/index.ts (100%) rename src/{ => app/plugins}/voice-recorder-kit/types.ts (100%) rename src/{ => app/plugins}/voice-recorder-kit/useVoiceRecorder.ts (98%) delete mode 100644 src/voice-recorder-kit/icons.tsx diff --git a/src/app/features/room/AudioMessageRecorder.tsx b/src/app/features/room/AudioMessageRecorder.tsx index 38ebe7214..c5dd36c3e 100644 --- a/src/app/features/room/AudioMessageRecorder.tsx +++ b/src/app/features/room/AudioMessageRecorder.tsx @@ -1,7 +1,7 @@ +import { VoiceRecorder } from '$plugins/voice-recorder-kit'; import FocusTrap from 'focus-trap-react'; import { Box, Text, color, config } from 'folds'; import { useRef } from 'react'; -import { VoiceRecorder } from 'src/voice-recorder-kit'; type AudioMessageRecorderProps = { onRecordingComplete: (audioBlob: Blob) => void; diff --git a/src/voice-recorder-kit/README.md b/src/app/plugins/voice-recorder-kit/README.md similarity index 100% rename from src/voice-recorder-kit/README.md rename to src/app/plugins/voice-recorder-kit/README.md diff --git a/src/voice-recorder-kit/VoiceRecorder.tsx b/src/app/plugins/voice-recorder-kit/VoiceRecorder.tsx similarity index 95% rename from src/voice-recorder-kit/VoiceRecorder.tsx rename to src/app/plugins/voice-recorder-kit/VoiceRecorder.tsx index 43952b72a..a51f634a9 100644 --- a/src/voice-recorder-kit/VoiceRecorder.tsx +++ b/src/app/plugins/voice-recorder-kit/VoiceRecorder.tsx @@ -1,10 +1,10 @@ -import type { FC, CSSProperties } from 'react'; +import type { CSSProperties } from 'react'; import { useMemo, useRef, useEffect, useState } from 'react'; import { useVoiceRecorder } from './useVoiceRecorder'; import type { VoiceRecorderProps } from './types'; import { PlayIcon, PauseIcon, StopIcon, RepeatIcon, DeleteIcon, ResumeIcon } from './icons'; -const VoiceRecorder: FC = (props) => { +function VoiceRecorder(props: VoiceRecorderProps) { const { width, height, @@ -49,9 +49,7 @@ const VoiceRecorder: FC = (props) => { state, isRecording, isStopped, - isTemporaryStopped, isPlaying, - isPaused, seconds, levels, error, @@ -63,7 +61,6 @@ const VoiceRecorder: FC = (props) => { handlePlay, handleRestart, handleDelete, - handleRecordAgain, } = useVoiceRecorder(recorderOptions); const containerRef = useRef(null); @@ -104,7 +101,7 @@ const VoiceRecorder: FC = (props) => { } const calculatedBars = Math.floor(visualizerWidth / (barWidth + barGap)); return Math.max(calculatedBars, 1); - }, [visualizerWidth, levels.length]); + }, [visualizerWidth, levels.length, barWidth, barGap]); const displayedLevels = useMemo(() => { if (maxBars <= 0 || levels.length === 0) { @@ -148,7 +145,7 @@ const VoiceRecorder: FC = (props) => { border: `1px solid ${borderColor}`, padding: typeof padding === 'number' ? `${padding}px` : padding, width: width ?? '100%', - height: height, + height, boxSizing: 'border-box', ...style, }), @@ -189,27 +186,21 @@ const VoiceRecorder: FC = (props) => { justifyContent: 'flex-start', }} > - {displayedLevels.map((level, index) => { - const clamped = Math.max(0.1, Math.min(level, 1)); - const barHeight = 1 + clamped * (visualizerBarHeight - 1); - const barColor = - typeof visualizerBarColor === 'function' - ? visualizerBarColor(level, index) - : visualizerBarColor; - - return ( - - ); - })} + {displayedLevels.map((level) => ( + + ))} {state === 'recording' && ( @@ -624,6 +615,6 @@ const VoiceRecorder: FC = (props) => { )} ); -}; +} export default VoiceRecorder; diff --git a/src/app/plugins/voice-recorder-kit/icons.tsx b/src/app/plugins/voice-recorder-kit/icons.tsx new file mode 100644 index 000000000..29248a00a --- /dev/null +++ b/src/app/plugins/voice-recorder-kit/icons.tsx @@ -0,0 +1,76 @@ +import type { FC } from 'react'; + +export const PlayIcon: FC<{ size?: number }> = function ({ size = 18 }) { + return ( + + + + + ); +}; + +export const ResumeIcon: FC<{ size?: number }> = function ({ size = 18 }) { + return ( + + + + ); +}; + +export const PauseIcon: FC<{ size?: number }> = function ({ size = 18 }) { + return ( + + + + + ); +}; + +export const StopIcon: FC<{ size?: number }> = function ({ size = 18 }) { + return ( + + + + ); +}; + +export const DeleteIcon: FC<{ size?: number }> = function ({ size = 18 }) { + return ( + + + + + + + + ); +}; + +export const RepeatIcon: FC<{ size?: number }> = function ({ size = 18 }) { + return ( + + + + ); +}; diff --git a/src/voice-recorder-kit/index.ts b/src/app/plugins/voice-recorder-kit/index.ts similarity index 100% rename from src/voice-recorder-kit/index.ts rename to src/app/plugins/voice-recorder-kit/index.ts diff --git a/src/voice-recorder-kit/types.ts b/src/app/plugins/voice-recorder-kit/types.ts similarity index 100% rename from src/voice-recorder-kit/types.ts rename to src/app/plugins/voice-recorder-kit/types.ts diff --git a/src/voice-recorder-kit/useVoiceRecorder.ts b/src/app/plugins/voice-recorder-kit/useVoiceRecorder.ts similarity index 98% rename from src/voice-recorder-kit/useVoiceRecorder.ts rename to src/app/plugins/voice-recorder-kit/useVoiceRecorder.ts index fbb6a13a9..454762463 100644 --- a/src/voice-recorder-kit/useVoiceRecorder.ts +++ b/src/app/plugins/voice-recorder-kit/useVoiceRecorder.ts @@ -19,11 +19,11 @@ function downsampleWaveform(samples: number[], targetCount: number): number[] { } const result: number[] = []; const blockSize = samples.length / targetCount; - for (let i = 0; i < targetCount; i++) { + for (let i = 0; i < targetCount; i += 1) { const start = Math.floor(i * blockSize); const end = Math.floor((i + 1) * blockSize); let sum = 0; - for (let j = start; j < end; j++) { + for (let j = start; j < end; j += 1) { sum += samples[j]; } result.push(sum / (end - start)); @@ -199,7 +199,7 @@ export function useVoiceRecorder(options: UseVoiceRecorderOptions = {}): UseVoic analyserRef.current = analyser; dataArrayRef.current = dataArray; source.connect(analyser); - void audioContext.resume(); + audioContext.resume().catch(() => {}); animateLevels(); }, [animateLevels] @@ -219,7 +219,7 @@ export function useVoiceRecorder(options: UseVoiceRecorderOptions = {}): UseVoic dataArrayRef.current = dataArray; source.connect(analyser); analyser.connect(audioContext.destination); - void audioContext.resume(); + audioContext.resume().catch(() => {}); animateLevels(); }, [animateLevels] @@ -326,7 +326,7 @@ export function useVoiceRecorder(options: UseVoiceRecorderOptions = {}): UseVoic ]); const start = useCallback(() => { - void internalStartRecording(); + internalStartRecording(); }, [internalStartRecording]); const handlePause = useCallback(() => { @@ -346,7 +346,7 @@ export function useVoiceRecorder(options: UseVoiceRecorderOptions = {}): UseVoic } if (audioContextRef.current && audioContextRef.current.state !== 'closed') { - void audioContextRef.current.suspend(); + audioContextRef.current.suspend().catch(() => {}); } setLevels(Array.from({ length: BAR_COUNT }, () => 0.15)); @@ -497,7 +497,7 @@ export function useVoiceRecorder(options: UseVoiceRecorderOptions = {}): UseVoic audio.currentTime = 0; setSeconds(0); } - void audio.play(); + audio.play().catch(() => {}); } }, [ audioUrl, @@ -546,7 +546,7 @@ export function useVoiceRecorder(options: UseVoiceRecorderOptions = {}): UseVoic audio.currentTime = 0; setSeconds(0); } - void audio.play(); + audio.play().catch(() => {}); } }, [audioUrl, cleanupAudioContext, isPlaying, setupPlaybackGraph, startPlaybackTimer, stopTimer]); @@ -730,12 +730,12 @@ export function useVoiceRecorder(options: UseVoiceRecorderOptions = {}): UseVoic setAudioUrl(null); setAudioFile(null); - void internalStartRecording(); + internalStartRecording(); }, [cleanupAudioContext, cleanupStream, internalStartRecording, stopTimer]); useEffect(() => { if (autoStart) { - void internalStartRecording(); + internalStartRecording(); } return () => { const mediaRecorder = mediaRecorderRef.current; diff --git a/src/voice-recorder-kit/icons.tsx b/src/voice-recorder-kit/icons.tsx deleted file mode 100644 index 1286d88f1..000000000 --- a/src/voice-recorder-kit/icons.tsx +++ /dev/null @@ -1,64 +0,0 @@ -import type { FC } from 'react'; - -export const PlayIcon: FC<{ size?: number }> = ({ size = 18 }) => ( - - - - -); - -export const ResumeIcon: FC<{ size?: number }> = ({ size = 18 }) => ( - - - -); - -export const PauseIcon: FC<{ size?: number }> = ({ size = 18 }) => ( - - - - -); - -export const StopIcon: FC<{ size?: number }> = ({ size = 18 }) => ( - - - -); - -export const DeleteIcon: FC<{ size?: number }> = ({ size = 18 }) => ( - - - - - - - -); - -export const RepeatIcon: FC<{ size?: number }> = ({ size = 18 }) => ( - - - -);