Skip to content

Commit c01fbf7

Browse files
✨ feat: Update import statements, add default values for "audio" parameter, refactor variable names and formatting
This commit updates the import statements and adds default values for the "audio" parameter in "index.tsx". It also refactors variable names and formatting. In "useAudioRecorder/index.ts", it changes the useState hooks and removes an eslint-disable comment.
1 parent e1d69ea commit c01fbf7

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

src/react/AudioPlayer/index.tsx

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { ActionIcon, ActionIconProps, Icon, Tag } from '@lobehub/ui';
1+
import { ActionIcon, type ActionIconProps, Icon, Tag } from '@lobehub/ui';
22
import { Dropdown, Slider } from 'antd';
33
import { Download, PauseCircle, Play, StopCircle } from 'lucide-react';
4-
import React, { memo, useCallback, useMemo } from 'react';
4+
import { type CSSProperties, memo, useCallback, useMemo } from 'react';
55
import { Flexbox } from 'react-layout-kit';
66

77
import { secondsToMinutesAndSeconds } from '@/core/utils/secondsToMinutesAndSeconds';
@@ -28,9 +28,9 @@ export interface AudioPlayerProps {
2828
onPlay?: () => void;
2929
onStop?: () => void;
3030
showSlider?: boolean;
31-
style?: React.CSSProperties;
31+
style?: CSSProperties;
3232
timeRender?: 'tag' | 'text';
33-
timeStyle?: React.CSSProperties;
33+
timeStyle?: CSSProperties;
3434
timeType?: 'left' | 'current' | 'combine';
3535
}
3636

@@ -41,7 +41,16 @@ const AudioPlayer = memo<AudioPlayerProps>(
4141
timeStyle,
4242
buttonSize,
4343
className,
44-
audio,
44+
audio = {
45+
currentTime: 0,
46+
download: () => {},
47+
duration: 0,
48+
isPlaying: false,
49+
pause: () => {},
50+
play: () => {},
51+
setTime: () => {},
52+
stop: () => {},
53+
},
4554
allowPause = true,
4655
timeType = 'left',
4756
showSlider = true,
@@ -53,9 +62,9 @@ const AudioPlayer = memo<AudioPlayerProps>(
5362
}) => {
5463
const { isPlaying, play, stop, pause, duration, setTime, currentTime, download } = audio;
5564

56-
const formatedLeftTime = secondsToMinutesAndSeconds(duration - currentTime);
57-
const formatedCurrentTime = secondsToMinutesAndSeconds(currentTime);
58-
const formatedDuration = secondsToMinutesAndSeconds(duration);
65+
const formattedLeftTime = secondsToMinutesAndSeconds(duration - currentTime);
66+
const formattedCurrentTime = secondsToMinutesAndSeconds(currentTime);
67+
const formattedDuration = secondsToMinutesAndSeconds(duration);
5968

6069
const Time = useMemo(
6170
() => (timeRender === 'tag' ? Tag : (props: any) => <div {...props} />),
@@ -122,12 +131,12 @@ const AudioPlayer = memo<AudioPlayerProps>(
122131
placement="top"
123132
>
124133
<Time style={{ cursor: 'pointer', flex: 'none', ...timeStyle }}>
125-
{timeType === 'left' && formatedLeftTime}
126-
{timeType === 'current' && formatedCurrentTime}
134+
{timeType === 'left' && formattedLeftTime}
135+
{timeType === 'current' && formattedCurrentTime}
127136
{timeType === 'combine' && (
128137
<span>
129-
{formatedCurrentTime}
130-
<span style={{ opacity: 0.66 }}>{` / ${formatedDuration}`}</span>
138+
{formattedCurrentTime}
139+
<span style={{ opacity: 0.66 }}>{` / ${formattedDuration}`}</span>
131140
</span>
132141
)}
133142
</Time>

src/react/useAudioRecorder/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ export const useAudioRecorder = (onBlobAvailable?: (blob: Blob) => void) => {
88

99
const [time, setTime] = useState(0);
1010
const [mediaRecorder, setMediaRecorder] = useState<MediaRecorder>();
11-
// eslint-disable-next-line no-undef
12-
const [timerInterval, setTimerInterval] = useState<NodeJS.Timer>();
11+
const [timerInterval, setTimerInterval] = useState<any>();
1312
const [blob, setBlob] = useState<Blob>();
1413
const [url, setUrl] = useState<string>();
1514

0 commit comments

Comments
 (0)