Use useTypedEventEmitterState for broadcasts (#9947)
This commit is contained in:
parent
9dbc5f3773
commit
234061c847
7 changed files with 67 additions and 49 deletions
|
@ -16,7 +16,7 @@ limitations under the License.
|
|||
|
||||
import { Room } from "matrix-js-sdk/src/models/room";
|
||||
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
|
||||
import React, { useState } from "react";
|
||||
import React from "react";
|
||||
|
||||
import {
|
||||
VoiceBroadcastInfoState,
|
||||
|
@ -25,7 +25,7 @@ import {
|
|||
VoiceBroadcastRecordingState,
|
||||
} from "..";
|
||||
import QuestionDialog from "../../components/views/dialogs/QuestionDialog";
|
||||
import { useTypedEventEmitter } from "../../hooks/useEventEmitter";
|
||||
import { useTypedEventEmitterState } from "../../hooks/useEventEmitter";
|
||||
import { _t } from "../../languageHandler";
|
||||
import { MatrixClientPeg } from "../../MatrixClientPeg";
|
||||
import Modal from "../../Modal";
|
||||
|
@ -74,17 +74,21 @@ export const useVoiceBroadcastRecording = (
|
|||
}
|
||||
};
|
||||
|
||||
const [recordingState, setRecordingState] = useState(recording.getState());
|
||||
useTypedEventEmitter(
|
||||
const recordingState = useTypedEventEmitterState(
|
||||
recording,
|
||||
VoiceBroadcastRecordingEvent.StateChanged,
|
||||
(state: VoiceBroadcastInfoState, _recording: VoiceBroadcastRecording) => {
|
||||
setRecordingState(state);
|
||||
(state?: VoiceBroadcastRecordingState) => {
|
||||
return state ?? recording.getState();
|
||||
},
|
||||
);
|
||||
|
||||
const [timeLeft, setTimeLeft] = useState(recording.getTimeLeft());
|
||||
useTypedEventEmitter(recording, VoiceBroadcastRecordingEvent.TimeLeftChanged, setTimeLeft);
|
||||
const timeLeft = useTypedEventEmitterState(
|
||||
recording,
|
||||
VoiceBroadcastRecordingEvent.TimeLeftChanged,
|
||||
(t?: number) => {
|
||||
return t ?? recording.getTimeLeft();
|
||||
},
|
||||
);
|
||||
|
||||
const live = (
|
||||
[VoiceBroadcastInfoState.Started, VoiceBroadcastInfoState.Resumed] as VoiceBroadcastRecordingState[]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue