Improve types (#11239)
This commit is contained in:
parent
44615b2b04
commit
f1534fda79
12 changed files with 35 additions and 42 deletions
|
@ -345,12 +345,15 @@ export default class ForgotPassword extends React.Component<Props, State> {
|
|||
}
|
||||
};
|
||||
|
||||
private onInputChanged = (stateKey: string, ev: React.FormEvent<HTMLInputElement>): void => {
|
||||
private onInputChanged = (
|
||||
stateKey: "email" | "password" | "password2",
|
||||
ev: React.FormEvent<HTMLInputElement>,
|
||||
): void => {
|
||||
let value = ev.currentTarget.value;
|
||||
if (stateKey === "email") value = value.trim();
|
||||
this.setState({
|
||||
[stateKey]: value,
|
||||
} as any);
|
||||
} as Pick<State, typeof stateKey>);
|
||||
};
|
||||
|
||||
public renderEnterEmail(): JSX.Element {
|
||||
|
|
|
@ -29,7 +29,7 @@ interface EnterEmailProps {
|
|||
errorText: string | ReactNode | null;
|
||||
homeserver: string;
|
||||
loading: boolean;
|
||||
onInputChanged: (stateKey: string, ev: React.FormEvent<HTMLInputElement>) => void;
|
||||
onInputChanged: (stateKey: "email", ev: React.FormEvent<HTMLInputElement>) => void;
|
||||
onLoginClick: () => void;
|
||||
onSubmitForm: (ev: React.FormEvent) => void;
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ export default class DeactivateAccountDialog extends React.Component<IProps, ISt
|
|||
// but given that a deactivation is followed by a local logout and all object instances being thrown away
|
||||
// this isn't done.
|
||||
MatrixClientPeg.safeGet()
|
||||
.deactivateAccount(auth, this.state.shouldErase)
|
||||
.deactivateAccount(auth ?? undefined, this.state.shouldErase)
|
||||
.then((r) => {
|
||||
// Deactivation worked - logout & close this dialog
|
||||
defaultDispatcher.fire(Action.TriggerLogout);
|
||||
|
@ -163,7 +163,7 @@ export default class DeactivateAccountDialog extends React.Component<IProps, ISt
|
|||
|
||||
private initAuth(shouldErase: boolean): void {
|
||||
MatrixClientPeg.safeGet()
|
||||
.deactivateAccount(null, shouldErase)
|
||||
.deactivateAccount(undefined, shouldErase)
|
||||
.then((r) => {
|
||||
// If we got here, oops. The server didn't require any auth.
|
||||
// Our application lifecycle will catch the error and do the logout bits.
|
||||
|
|
|
@ -37,7 +37,7 @@ export const StateEventEditor: React.FC<IEditorProps> = ({ mxEvent, onBack }) =>
|
|||
[mxEvent],
|
||||
);
|
||||
|
||||
const onSend = async ([eventType, stateKey]: string[], content?: IContent): Promise<void> => {
|
||||
const onSend = async ([eventType, stateKey]: string[], content: IContent): Promise<void> => {
|
||||
await cli.sendStateEvent(context.room.roomId, eventType, content, stateKey);
|
||||
};
|
||||
|
||||
|
|
|
@ -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 });
|
||||
}
|
||||
|
|
|
@ -53,14 +53,13 @@ import { Key } from "../../../Keyboard";
|
|||
import { ALTERNATE_KEY_NAME } from "../../../accessibility/KeyboardShortcuts";
|
||||
import { Action } from "../../../dispatcher/actions";
|
||||
import { ShowThreadPayload } from "../../../dispatcher/payloads/ShowThreadPayload";
|
||||
import { GetRelationsForEvent } from "../rooms/EventTile";
|
||||
import { GetRelationsForEvent, IEventTileType } from "../rooms/EventTile";
|
||||
import { VoiceBroadcastInfoEventType } from "../../../voice-broadcast/types";
|
||||
import { ButtonEvent } from "../elements/AccessibleButton";
|
||||
|
||||
interface IOptionsButtonProps {
|
||||
mxEvent: MatrixEvent;
|
||||
// TODO: Types
|
||||
getTile: () => any | null;
|
||||
getTile: () => IEventTileType | null;
|
||||
getReplyChain: () => ReplyChain | null;
|
||||
permalinkCreator?: RoomPermalinkCreator;
|
||||
onFocusChange: (menuDisplayed: boolean) => void;
|
||||
|
@ -97,7 +96,7 @@ const OptionsButton: React.FC<IOptionsButtonProps> = ({
|
|||
|
||||
let contextMenu: ReactElement | undefined;
|
||||
if (menuDisplayed && button.current) {
|
||||
const tile = getTile && getTile();
|
||||
const tile = getTile?.();
|
||||
const replyChain = getReplyChain();
|
||||
|
||||
const buttonRect = button.current.getBoundingClientRect();
|
||||
|
@ -254,8 +253,7 @@ const ReplyInThreadButton: React.FC<IReplyInThreadButton> = ({ mxEvent }) => {
|
|||
interface IMessageActionBarProps {
|
||||
mxEvent: MatrixEvent;
|
||||
reactions?: Relations | null | undefined;
|
||||
// TODO: Types
|
||||
getTile: () => any | null;
|
||||
getTile: () => IEventTileType | null;
|
||||
getReplyChain: () => ReplyChain | null;
|
||||
permalinkCreator?: RoomPermalinkCreator;
|
||||
onFocusChange?: (menuDisplayed: boolean) => void;
|
||||
|
@ -487,7 +485,7 @@ export default class MessageActionBar extends React.PureComponent<IMessageAction
|
|||
0,
|
||||
<DownloadActionButton
|
||||
mxEvent={this.props.mxEvent}
|
||||
mediaEventHelperGet={() => this.props.getTile?.().getMediaHelper?.()}
|
||||
mediaEventHelperGet={() => this.props.getTile()?.getMediaHelper?.()}
|
||||
key="download"
|
||||
/>,
|
||||
);
|
||||
|
|
|
@ -107,6 +107,7 @@ export interface IEventTileOps {
|
|||
|
||||
export interface IEventTileType extends React.Component {
|
||||
getEventTileOps?(): IEventTileOps;
|
||||
getMediaHelper(): MediaEventHelper | undefined;
|
||||
}
|
||||
|
||||
export interface EventTileProps {
|
||||
|
|
|
@ -61,7 +61,7 @@ const JoinRuleSettings: React.FC<JoinRuleSettingsProps> = ({
|
|||
|
||||
const disabled = !room.currentState.mayClientSendStateEvent(EventType.RoomJoinRules, cli);
|
||||
|
||||
const [content, setContent] = useLocalEcho<IJoinRuleEventContent | undefined>(
|
||||
const [content, setContent] = useLocalEcho<IJoinRuleEventContent | undefined, IJoinRuleEventContent>(
|
||||
() => room.currentState.getStateEvents(EventType.RoomJoinRules, "")?.getContent(),
|
||||
(content) => cli.sendStateEvent(room.roomId, EventType.RoomJoinRules, content, ""),
|
||||
onError,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue