@@ -133,13 +133,13 @@ export default class ImageView extends React.Component<IProps, IState> {
133133 // We want to recalculate zoom whenever the window's size changes
134134 window . addEventListener ( "resize" , this . recalculateZoom ) ;
135135 // After the image loads for the first time we want to calculate the zoom
136- this . image . current . addEventListener ( "load" , this . imageLoaded ) ;
136+ this . image . current ? .addEventListener ( "load" , this . imageLoaded ) ;
137137 }
138138
139139 public componentWillUnmount ( ) : void {
140140 this . focusLock . current . removeEventListener ( "wheel" , this . onWheel ) ;
141141 window . removeEventListener ( "resize" , this . recalculateZoom ) ;
142- this . image . current . removeEventListener ( "load" , this . imageLoaded ) ;
142+ this . image . current ? .removeEventListener ( "load" , this . imageLoaded ) ;
143143 }
144144
145145 private imageLoaded = ( ) : void => {
@@ -171,6 +171,7 @@ export default class ImageView extends React.Component<IProps, IState> {
171171 private setZoomAndRotation = ( inputRotation ?: number ) : void => {
172172 const image = this . image . current ;
173173 const imageWrapper = this . imageWrapper . current ;
174+ if ( ! image || ! imageWrapper ) return ;
174175
175176 const rotation = inputRotation ?? this . state . rotation ;
176177
@@ -236,8 +237,8 @@ export default class ImageView extends React.Component<IProps, IState> {
236237 // Zoom relative to the given point on the image.
237238 // First we need to figure out the offset of the anchor point
238239 // relative to the center of the image, accounting for rotation.
239- let offsetX ;
240- let offsetY ;
240+ let offsetX : number | undefined ;
241+ let offsetY : number | undefined ;
241242 // The modulo operator can return negative values for some
242243 // rotations, so we have to do some extra work to normalize it
243244 switch ( ( ( this . state . rotation % 360 ) + 360 ) % 360 ) {
@@ -310,7 +311,7 @@ export default class ImageView extends React.Component<IProps, IState> {
310311 private onDownloadClick = ( ) : void => {
311312 const a = document . createElement ( "a" ) ;
312313 a . href = this . props . src ;
313- a . download = this . props . name ;
314+ if ( this . props . name ) a . download = this . props . name ;
314315 a . target = "_blank" ;
315316 a . rel = "noreferrer noopener" ;
316317 a . click ( ) ;
@@ -334,9 +335,9 @@ export default class ImageView extends React.Component<IProps, IState> {
334335 ev . preventDefault ( ) ;
335336 dis . dispatch < ViewRoomPayload > ( {
336337 action : Action . ViewRoom ,
337- event_id : this . props . mxEvent . getId ( ) ,
338+ event_id : this . props . mxEvent ? .getId ( ) ,
338339 highlighted : true ,
339- room_id : this . props . mxEvent . getRoomId ( ) ,
340+ room_id : this . props . mxEvent ? .getRoomId ( ) ,
340341 metricsTrigger : undefined , // room doesn't change
341342 } ) ;
342343 this . props . onFinished ( ) ;
@@ -440,11 +441,11 @@ export default class ImageView extends React.Component<IProps, IState> {
440441
441442 let info : JSX . Element | undefined ;
442443 if ( showEventMeta ) {
443- const mxEvent = this . props . mxEvent ;
444+ const mxEvent = this . props . mxEvent ! ;
444445 const showTwelveHour = SettingsStore . getValue ( "showTwelveHourTimestamps" ) ;
445446 let permalink = "#" ;
446447 if ( this . props . permalinkCreator ) {
447- permalink = this . props . permalinkCreator . forEvent ( this . props . mxEvent . getId ( ) ) ;
448+ permalink = this . props . permalinkCreator . forEvent ( mxEvent . getId ( ) ) ;
448449 }
449450
450451 const senderName = mxEvent . sender ?. name ?? mxEvent . getSender ( ) ;
@@ -453,7 +454,7 @@ export default class ImageView extends React.Component<IProps, IState> {
453454 < a
454455 href = { permalink }
455456 onClick = { this . onPermalinkClicked }
456- aria-label = { formatFullDate ( new Date ( this . props . mxEvent . getTs ( ) ) , showTwelveHour , false ) }
457+ aria-label = { formatFullDate ( new Date ( mxEvent . getTs ( ) ) , showTwelveHour , false ) }
457458 >
458459 < MessageTimestamp
459460 showFullDate = { true }
0 commit comments