@@ -15,7 +15,16 @@ limitations under the License.
15
15
*/
16
16
17
17
import React , { ReactNode } from "react" ;
18
- import { EventStatus , MatrixEvent , Room , MatrixError , SyncState , SyncStateData } from "matrix-js-sdk/src/matrix" ;
18
+ import {
19
+ ClientEvent ,
20
+ EventStatus ,
21
+ MatrixError ,
22
+ MatrixEvent ,
23
+ Room ,
24
+ RoomEvent ,
25
+ SyncState ,
26
+ SyncStateData ,
27
+ } from "matrix-js-sdk/src/matrix" ;
19
28
20
29
import { Icon as WarningIcon } from "../../../res/img/feather-customised/warning-triangle.svg" ;
21
30
import { _t , _td } from "../../languageHandler" ;
@@ -79,18 +88,20 @@ interface IProps {
79
88
}
80
89
81
90
interface IState {
82
- syncState : SyncState ;
83
- syncStateData : SyncStateData ;
91
+ syncState : SyncState | null ;
92
+ syncStateData : SyncStateData | null ;
84
93
unsentMessages : MatrixEvent [ ] ;
85
94
isResending : boolean ;
86
95
}
87
96
88
97
export default class RoomStatusBar extends React . PureComponent < IProps , IState > {
89
98
private unmounted = false ;
90
99
public static contextType = MatrixClientContext ;
100
+ public context ! : React . ContextType < typeof MatrixClientContext > ;
91
101
92
- public constructor ( props : IProps , context : typeof MatrixClientContext ) {
102
+ public constructor ( props : IProps , context : React . ContextType < typeof MatrixClientContext > ) {
93
103
super ( props , context ) ;
104
+ this . context = context ; // XXX: workaround for lack of `declare` support on `public context!:` definition
94
105
95
106
this . state = {
96
107
syncState : this . context . getSyncState ( ) ,
@@ -102,8 +113,8 @@ export default class RoomStatusBar extends React.PureComponent<IProps, IState> {
102
113
103
114
public componentDidMount ( ) : void {
104
115
const client = this . context ;
105
- client . on ( "sync" , this . onSyncStateChange ) ;
106
- client . on ( "Room.localEchoUpdated" , this . onRoomLocalEchoUpdated ) ;
116
+ client . on ( ClientEvent . Sync , this . onSyncStateChange ) ;
117
+ client . on ( RoomEvent . LocalEchoUpdated , this . onRoomLocalEchoUpdated ) ;
107
118
108
119
this . checkSize ( ) ;
109
120
}
@@ -117,19 +128,19 @@ export default class RoomStatusBar extends React.PureComponent<IProps, IState> {
117
128
// we may have entirely lost our client as we're logging out before clicking login on the guest bar...
118
129
const client = this . context ;
119
130
if ( client ) {
120
- client . removeListener ( "sync" , this . onSyncStateChange ) ;
121
- client . removeListener ( "Room.localEchoUpdated" , this . onRoomLocalEchoUpdated ) ;
131
+ client . removeListener ( ClientEvent . Sync , this . onSyncStateChange ) ;
132
+ client . removeListener ( RoomEvent . LocalEchoUpdated , this . onRoomLocalEchoUpdated ) ;
122
133
}
123
134
}
124
135
125
- private onSyncStateChange = ( state : SyncState , prevState : SyncState , data : SyncStateData ) : void => {
136
+ private onSyncStateChange = ( state : SyncState , prevState : SyncState | null , data ? : SyncStateData ) : void => {
126
137
if ( state === "SYNCING" && prevState === "SYNCING" ) {
127
138
return ;
128
139
}
129
140
if ( this . unmounted ) return ;
130
141
this . setState ( {
131
142
syncState : state ,
132
- syncStateData : data ,
143
+ syncStateData : data ?? null ,
133
144
} ) ;
134
145
} ;
135
146
0 commit comments