Skip to content

Commit 90ff0a4

Browse files
committed
fix: ui between state when deleting recording
1 parent 24b03de commit 90ff0a4

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

package/src/components/MessageInput/hooks/useAudioRecorder.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ export const useAudioRecorder = ({
2727
* side only. Meant to be used as a pure function (during unmounting for instance)
2828
* hence this approach.
2929
*/
30-
const stopVoiceRecording = useCallback(async () => {
31-
await audioRecorderManager.stopRecording();
32-
}, [audioRecorderManager]);
30+
const stopVoiceRecording = useCallback(
31+
async (withDelete?: boolean) => {
32+
await audioRecorderManager.stopRecording(withDelete);
33+
},
34+
[audioRecorderManager],
35+
);
3336

3437
// This effect stop the player from playing and stops audio recording on
3538
// the audio SDK side on unmount.
@@ -60,9 +63,8 @@ export const useAudioRecorder = ({
6063
* Function to delete voice recording.
6164
*/
6265
const deleteVoiceRecording = useCallback(async () => {
63-
await stopVoiceRecording();
64-
audioRecorderManager.reset();
65-
}, [audioRecorderManager, stopVoiceRecording]);
66+
await stopVoiceRecording(true);
67+
}, [stopVoiceRecording]);
6668

6769
/**
6870
* Function to upload or send voice recording.

package/src/state-store/audio-recorder-manager.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export class AudioRecorderManager {
139139
return accessGranted;
140140
}
141141

142-
async stopRecording() {
142+
async stopRecording(withDelete: boolean = false) {
143143
if (!NativeHandlers.Audio) {
144144
return;
145145
}
@@ -157,7 +157,12 @@ export class AudioRecorderManager {
157157
} catch {
158158
// Best effort cleanup, native implementation may already be stopped.
159159
}
160-
this.state.partialNext({ isStarting: false, status: 'stopped' });
160+
161+
if (withDelete) {
162+
this.reset();
163+
} else {
164+
this.state.partialNext({ isStarting: false, status: 'stopped' });
165+
}
161166
}
162167

163168
set micLocked(value: boolean) {

0 commit comments

Comments
 (0)