From 209c35013232f3e430d3fa45d7b163179dfe9e2e Mon Sep 17 00:00:00 2001
From: Michael Telatynski <7t3chguy@gmail.com>
Date: Mon, 13 Jul 2020 00:19:15 +0100
Subject: [PATCH] Fix typing
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
---
src/ContentMessages.tsx | 12 ++++++------
src/Modal.tsx | 40 ++++++++++++++++++++++++----------------
src/SlashCommands.tsx | 12 +++++++-----
3 files changed, 37 insertions(+), 27 deletions(-)
diff --git a/src/ContentMessages.tsx b/src/ContentMessages.tsx
index 25445b1c74..afb3081448 100644
--- a/src/ContentMessages.tsx
+++ b/src/ContentMessages.tsx
@@ -386,7 +386,7 @@ export default class ContentMessages {
const isQuoting = Boolean(RoomViewStore.getQuotingEvent());
if (isQuoting) {
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
- const {finished} = Modal.createTrackedDialog('Upload Reply Warning', '', QuestionDialog, {
+ const {finished} = Modal.createTrackedDialog<[boolean]>('Upload Reply Warning', '', QuestionDialog, {
title: _t('Replying With Files'),
description: (
{_t(
@@ -397,7 +397,7 @@ export default class ContentMessages {
hasCancelButton: true,
button: _t("Continue"),
});
- const [shouldUpload]: [boolean] = await finished;
+ const [shouldUpload] = await finished;
if (!shouldUpload) return;
}
@@ -420,12 +420,12 @@ export default class ContentMessages {
if (tooBigFiles.length > 0) {
const UploadFailureDialog = sdk.getComponent("dialogs.UploadFailureDialog");
- const {finished} = Modal.createTrackedDialog('Upload Failure', '', UploadFailureDialog, {
+ const {finished} = Modal.createTrackedDialog<[boolean]>('Upload Failure', '', UploadFailureDialog, {
badFiles: tooBigFiles,
totalFiles: files.length,
contentMessages: this,
});
- const [shouldContinue]: [boolean] = await finished;
+ const [shouldContinue] = await finished;
if (!shouldContinue) return;
}
@@ -437,12 +437,12 @@ export default class ContentMessages {
for (let i = 0; i < okFiles.length; ++i) {
const file = okFiles[i];
if (!uploadAll) {
- const {finished} = Modal.createTrackedDialog('Upload Files confirmation', '', UploadConfirmDialog, {
+ const {finished} = Modal.createTrackedDialog<[boolean, boolean]>('Upload Files confirmation', '', UploadConfirmDialog, {
file,
currentIndex: i,
totalFiles: okFiles.length,
});
- const [shouldContinue, shouldUploadAll]: [boolean, boolean] = await finished;
+ const [shouldContinue, shouldUploadAll] = await finished;
if (!shouldContinue) break;
if (shouldUploadAll) {
uploadAll = true;
diff --git a/src/Modal.tsx b/src/Modal.tsx
index 8e0bff03e7..b744dbacf4 100644
--- a/src/Modal.tsx
+++ b/src/Modal.tsx
@@ -44,7 +44,9 @@ interface IHandle
{
}
interface IProps {
- onFinished(...args: T): void;
+ onFinished?(...args: T): void;
+ // TODO improve typing here once all Modals are TS and we can exhaustively check the props
+ [key: string]: any;
}
interface IOptions {
@@ -95,48 +97,54 @@ export class ModalManager {
return this.priorityModal || this.staticModal || this.modals.length > 0;
}
- public createTrackedDialog(
+ public createTrackedDialog(
analyticsAction: string,
analyticsInfo: string,
...rest: Parameters
) {
Analytics.trackEvent('Modal', analyticsAction, analyticsInfo);
- return this.createDialog(...rest);
+ return this.createDialog(...rest);
}
- public appendTrackedDialog(
+ public appendTrackedDialog(
analyticsAction: string,
analyticsInfo: string,
...rest: Parameters
) {
Analytics.trackEvent('Modal', analyticsAction, analyticsInfo);
- return this.appendDialog(...rest);
+ return this.appendDialog(...rest);
}
- public createDialog(Element: React.ComponentType, ...rest: ParametersWithoutFirst) {
- return this.createDialogAsync(Promise.resolve(Element), ...rest);
+ public createDialog(
+ Element: React.ComponentType,
+ ...rest: ParametersWithoutFirst
+ ) {
+ return this.createDialogAsync(Promise.resolve(Element), ...rest);
}
- public appendDialog(Element: React.ComponentType, ...rest: ParametersWithoutFirst) {
- return this.appendDialogAsync(Promise.resolve(Element), ...rest);
+ public appendDialog(
+ Element: React.ComponentType,
+ ...rest: ParametersWithoutFirst
+ ) {
+ return this.appendDialogAsync(Promise.resolve(Element), ...rest);
}
- public createTrackedDialogAsync(
+ public createTrackedDialogAsync(
analyticsAction: string,
analyticsInfo: string,
...rest: Parameters
) {
Analytics.trackEvent('Modal', analyticsAction, analyticsInfo);
- return this.createDialogAsync(...rest);
+ return this.createDialogAsync(...rest);
}
- public appendTrackedDialogAsync(
+ public appendTrackedDialogAsync(
analyticsAction: string,
analyticsInfo: string,
...rest: Parameters
) {
Analytics.trackEvent('Modal', analyticsAction, analyticsInfo);
- return this.appendDialogAsync(...rest);
+ return this.appendDialogAsync(...rest);
}
private buildModal(
@@ -250,9 +258,9 @@ export class ModalManager {
* @param {onBeforeClose} options.onBeforeClose a callback to decide whether to close the dialog
* @returns {object} Object with 'close' parameter being a function that will close the dialog
*/
- private createDialogAsync(
- prom: Promise,
- props?: IProps & React.ComponentProps,
+ private createDialogAsync(
+ prom: Promise,
+ props?: IProps,
className?: string,
isPriorityModal = false,
isStaticModal = false,
diff --git a/src/SlashCommands.tsx b/src/SlashCommands.tsx
index f667c47b3c..f45c3b5471 100644
--- a/src/SlashCommands.tsx
+++ b/src/SlashCommands.tsx
@@ -400,14 +400,16 @@ export const Commands = [
// If we need an identity server but don't have one, things
// get a bit more complex here, but we try to show something
// meaningful.
- let finished = Promise.resolve();
+ let prom = Promise.resolve();
if (
getAddressType(address) === 'email' &&
!MatrixClientPeg.get().getIdentityServerUrl()
) {
const defaultIdentityServerUrl = getDefaultIdentityServerUrl();
if (defaultIdentityServerUrl) {
- ({ finished } = Modal.createTrackedDialog('Slash Commands', 'Identity server',
+ const { finished } = Modal.createTrackedDialog<[boolean]>(
+ 'Slash Commands',
+ 'Identity server',
QuestionDialog, {
title: _t("Use an identity server"),
description: {_t(
@@ -420,9 +422,9 @@ export const Commands = [
)}
,
button: _t("Continue"),
},
- ));
+ );
- finished = finished.then(([useDefault]: any) => {
+ prom = finished.then(([useDefault]) => {
if (useDefault) {
useDefaultIdentityServer();
return;
@@ -434,7 +436,7 @@ export const Commands = [
}
}
const inviter = new MultiInviter(roomId);
- return success(finished.then(() => {
+ return success(prom.then(() => {
return inviter.invite([address]);
}).then(() => {
if (inviter.getCompletionState(address) !== "invited") {