More specific type definition and adhering to code style better

This commit is contained in:
Germain Souquet 2021-06-18 12:44:15 +01:00
parent 3f1ca970d6
commit d22617c422
13 changed files with 66 additions and 72 deletions

View file

@ -59,7 +59,7 @@ import IconizedContextMenu, {
} from "../views/context_menus/IconizedContextMenu";
import AccessibleTooltipButton from "../views/elements/AccessibleTooltipButton";
import {BetaPill} from "../views/beta/BetaCard";
import { USER_TAB } from "../views/dialogs/UserSettingsDialog";
import { UserTab } from "../views/dialogs/UserSettingsDialog";
import SettingsStore from "../../settings/SettingsStore";
import dis from "../../dispatcher/dispatcher";
import Modal from "../../Modal";
@ -166,7 +166,7 @@ const SpaceInfo = ({ space }) => {
const onBetaClick = () => {
defaultDispatcher.dispatch({
action: Action.ViewUserSettings,
initialTabId: USER_TAB.LABS,
initialTabId: UserTab.Labs,
});
};

View file

@ -26,7 +26,7 @@ import { ActionPayload } from "../../dispatcher/payloads";
import { Action } from "../../dispatcher/actions";
import { _t } from "../../languageHandler";
import { ContextMenuButton } from "./ContextMenu";
import { USER_TAB } from "../views/dialogs/UserSettingsDialog";
import { UserTab } from "../views/dialogs/UserSettingsDialog";
import { OpenToTabPayload } from "../../dispatcher/payloads/OpenToTabPayload";
import FeedbackDialog from "../views/dialogs/FeedbackDialog";
import Modal from "../../Modal";
@ -408,12 +408,12 @@ export default class UserMenu extends React.Component<IProps, IState> {
<IconizedContextMenuOption
iconClassName="mx_UserMenu_iconBell"
label={_t("Notification settings")}
onClick={(e) => this.onSettingsOpen(e, USER_TAB.NOTIFICATIONS)}
onClick={(e) => this.onSettingsOpen(e, UserTab.Notifications)}
/>
<IconizedContextMenuOption
iconClassName="mx_UserMenu_iconLock"
label={_t("Security & privacy")}
onClick={(e) => this.onSettingsOpen(e, USER_TAB.SECURITY)}
onClick={(e) => this.onSettingsOpen(e, UserTab.Security)}
/>
<IconizedContextMenuOption
iconClassName="mx_UserMenu_iconSettings"

View file

@ -269,7 +269,7 @@ export default class Registration extends React.Component<IProps, IState> {
);
}
private onUIAuthFinished = async (success, response) => {
private onUIAuthFinished = async (success: boolean, response: any) => {
if (!success) {
let msg = response.message || response.toString();
// can we give a better error message?

View file

@ -29,7 +29,7 @@ import InfoDialog from "./InfoDialog";
import AccessibleButton from "../elements/AccessibleButton";
import defaultDispatcher from "../../../dispatcher/dispatcher";
import {Action} from "../../../dispatcher/actions";
import { USER_TAB } from "./UserSettingsDialog";
import { UserTab } from "./UserSettingsDialog";
interface IProps extends IDialogProps {
featureId: string;
@ -70,7 +70,7 @@ const BetaFeedbackDialog: React.FC<IProps> = ({featureId, onFinished}) => {
onFinished(false);
defaultDispatcher.dispatch({
action: Action.ViewUserSettings,
initialTabId: USER_TAB.LABS,
initialTabId: UserTab.Labs,
});
}}>
{ _t("To leave the beta, visit your settings.") }

View file

@ -58,12 +58,6 @@ export default class ConfirmUserActionDialog extends React.Component<IProps> {
askReason: false,
};
constructor(props) {
super(props);
this.reasonField = null;
}
public onOk = (): void => {
let reason;
if (this.reasonField) {

View file

@ -115,7 +115,7 @@ export default class DeactivateAccountDialog extends React.Component<IProps, ISt
this.setState({errStr: _t("There was a problem communicating with the server. Please try again.")});
};
private onUIAuthComplete = (auth): void => {
private onUIAuthComplete = (auth: any): void => {
MatrixClientPeg.get().deactivateAccount(auth, this.state.shouldErase).then(r => {
// Deactivation worked - logout & close this dialog
Analytics.trackEvent('Account', 'Deactivate Account');

View file

@ -19,7 +19,7 @@ import React from 'react';
import TabbedView, {Tab} from "../../structures/TabbedView";
import {_t, _td} from "../../../languageHandler";
import GeneralUserSettingsTab from "../settings/tabs/user/GeneralUserSettingsTab";
import SettingsStore from "../../../settings/SettingsStore";
import SettingsStore, { CallbackFn } from "../../../settings/SettingsStore";
import LabsUserSettingsTab from "../settings/tabs/user/LabsUserSettingsTab";
import AppearanceUserSettingsTab from "../settings/tabs/user/AppearanceUserSettingsTab";
import SecurityUserSettingsTab from "../settings/tabs/user/SecurityUserSettingsTab";
@ -34,17 +34,17 @@ import MjolnirUserSettingsTab from "../settings/tabs/user/MjolnirUserSettingsTab
import {UIFeature} from "../../../settings/UIFeature";
import {replaceableComponent} from "../../../utils/replaceableComponent";
export enum USER_TAB {
GENERAL = "USER_GENERAL_TAB",
APPEARANCE = "USER_APPEARANCE_TAB",
FLAIR = "USER_FLAIR_TAB",
NOTIFICATIONS = "USER_NOTIFICATIONS_TAB",
PREFERENCES = "USER_PREFERENCES_TAB",
VOICE = "USER_VOICE_TAB",
SECURITY = "USER_SECURITY_TAB",
LABS = "USER_LABS_TAB",
MJOLNIR = "USER_MJOLNIR_TAB",
HELP = "USER_HELP_TAB",
export enum UserTab {
General = "USER_GENERAL_TAB",
Appearance = "USER_APPEARANCE_TAB",
Flair = "USER_FLAIR_TAB",
Notifications = "USER_NOTIFICATIONS_TAB",
Preferences = "USER_PREFERENCES_TAB",
Voice = "USER_VOICE_TAB",
Security = "USER_SECURITY_TAB",
Labs = "USER_LABS_TAB",
Mjolnir = "USER_MJOLNIR_TAB",
Help = "USER_HELP_TAB",
}
interface IProps {
@ -76,7 +76,7 @@ export default class UserSettingsDialog extends React.Component<IProps, IState>
SettingsStore.unwatchSetting(this.mjolnirWatcher);
}
private mjolnirChanged = (settingName, roomId, atLevel, newValue: boolean) => {
private mjolnirChanged: CallbackFn = (settingName, roomId, atLevel, newValue) => {
// We can cheat because we know what levels a feature is tracked at, and how it is tracked
this.setState({mjolnirEnabled: newValue});
}
@ -85,33 +85,33 @@ export default class UserSettingsDialog extends React.Component<IProps, IState>
const tabs = [];
tabs.push(new Tab(
USER_TAB.GENERAL,
UserTab.General,
_td("General"),
"mx_UserSettingsDialog_settingsIcon",
<GeneralUserSettingsTab closeSettingsFn={this.props.onFinished} />,
));
tabs.push(new Tab(
USER_TAB.APPEARANCE,
UserTab.Appearance,
_td("Appearance"),
"mx_UserSettingsDialog_appearanceIcon",
<AppearanceUserSettingsTab />,
));
if (SettingsStore.getValue(UIFeature.Flair)) {
tabs.push(new Tab(
USER_TAB.FLAIR,
UserTab.Flair,
_td("Flair"),
"mx_UserSettingsDialog_flairIcon",
<FlairUserSettingsTab />,
));
}
tabs.push(new Tab(
USER_TAB.NOTIFICATIONS,
UserTab.Notifications,
_td("Notifications"),
"mx_UserSettingsDialog_bellIcon",
<NotificationUserSettingsTab />,
));
tabs.push(new Tab(
USER_TAB.PREFERENCES,
UserTab.Preferences,
_td("Preferences"),
"mx_UserSettingsDialog_preferencesIcon",
<PreferencesUserSettingsTab />,
@ -119,7 +119,7 @@ export default class UserSettingsDialog extends React.Component<IProps, IState>
if (SettingsStore.getValue(UIFeature.Voip)) {
tabs.push(new Tab(
USER_TAB.VOICE,
UserTab.Voice,
_td("Voice & Video"),
"mx_UserSettingsDialog_voiceIcon",
<VoiceUserSettingsTab />,
@ -127,7 +127,7 @@ export default class UserSettingsDialog extends React.Component<IProps, IState>
}
tabs.push(new Tab(
USER_TAB.SECURITY,
UserTab.Security,
_td("Security & Privacy"),
"mx_UserSettingsDialog_securityIcon",
<SecurityUserSettingsTab closeSettingsFn={this.props.onFinished} />,
@ -137,7 +137,7 @@ export default class UserSettingsDialog extends React.Component<IProps, IState>
|| SettingsStore.getFeatureSettingNames().some(k => SettingsStore.getBetaInfo(k))
) {
tabs.push(new Tab(
USER_TAB.LABS,
UserTab.Labs,
_td("Labs"),
"mx_UserSettingsDialog_labsIcon",
<LabsUserSettingsTab />,
@ -145,14 +145,14 @@ export default class UserSettingsDialog extends React.Component<IProps, IState>
}
if (this.state.mjolnirEnabled) {
tabs.push(new Tab(
USER_TAB.MJOLNIR,
UserTab.Mjolnir,
_td("Ignored users"),
"mx_UserSettingsDialog_mjolnirIcon",
<MjolnirUserSettingsTab />,
));
}
tabs.push(new Tab(
USER_TAB.HELP,
UserTab.Help,
_td("Help & About"),
"mx_UserSettingsDialog_helpIcon",
<HelpUserSettingsTab closeSettingsFn={() => this.props.onFinished(true)} />,

View file

@ -34,7 +34,7 @@ interface IProps {
interface IState {
error: Error | null;
canUploadKeysWithPasswordOnly: boolean | null;
canUploadKeysWithPasswordOnly?: boolean;
accountPassword: string;
}
@ -45,7 +45,7 @@ interface IState {
*/
@replaceableComponent("views.dialogs.security.CreateCrossSigningDialog")
export default class CreateCrossSigningDialog extends React.PureComponent<IProps, IState> {
constructor(props) {
constructor(props: IProps) {
super(props);
this.state = {
@ -90,7 +90,7 @@ export default class CreateCrossSigningDialog extends React.PureComponent<IProps
}
}
private doBootstrapUIAuth = async (makeRequest): Promise<void> => {
private doBootstrapUIAuth = async (makeRequest: (authData: any) => void): Promise<void> => {
if (this.state.canUploadKeysWithPasswordOnly && this.state.accountPassword) {
await makeRequest({
type: 'm.login.password',

View file

@ -18,11 +18,11 @@ import React from 'react';
import SetupEncryptionBody from '../../../structures/auth/SetupEncryptionBody';
import BaseDialog from '../BaseDialog';
import { _t } from '../../../../languageHandler';
import { SetupEncryptionStore, PHASE } from '../../../../stores/SetupEncryptionStore';
import { SetupEncryptionStore, Phase } from '../../../../stores/SetupEncryptionStore';
import {replaceableComponent} from "../../../../utils/replaceableComponent";
function iconFromPhase(phase: PHASE) {
if (phase === PHASE.DONE) {
function iconFromPhase(phase: Phase) {
if (phase === Phase.Done) {
return require("../../../../../res/img/e2e/verified.svg");
} else {
return require("../../../../../res/img/e2e/warning.svg");
@ -34,14 +34,14 @@ interface IProps {
}
interface IState {
icon: PHASE;
icon: Phase;
}
@replaceableComponent("views.dialogs.security.SetupEncryptionDialog")
export default class SetupEncryptionDialog extends React.Component<IProps, IState> {
private store: SetupEncryptionStore;
constructor(props) {
constructor(props: IProps) {
super(props);
this.store = SetupEncryptionStore.sharedInstance();

View file

@ -48,7 +48,7 @@ import EncryptionPanel from "./EncryptionPanel";
import { useAsyncMemo } from '../../../hooks/useAsyncMemo';
import { legacyVerifyUser, verifyDevice, verifyUser } from '../../../verification';
import { Action } from "../../../dispatcher/actions";
import { USER_TAB } from "../dialogs/UserSettingsDialog";
import { UserTab } from "../dialogs/UserSettingsDialog";
import { useIsEncrypted } from "../../../hooks/useIsEncrypted";
import BaseCard from "./BaseCard";
import { E2EStatus } from "../../../utils/ShieldUtils";
@ -1381,7 +1381,7 @@ const BasicUserInfo: React.FC<{
<AccessibleButton className="mx_UserInfo_field" onClick={() => {
dis.dispatch({
action: Action.ViewUserSettings,
initialTabId: USER_TAB.SECURITY,
initialTabId: UserTab.Security,
});
}}>
{ _t("Edit devices") }

View file

@ -29,7 +29,7 @@ import AccessibleButton from "../elements/AccessibleButton";
import {BetaPill} from "../beta/BetaCard";
import defaultDispatcher from "../../../dispatcher/dispatcher";
import {Action} from "../../../dispatcher/actions";
import { USER_TAB } from "../dialogs/UserSettingsDialog";
import { UserTab } from "../dialogs/UserSettingsDialog";
import Field from "../elements/Field";
import withValidation from "../elements/Validation";
import {SpaceFeedbackPrompt} from "../../structures/SpaceRoomView";
@ -224,7 +224,7 @@ const SpaceCreateMenu = ({ onFinished }) => {
onFinished();
defaultDispatcher.dispatch({
action: Action.ViewUserSettings,
initialTabId: USER_TAB.LABS,
initialTabId: UserTab.Labs,
});
}} />
{ body }

View file

@ -22,18 +22,18 @@ import { MatrixClientPeg } from '../MatrixClientPeg';
import { accessSecretStorage, AccessCancelledError } from '../SecurityManager';
import { PHASE_DONE as VERIF_PHASE_DONE } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
export enum PHASE {
LOADING = 0,
INTRO = 1,
BUSY = 2,
DONE = 3, // final done stage, but still showing UX
CONFIRM_SKIP = 4,
FINISHED = 5, // UX can be closed
export enum Phase {
Loading = 0,
Intro = 1,
Busy = 2,
Done = 3, // final done stage, but still showing UX
ConfirmSkip = 4,
Finished = 5, // UX can be closed
}
export class SetupEncryptionStore extends EventEmitter {
private started: boolean;
public phase: PHASE;
public phase: Phase;
public verificationRequest: VerificationRequest;
public backupInfo: IKeyBackupVersion;
public keyId: string;
@ -50,7 +50,7 @@ export class SetupEncryptionStore extends EventEmitter {
return;
}
this.started = true;
this.phase = PHASE.LOADING;
this.phase = Phase.Loading;
this.verificationRequest = null;
this.backupInfo = null;
@ -110,15 +110,15 @@ export class SetupEncryptionStore extends EventEmitter {
if (!this.hasDevicesToVerifyAgainst && !this.keyInfo) {
// skip before we can even render anything.
this.phase = PHASE.FINISHED;
this.phase = Phase.Finished;
} else {
this.phase = PHASE.INTRO;
this.phase = Phase.Intro;
}
this.emit("update");
}
public async usePassPhrase(): Promise<void> {
this.phase = PHASE.BUSY;
this.phase = Phase.Busy;
this.emit("update");
const cli = MatrixClientPeg.get();
try {
@ -147,7 +147,7 @@ export class SetupEncryptionStore extends EventEmitter {
});
if (cli.getCrossSigningId()) {
this.phase = PHASE.DONE;
this.phase = Phase.Done;
this.emit("update");
}
} catch (e) {
@ -155,7 +155,7 @@ export class SetupEncryptionStore extends EventEmitter {
console.log(e);
}
// this will throw if the user hits cancel, so ignore
this.phase = PHASE.INTRO;
this.phase = Phase.Intro;
this.emit("update");
}
}
@ -164,7 +164,7 @@ export class SetupEncryptionStore extends EventEmitter {
if (userId !== MatrixClientPeg.get().getUserId()) return;
const publicKeysTrusted = MatrixClientPeg.get().getCrossSigningId();
if (publicKeysTrusted) {
this.phase = PHASE.DONE;
this.phase = Phase.Done;
this.emit("update");
}
}
@ -185,28 +185,28 @@ export class SetupEncryptionStore extends EventEmitter {
// cross signing to be ready to use, so wait for the user trust status to
// change (or change to DONE if it's already ready).
const publicKeysTrusted = MatrixClientPeg.get().getCrossSigningId();
this.phase = publicKeysTrusted ? PHASE.DONE : PHASE.BUSY;
this.phase = publicKeysTrusted ? Phase.Done : Phase.Busy;
this.emit("update");
}
}
public skip(): void {
this.phase = PHASE.CONFIRM_SKIP;
this.phase = Phase.ConfirmSkip;
this.emit("update");
}
public skipConfirm(): void {
this.phase = PHASE.FINISHED;
this.phase = Phase.Finished;
this.emit("update");
}
public returnAfterSkip(): void {
this.phase = PHASE.INTRO;
this.phase = Phase.Intro;
this.emit("update");
}
public done(): void {
this.phase = PHASE.FINISHED;
this.phase = Phase.Finished;
this.emit("update");
// async - ask other clients for keys, if necessary
MatrixClientPeg.get().crypto.cancelAndResendAllOutgoingKeyRequests();

View file

@ -21,7 +21,7 @@ import DeviceListener from '../DeviceListener';
import ToastStore from "../stores/ToastStore";
import GenericToast from "../components/views/toasts/GenericToast";
import { Action } from "../dispatcher/actions";
import { USER_TAB } from "../components/views/dialogs/UserSettingsDialog";
import { UserTab } from "../components/views/dialogs/UserSettingsDialog";
function toastKey(deviceId: string) {
return "unverified_session_" + deviceId;
@ -34,7 +34,7 @@ export const showToast = async (deviceId: string) => {
DeviceListener.sharedInstance().dismissUnverifiedSessions([deviceId]);
dis.dispatch({
action: Action.ViewUserSettings,
initialTabId: USER_TAB.SECURITY,
initialTabId: UserTab.Security,
});
};