Improve types (#11239)

This commit is contained in:
Michael Telatynski 2023-07-12 15:56:51 +01:00 committed by GitHub
parent 44615b2b04
commit f1534fda79
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 35 additions and 42 deletions

View file

@ -31,7 +31,7 @@ interface IProps {
// XXX: It can take a cycle or two for the MessageActionBar to have all the props/setup
// required to get us a MediaEventHelper, so we use a getter function instead to prod for
// one.
mediaEventHelperGet: () => MediaEventHelper;
mediaEventHelperGet: () => MediaEventHelper | undefined;
}
interface IState {
@ -53,9 +53,10 @@ export default class DownloadActionButton extends React.PureComponent<IProps, IS
}
private onDownloadClick = async (): Promise<void> => {
if (this.state.loading) return;
const mediaEventHelper = this.props.mediaEventHelperGet();
if (this.state.loading || !mediaEventHelper) return;
if (this.props.mediaEventHelperGet().media.isEncrypted) {
if (mediaEventHelper.media.isEncrypted) {
this.setState({ tooltip: _td("Decrypting") });
}
@ -66,7 +67,7 @@ export default class DownloadActionButton extends React.PureComponent<IProps, IS
return this.doDownload(this.state.blob);
}
const blob = await this.props.mediaEventHelperGet().sourceBlob.value;
const blob = await mediaEventHelper.sourceBlob.value;
this.setState({ blob });
await this.doDownload(blob);
};
@ -74,7 +75,7 @@ export default class DownloadActionButton extends React.PureComponent<IProps, IS
private async doDownload(blob: Blob): Promise<void> {
await this.downloader.download({
blob,
name: this.props.mediaEventHelperGet().fileName,
name: this.props.mediaEventHelperGet()!.fileName,
});
this.setState({ loading: false });
}