Conform more code to strict null checking (#10169)
* Conform more code to strict null checking * delint * Iterate * delint * Fix bad test
This commit is contained in:
parent
5123d7e641
commit
e8b92b308b
85 changed files with 283 additions and 287 deletions
|
@ -34,11 +34,11 @@ import PosthogTrackers from "../../../PosthogTrackers";
|
|||
|
||||
interface IState {
|
||||
userId?: string;
|
||||
originalDisplayName?: string;
|
||||
displayName?: string;
|
||||
originalAvatarUrl?: string;
|
||||
originalDisplayName: string;
|
||||
displayName: string;
|
||||
originalAvatarUrl: string | null;
|
||||
avatarUrl?: string | ArrayBuffer;
|
||||
avatarFile?: File;
|
||||
avatarFile?: File | null;
|
||||
enableProfileSave?: boolean;
|
||||
}
|
||||
|
||||
|
@ -52,25 +52,25 @@ export default class ProfileSettings extends React.Component<{}, IState> {
|
|||
let avatarUrl = OwnProfileStore.instance.avatarMxc;
|
||||
if (avatarUrl) avatarUrl = mediaFromMxc(avatarUrl).getSquareThumbnailHttp(96);
|
||||
this.state = {
|
||||
userId: client.getUserId(),
|
||||
originalDisplayName: OwnProfileStore.instance.displayName,
|
||||
displayName: OwnProfileStore.instance.displayName,
|
||||
userId: client.getUserId()!,
|
||||
originalDisplayName: OwnProfileStore.instance.displayName ?? "",
|
||||
displayName: OwnProfileStore.instance.displayName ?? "",
|
||||
originalAvatarUrl: avatarUrl,
|
||||
avatarUrl: avatarUrl,
|
||||
avatarUrl: avatarUrl ?? undefined,
|
||||
avatarFile: null,
|
||||
enableProfileSave: false,
|
||||
};
|
||||
}
|
||||
|
||||
private uploadAvatar = (): void => {
|
||||
this.avatarUpload.current.click();
|
||||
this.avatarUpload.current?.click();
|
||||
};
|
||||
|
||||
private removeAvatar = (): void => {
|
||||
// clear file upload field so same file can be selected
|
||||
this.avatarUpload.current.value = "";
|
||||
this.setState({
|
||||
avatarUrl: null,
|
||||
avatarUrl: undefined,
|
||||
avatarFile: null,
|
||||
enableProfileSave: true,
|
||||
});
|
||||
|
@ -84,7 +84,7 @@ export default class ProfileSettings extends React.Component<{}, IState> {
|
|||
this.setState({
|
||||
enableProfileSave: false,
|
||||
displayName: this.state.originalDisplayName,
|
||||
avatarUrl: this.state.originalAvatarUrl,
|
||||
avatarUrl: this.state.originalAvatarUrl ?? undefined,
|
||||
avatarFile: null,
|
||||
});
|
||||
};
|
||||
|
@ -97,7 +97,7 @@ export default class ProfileSettings extends React.Component<{}, IState> {
|
|||
this.setState({ enableProfileSave: false });
|
||||
|
||||
const client = MatrixClientPeg.get();
|
||||
const newState: IState = {};
|
||||
const newState: Partial<IState> = {};
|
||||
|
||||
const displayName = this.state.displayName.trim();
|
||||
try {
|
||||
|
@ -114,7 +114,7 @@ export default class ProfileSettings extends React.Component<{}, IState> {
|
|||
);
|
||||
const { content_uri: uri } = await client.uploadContent(this.state.avatarFile);
|
||||
await client.setAvatarUrl(uri);
|
||||
newState.avatarUrl = mediaFromMxc(uri).getSquareThumbnailHttp(96);
|
||||
newState.avatarUrl = mediaFromMxc(uri).getSquareThumbnailHttp(96) ?? undefined;
|
||||
newState.originalAvatarUrl = newState.avatarUrl;
|
||||
newState.avatarFile = null;
|
||||
} else if (this.state.originalAvatarUrl !== this.state.avatarUrl) {
|
||||
|
@ -128,7 +128,7 @@ export default class ProfileSettings extends React.Component<{}, IState> {
|
|||
});
|
||||
}
|
||||
|
||||
this.setState(newState);
|
||||
this.setState<any>(newState);
|
||||
};
|
||||
|
||||
private onDisplayNameChanged = (e: React.ChangeEvent<HTMLInputElement>): void => {
|
||||
|
@ -141,7 +141,7 @@ export default class ProfileSettings extends React.Component<{}, IState> {
|
|||
private onAvatarChanged = (e: React.ChangeEvent<HTMLInputElement>): void => {
|
||||
if (!e.target.files || !e.target.files.length) {
|
||||
this.setState({
|
||||
avatarUrl: this.state.originalAvatarUrl,
|
||||
avatarUrl: this.state.originalAvatarUrl ?? undefined,
|
||||
avatarFile: null,
|
||||
enableProfileSave: false,
|
||||
});
|
||||
|
@ -152,7 +152,7 @@ export default class ProfileSettings extends React.Component<{}, IState> {
|
|||
const reader = new FileReader();
|
||||
reader.onload = (ev) => {
|
||||
this.setState({
|
||||
avatarUrl: ev.target.result,
|
||||
avatarUrl: ev.target?.result,
|
||||
avatarFile: file,
|
||||
enableProfileSave: true,
|
||||
});
|
||||
|
@ -162,7 +162,7 @@ export default class ProfileSettings extends React.Component<{}, IState> {
|
|||
|
||||
public render(): React.ReactNode {
|
||||
const hostingSignupLink = getHostingLink("user-settings");
|
||||
let hostingSignup = null;
|
||||
let hostingSignup: JSX.Element | undefined;
|
||||
if (hostingSignupLink) {
|
||||
hostingSignup = (
|
||||
<span>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue