Apply strictNullChecks to src/stores/widgets/* (#10324)

* Apply `strictNullChecks` to src/stores/widgets/*

* Iterate

* Iterate
This commit is contained in:
Michael Telatynski
2023-03-08 11:48:58 +00:00
committed by GitHub
parent 0c1c3f1cde
commit c0e40217f3
11 changed files with 59 additions and 55 deletions
+11 -11
View File
@@ -17,7 +17,6 @@
import { Room } from "matrix-js-sdk/src/models/room";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import { Optional } from "matrix-events-sdk";
import { compare } from "matrix-js-sdk/src/utils";
import SettingsStore from "../../settings/SettingsStore";
@@ -63,7 +62,7 @@ export interface IStoredLayout {
// this only applies to the top container currently, and that container
// will take the highest value among widgets in the container. Clamped
// to 0-100 and may have minimums imposed on it.
height?: number;
height?: number | null;
// TODO: [Deferred] Maximizing (fullscreen) widgets by default.
}
@@ -147,6 +146,7 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
}
private updateAllRooms = (): void => {
if (!this.matrixClient) return;
this.byRoom = {};
for (const room of this.matrixClient.getVisibleRooms()) {
this.recalculateRoom(room);
@@ -267,7 +267,7 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
const userWidgetLayout = userLayout?.widgets?.[widget.id];
if (Number.isFinite(userWidgetLayout?.width) || Number.isFinite(widgetLayout?.width)) {
const val = userWidgetLayout?.width || widgetLayout?.width;
const val = (userWidgetLayout?.width || widgetLayout?.width)!;
const normalized = clamp(val, MIN_WIDGET_WIDTH_PCT, 100);
widths.push(normalized);
doAutobalance = false; // a manual width was specified
@@ -278,7 +278,7 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
if (widgetLayout?.height || userWidgetLayout?.height) {
const defRoomHeight = defaultNumber(widgetLayout?.height, MIN_WIDGET_HEIGHT_PCT);
const h = defaultNumber(userWidgetLayout?.height, defRoomHeight);
maxHeight = Math.max(maxHeight, clamp(h, MIN_WIDGET_HEIGHT_PCT, 100));
maxHeight = Math.max(maxHeight ?? 0, clamp(h, MIN_WIDGET_HEIGHT_PCT, 100));
}
}
if (doAutobalance) {
@@ -346,11 +346,11 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
}
}
public getContainerWidgets(room: Optional<Room>, container: Container): IApp[] {
return this.byRoom[room?.roomId]?.[container]?.ordered || [];
public getContainerWidgets(room: Room, container: Container): IApp[] {
return this.byRoom[room.roomId]?.[container]?.ordered || [];
}
public isInContainer(room: Optional<Room>, widget: IApp, container: Container): boolean {
public isInContainer(room: Room, widget: IApp, container: Container): boolean {
return this.getContainerWidgets(room, container).some((w) => w.id === widget.id);
}
@@ -406,7 +406,7 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
return this.byRoom[room.roomId]?.[container]?.height ?? null; // let the default get returned if needed
}
public setContainerHeight(room: Room, container: Container, height?: number): void {
public setContainerHeight(room: Room, container: Container, height?: number | null): void {
const widgets = this.getContainerWidgets(room, container);
const widths = this.byRoom[room.roomId]?.[container]?.distributions;
const localLayout: Record<string, IStoredLayout> = {};
@@ -438,7 +438,7 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
container: container,
width: widths?.[i],
index: i,
height: height,
height,
};
});
this.updateUserLayout(room, localLayout);
@@ -477,7 +477,7 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
this.updateUserLayout(room, newLayout);
}
public hasMaximisedWidget(room?: Room): boolean {
public hasMaximisedWidget(room: Room): boolean {
return this.getContainerWidgets(room, Container.Center).length > 0;
}
@@ -517,7 +517,7 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
const ret: [IApp, Container][] = [];
for (const container in containers) {
const widgets = containers[container as Container].ordered;
const widgets = containers[container as Container]!.ordered;
for (const widget of widgets) {
ret.push([widget, container as Container]);
}