Skip to content

Commit 316dbbb

Browse files
authored
chore: Rename VoicePlayerStatus for separating object and type (#531)
* Rename VoicePlayerStatus for separating instance and type * Use ModuleNameSpaces for type defining of Sdk instance
1 parent 7fc7ace commit 316dbbb

File tree

6 files changed

+34
-22
lines changed

6 files changed

+34
-22
lines changed

scripts/index_d_ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { GroupChannelModule, ModuleNamespaces, OpenChannelModule } from '@sendbird/chat/lib/__definition';
2+
13
/**
24
* Type Definitions for @sendbird/uikit-react@{{ version }}
35
* homepage: https://sendbird.com/
@@ -147,7 +149,7 @@ declare module "SendbirdUIKitGlobal" {
147149
export type EveryMessage = ClientUserMessage | ClientFileMessage | ClientAdminMessage;
148150
export type ClientSentMessages = ClientUserMessage | ClientFileMessage;
149151

150-
export type GetSdk = SendbirdChat | SendbirdGroupChat | SendbirdOpenChat | undefined;
152+
export type GetSdk = SendbirdChat & ModuleNamespaces<[GroupChannelModule, OpenChannelModule]> | undefined;
151153
export type GetConnect = (
152154
userId: string,
153155
accessToken?: string
@@ -483,13 +485,15 @@ declare module "SendbirdUIKitGlobal" {
483485
onCancel: () => void;
484486
};
485487

486-
export enum VoicePlayerStatus {
488+
export enum VoicePlayerStatusType {
487489
IDLE = 'IDLE',
488490
PREPARING = 'PREPARING',
489491
READY_TO_PLAY = 'READY_TO_PLAY',
490492
PLAYING = 'PLAYING',
491493
COMPLETED = 'COMPLETED',
492494
}
495+
// should be deprecated / for backward
496+
export type VoicePlayerStatus = VoicePlayerStatusType;
493497

494498
/**
495499
* Channel
@@ -1895,11 +1899,18 @@ declare module '@sendbird/uikit-react/ui/FileMessageItemBody' {
18951899
}
18961900

18971901
declare module '@sendbird/uikit-react/ui/VoiceMessageItemBody' {
1902+
enum VoicePlayerStatusType {
1903+
IDLE = 'IDLE',
1904+
PREPARING = 'PREPARING',
1905+
READY_TO_PLAY = 'READY_TO_PLAY',
1906+
PLAYING = 'PLAYING',
1907+
COMPLETED = 'COMPLETED',
1908+
}
18981909
interface VoiceMessageItemBodyProps {
18991910
minRecordTime?: number;
19001911
maximumValue: number;
19011912
currentValue?: number;
1902-
currentType: VoicePlayerStatus;
1913+
currentType: VoicePlayerStatusType;
19031914
}
19041915
type VoiceMessageItemBody = React.FC<VoiceMessageItemBodyProps>;
19051916
export default VoiceMessageItemBody;

src/hooks/VoicePlayer/dux/initialState.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1+
import { ObjectValues } from '../../../utils/typeHelpers/objectValues';
12
import { GroupKey } from '../utils';
23

3-
/* eslint-disable no-redeclare */
4-
export const VoicePlayerStatus = {
4+
export const VOICE_PLAYER_STATUS = {
55
IDLE: 'IDLE',
66
PREPARING: 'PREPARING',
77
PLAYING: 'PLAYING',
88
PAUSED: 'PAUSED',
99
COMPLETED: 'COMPLETED',
1010
} as const;
11-
export type VoicePlayerStatus = typeof VoicePlayerStatus[keyof typeof VoicePlayerStatus];
11+
// VoicePlayerStatus should be deprecated / It's left for backward legacy
12+
export const VoicePlayerStatus = VOICE_PLAYER_STATUS;
13+
export type VoicePlayerStatusType = ObjectValues<typeof VOICE_PLAYER_STATUS>;
1214

1315
export type AudioStorageUnit = {
14-
playingStatus: VoicePlayerStatus;
16+
playingStatus: VoicePlayerStatusType;
1517
audioFile: null | File;
1618
playbackTime: number;
1719
duration: number;
@@ -20,10 +22,9 @@ export const AudioUnitDefaultValue = (): AudioStorageUnit => ({
2022
audioFile: null,
2123
playbackTime: 0,
2224
duration: 1000,
23-
playingStatus: VoicePlayerStatus.IDLE,
25+
playingStatus: VOICE_PLAYER_STATUS.IDLE,
2426
});
2527

26-
/* eslint-disable no-redeclare */
2728
export interface VoicePlayerInitialState {
2829
currentPlayer: null | HTMLAudioElement;
2930
currentGroupKey: string;

src/hooks/VoicePlayer/dux/reducer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
AudioStorageUnit,
1010
AudioUnitDefaultValue,
1111
VoicePlayerInitialState,
12-
VoicePlayerStatus,
12+
VOICE_PLAYER_STATUS,
1313
} from './initialState';
1414

1515
type InitializeAudioUnitPayload = { groupKey: string };
@@ -37,7 +37,7 @@ export default function voicePlayerReducer(
3737
case INITIALIZE_AUDIO_UNIT: {
3838
const { groupKey } = action.payload as InitializeAudioUnitPayload;
3939
const audioUnit = (state.audioStorage?.[groupKey] ? state.audioStorage[groupKey] : AudioUnitDefaultValue()) as AudioStorageUnit;
40-
audioUnit.playingStatus = VoicePlayerStatus.PREPARING;
40+
audioUnit.playingStatus = VOICE_PLAYER_STATUS.PREPARING;
4141
return {
4242
...state,
4343
audioStorage: {
@@ -58,7 +58,7 @@ export default function voicePlayerReducer(
5858
const { groupKey, audioFile } = action.payload as OnVoicePlayerPlayPayload;
5959
const audioUnit = (state.audioStorage?.[groupKey] ? state.audioStorage[groupKey] : AudioUnitDefaultValue()) as AudioStorageUnit;
6060
audioUnit.audioFile = audioFile;
61-
audioUnit.playingStatus = VoicePlayerStatus.PLAYING;
61+
audioUnit.playingStatus = VOICE_PLAYER_STATUS.PLAYING;
6262
return {
6363
...state,
6464
audioStorage: {
@@ -70,7 +70,7 @@ export default function voicePlayerReducer(
7070
case ON_VOICE_PLAYER_PAUSE: {
7171
const { groupKey } = action.payload as OnVoicePlayerPausePayload;
7272
const audioUnit = (state.audioStorage?.[groupKey] ? state.audioStorage[groupKey] : AudioUnitDefaultValue()) as AudioStorageUnit;
73-
audioUnit.playingStatus = VoicePlayerStatus.PAUSED;
73+
audioUnit.playingStatus = VOICE_PLAYER_STATUS.PAUSED;
7474
const { currentTime, duration } = state.currentPlayer as HTMLAudioElement;
7575
if (audioUnit.playbackTime === audioUnit.duration) {
7676
audioUnit.playbackTime = 0;

src/hooks/VoicePlayer/useVoicePlayer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useVoicePlayerContext } from '.';
33
import { VOICE_PLAYER_AUDIO_ID } from '../../utils/consts';
44
import { useVoiceRecorderContext } from '../VoiceRecorder';
55

6-
import { AudioUnitDefaultValue, VoicePlayerStatus } from './dux/initialState';
6+
import { AudioUnitDefaultValue, VoicePlayerStatusType } from './dux/initialState';
77
import { generateGroupKey } from './utils';
88

99
export interface UseVoicePlayerProps {
@@ -19,7 +19,7 @@ export interface UseVoicePlayerContext {
1919
stop: (text?: string) => void;
2020
playbackTime: number;
2121
duration: number;
22-
playingStatus: VoicePlayerStatus;
22+
playingStatus: VoicePlayerStatusType;
2323
}
2424

2525
export const useVoicePlayer = ({

src/modules/Channel/components/MessageInput/VoiceMessageInputWrapper.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Modal from '../../../../ui/Modal';
1313
import Button, { ButtonSizes, ButtonTypes } from '../../../../ui/Button';
1414
import useSendbirdStateContext from '../../../../hooks/useSendbirdStateContext';
1515
import { VOICE_RECORDER_DEFAULT_MIN } from '../../../../utils/consts';
16-
import { VoicePlayerStatus } from '../../../../hooks/VoicePlayer/dux/initialState';
16+
import { VOICE_PLAYER_STATUS } from '../../../../hooks/VoicePlayer/dux/initialState';
1717
import uuidv4 from '../../../../utils/uuid';
1818

1919
export interface VoiceMessageInputWrapperProps {
@@ -87,7 +87,7 @@ export const VoiceMessageInputWrapper = ({
8787
if (recordingTime < minRecordingTime) {
8888
setVoiceInputState(VoiceMessageInputStatus.READY_TO_RECORD);
8989
setAudioFile(null);
90-
} else if (playingStatus === VoicePlayerStatus.PLAYING) {
90+
} else if (playingStatus === VOICE_PLAYER_STATUS.PLAYING) {
9191
setVoiceInputState(VoiceMessageInputStatus.PLAYING);
9292
} else {
9393
setVoiceInputState(VoiceMessageInputStatus.READY_TO_PLAY);

src/ui/VoiceMessageItemBody/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import PlaybackTime from '../PlaybackTime';
99
import Loader from '../Loader';
1010
import Icon, { IconTypes, IconColors } from '../Icon';
1111
import { LabelTypography, LabelColors } from '../Label';
12-
import { VoicePlayerStatus } from '../../hooks/VoicePlayer/dux/initialState';
12+
import { VOICE_PLAYER_STATUS } from '../../hooks/VoicePlayer/dux/initialState';
1313

1414
export interface VoiceMessageItemBodyProps {
1515
className?: string;
@@ -32,7 +32,7 @@ export const VoiceMessageItemBody = ({
3232
pause,
3333
playbackTime = 0,
3434
duration,
35-
playingStatus = VoicePlayerStatus.IDLE,
35+
playingStatus = VOICE_PLAYER_STATUS.IDLE,
3636
} = useVoicePlayer({
3737
channelUrl,
3838
key: `${message?.messageId}`,
@@ -63,7 +63,7 @@ export const VoiceMessageItemBody = ({
6363
colorType={isByMe ? ProgressBarColorTypes.PRIMARY : ProgressBarColorTypes.GRAY}
6464
/>
6565
<div className="sendbird-voice-message-item-body__status-button">
66-
{(playingStatus === VoicePlayerStatus.IDLE || playingStatus === VoicePlayerStatus.PAUSED) && (
66+
{(playingStatus === VOICE_PLAYER_STATUS.IDLE || playingStatus === VOICE_PLAYER_STATUS.PAUSED) && (
6767
<div
6868
className="sendbird-voice-message-item-body__status-button__button"
6969
onClick={play}
@@ -76,7 +76,7 @@ export const VoiceMessageItemBody = ({
7676
/>
7777
</div>
7878
)}
79-
{playingStatus === VoicePlayerStatus.PREPARING && (
79+
{playingStatus === VOICE_PLAYER_STATUS.PREPARING && (
8080
<Loader width="22.2px" height="22.2px">
8181
<Icon
8282
width="22.2px"
@@ -86,7 +86,7 @@ export const VoiceMessageItemBody = ({
8686
/>
8787
</Loader>
8888
)}
89-
{playingStatus === VoicePlayerStatus.PLAYING && (
89+
{playingStatus === VOICE_PLAYER_STATUS.PLAYING && (
9090
<div
9191
className="sendbird-voice-message-item-body__status-button__button"
9292
onClick={() => { pause(); }}

0 commit comments

Comments
 (0)