Improve typing

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
Šimon Brandner 2021-07-20 12:16:17 +02:00
parent 93ab4dc787
commit 48949af961
No known key found for this signature in database
GPG key ID: 55C211A1226CB17D
3 changed files with 18 additions and 17 deletions

View file

@ -24,7 +24,7 @@ import { _t, _td } from '../../../languageHandler';
import * as sdk from '../../../index'; import * as sdk from '../../../index';
import { MatrixClientPeg } from '../../../MatrixClientPeg'; import { MatrixClientPeg } from '../../../MatrixClientPeg';
import dis from '../../../dispatcher/dispatcher'; import dis from '../../../dispatcher/dispatcher';
import { addressTypes, getAddressType } from '../../../UserAddress'; import { AddressType, addressTypes, getAddressType, IUserAddress } from '../../../UserAddress';
import GroupStore from '../../../stores/GroupStore'; import GroupStore from '../../../stores/GroupStore';
import * as Email from '../../../email'; import * as Email from '../../../email';
import IdentityAuthClient from '../../../IdentityAuthClient'; import IdentityAuthClient from '../../../IdentityAuthClient';
@ -54,8 +54,8 @@ interface IProps {
roomId?: string; roomId?: string;
button?: string; button?: string;
focus?: boolean; focus?: boolean;
validAddressTypes?; // FIXME: UserAddressType should be an interface validAddressTypes?: AddressType[];
onFinished: (success: boolean, list?) => void; // FIXME: UserAddressType should be an interface onFinished: (success: boolean, list?: IUserAddress[]) => void;
groupId?: string; groupId?: string;
// The type of entity to search for. Default: 'user'. // The type of entity to search for. Default: 'user'.
pickerType?: 'user' | 'room'; pickerType?: 'user' | 'room';
@ -69,7 +69,7 @@ interface IState {
invalidAddressError: boolean; invalidAddressError: boolean;
// List of UserAddressType objects representing // List of UserAddressType objects representing
// the list of addresses we're going to invite // the list of addresses we're going to invite
selectedList; // FIXME: UserAddressType should be an interface selectedList: IUserAddress[];
// Whether a search is ongoing // Whether a search is ongoing
busy: boolean; busy: boolean;
// An error message generated during the user directory search // An error message generated during the user directory search
@ -80,10 +80,10 @@ interface IState {
query: string; query: string;
// List of UserAddressType objects representing the set of // List of UserAddressType objects representing the set of
// auto-completion results for the current search query. // auto-completion results for the current search query.
suggestedList; // FIXME: UserAddressType should be an interface suggestedList: IUserAddress[];
// List of address types initialised from props, but may change while the // List of address types initialised from props, but may change while the
// dialog is open and represents the supported list of address types at this time. // dialog is open and represents the supported list of address types at this time.
validAddressTypes; validAddressTypes: AddressType[];
} }
@replaceableComponent("views.dialogs.AddressPickerDialog") @replaceableComponent("views.dialogs.AddressPickerDialog")
@ -106,8 +106,8 @@ export default class AddressPickerDialog extends React.Component<IProps, IState>
let validAddressTypes = this.props.validAddressTypes; let validAddressTypes = this.props.validAddressTypes;
// Remove email from validAddressTypes if no IS is configured. It may be added at a later stage by the user // Remove email from validAddressTypes if no IS is configured. It may be added at a later stage by the user
if (!MatrixClientPeg.get().getIdentityServerUrl() && validAddressTypes.includes("email")) { if (!MatrixClientPeg.get().getIdentityServerUrl() && validAddressTypes.includes(AddressType.Email)) {
validAddressTypes = validAddressTypes.filter(type => type !== "email"); validAddressTypes = validAddressTypes.filter(type => type !== AddressType.Email);
} }
this.state = { this.state = {
@ -488,14 +488,14 @@ export default class AddressPickerDialog extends React.Component<IProps, IState>
}); });
} }
private addAddressesToList(addressTexts): void { private addAddressesToList(addressTexts): IUserAddress[] {
const selectedList = this.state.selectedList.slice(); const selectedList = this.state.selectedList.slice();
let hasError = false; let hasError = false;
addressTexts.forEach((addressText) => { addressTexts.forEach((addressText) => {
addressText = addressText.trim(); addressText = addressText.trim();
const addrType = getAddressType(addressText); const addrType = getAddressType(addressText);
const addrObj = { const addrObj: IUserAddress = {
addressType: addrType, addressType: addrType,
address: addressText, address: addressText,
isKnown: false, isKnown: false,
@ -514,7 +514,6 @@ export default class AddressPickerDialog extends React.Component<IProps, IState>
const room = MatrixClientPeg.get().getRoom(addrObj.address); const room = MatrixClientPeg.get().getRoom(addrObj.address);
if (room) { if (room) {
addrObj.displayName = room.name; addrObj.displayName = room.name;
addrObj.avatarMxc = room.avatarUrl;
addrObj.isKnown = true; addrObj.isKnown = true;
} }
} }
@ -580,7 +579,7 @@ export default class AddressPickerDialog extends React.Component<IProps, IState>
} }
} }
private getFilteredSuggestions() { // FIXME: UserAddressType should be an interface private getFilteredSuggestions(): IUserAddress[] {
// map addressType => set of addresses to avoid O(n*m) operation // map addressType => set of addresses to avoid O(n*m) operation
const selectedAddresses = {}; const selectedAddresses = {};
this.state.selectedList.forEach(({ address, addressType }) => { this.state.selectedList.forEach(({ address, addressType }) => {
@ -611,7 +610,7 @@ export default class AddressPickerDialog extends React.Component<IProps, IState>
// Add email as a valid address type. // Add email as a valid address type.
const { validAddressTypes } = this.state; const { validAddressTypes } = this.state;
validAddressTypes.push('email'); validAddressTypes.push(AddressType.Email);
this.setState({ validAddressTypes }); this.setState({ validAddressTypes });
}; };
@ -695,8 +694,8 @@ export default class AddressPickerDialog extends React.Component<IProps, IState>
let identityServer; let identityServer;
// If picker cannot currently accept e-mail but should be able to // If picker cannot currently accept e-mail but should be able to
if (this.props.pickerType === 'user' && !this.state.validAddressTypes.includes('email') if (this.props.pickerType === 'user' && !this.state.validAddressTypes.includes(AddressType.Email)
&& this.props.validAddressTypes.includes('email')) { && this.props.validAddressTypes.includes(AddressType.Email)) {
const defaultIdentityServerUrl = getDefaultIdentityServerUrl(); const defaultIdentityServerUrl = getDefaultIdentityServerUrl();
if (defaultIdentityServerUrl) { if (defaultIdentityServerUrl) {
identityServer = <div className="mx_AddressPickerDialog_identityServer">{ _t( identityServer = <div className="mx_AddressPickerDialog_identityServer">{ _t(

View file

@ -19,12 +19,13 @@ import React, { createRef } from 'react';
import * as sdk from '../../../index'; import * as sdk from '../../../index';
import classNames from 'classnames'; import classNames from 'classnames';
import { replaceableComponent } from "../../../utils/replaceableComponent"; import { replaceableComponent } from "../../../utils/replaceableComponent";
import { IUserAddress } from '../../../UserAddress';
interface IProps { interface IProps {
onSelected: (index: number) => void; onSelected: (index: number) => void;
// List of the addresses to display // List of the addresses to display
addressList; // FIXME: UserAddressType should be an interface addressList: IUserAddress[];
// Whether to show the address on the address tiles // Whether to show the address on the address tiles
showAddress?: boolean; showAddress?: boolean;
truncateAt: number; truncateAt: number;

View file

@ -21,9 +21,10 @@ import * as sdk from "../../../index";
import { _t } from '../../../languageHandler'; import { _t } from '../../../languageHandler';
import { replaceableComponent } from "../../../utils/replaceableComponent"; import { replaceableComponent } from "../../../utils/replaceableComponent";
import { mediaFromMxc } from "../../../customisations/Media"; import { mediaFromMxc } from "../../../customisations/Media";
import { IUserAddress } from '../../../UserAddress';
interface IProps { interface IProps {
address; // FIXME: UserAddressType should be an interface address: IUserAddress;
canDismiss?: boolean; canDismiss?: boolean;
onDismissed?: () => void; onDismissed?: () => void;
justified?: boolean; justified?: boolean;