Skip to content

Commit c087755

Browse files
authored
Move ResizerNotifier into SDKContext (#30939)
* Move ResizerNotifier into SDKContext so we don't have to pass it into RoomView * Fix test * Unused import * Add tests * Remove a bunch of resizeNotifier props * Remove more resizeNotifier props * Add resizenotifier to test * Add more sdkcontext wrappers in tests * More sdkcontext wrappers * Even more sdkcontext wrappers * Add test to make sonarcloud happy * Context isn't always there unlike props * Test actual resizing too * Remove commented line
1 parent 87fdf96 commit c087755

32 files changed

+490
-443
lines changed

src/components/structures/FilePanel.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import EventIndexPeg from "../../indexing/EventIndexPeg";
2727
import { _t } from "../../languageHandler";
2828
import SearchWarning, { WarningKind } from "../views/elements/SearchWarning";
2929
import BaseCard from "../views/right_panel/BaseCard";
30-
import type ResizeNotifier from "../../utils/ResizeNotifier";
3130
import TimelinePanel from "./TimelinePanel";
3231
import Spinner from "../views/elements/Spinner";
3332
import { Layout } from "../../settings/enums/Layout";
@@ -39,7 +38,6 @@ import { ScopedRoomContextProvider } from "../../contexts/ScopedRoomContext.tsx"
3938
interface IProps {
4039
roomId: string;
4140
onClose: () => void;
42-
resizeNotifier: ResizeNotifier;
4341
}
4442

4543
interface IState {
@@ -294,7 +292,6 @@ class FilePanel extends React.Component<IProps, IState> {
294292
timelineSet={this.state.timelineSet}
295293
showUrlPreview={false}
296294
onPaginationRequest={this.onPaginationRequest}
297-
resizeNotifier={this.props.resizeNotifier}
298295
empty={emptyState}
299296
layout={Layout.Group}
300297
/>

src/components/structures/LoggedInView.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import SettingsStore from "../../settings/SettingsStore";
3030
import { SettingLevel } from "../../settings/SettingLevel";
3131
import ResizeHandle from "../views/elements/ResizeHandle";
3232
import { CollapseDistributor, Resizer } from "../../resizer";
33-
import type ResizeNotifier from "../../utils/ResizeNotifier";
3433
import PlatformPeg from "../../PlatformPeg";
3534
import { DefaultTagID } from "../../stores/room-list/models";
3635
import { hideToast as hideServerLimitToast, showToast as showServerLimitToast } from "../../toasts/ServerLimitToast";
@@ -67,6 +66,7 @@ import { monitorSyncedPushRules } from "../../utils/pushRules/monitorSyncedPushR
6766
import { type ConfigOptions } from "../../SdkConfig";
6867
import { MatrixClientContextProvider } from "./MatrixClientContextProvider";
6968
import { Landmark, LandmarkNavigation } from "../../accessibility/LandmarkNavigation";
69+
import { SDKContext } from "../../contexts/SDKContext.ts";
7070

7171
// We need to fetch each pinned message individually (if we don't already have it)
7272
// so each pinned message may trigger a request. Limit the number per room for sanity.
@@ -86,7 +86,6 @@ interface IProps {
8686
// transitioned to PWLU)
8787
onRegistered: (credentials: IMatrixClientCreds) => Promise<MatrixClient>;
8888
hideToSRUsers: boolean;
89-
resizeNotifier: ResizeNotifier;
9089
// eslint-disable-next-line camelcase
9190
page_type?: string;
9291
autoJoin?: boolean;
@@ -134,8 +133,11 @@ class LoggedInView extends React.Component<IProps, IState> {
134133
protected timezoneProfileUpdateRef?: string[];
135134
protected resizer?: Resizer<ICollapseConfig, CollapseItem>;
136135

137-
public constructor(props: IProps) {
138-
super(props);
136+
public static contextType = SDKContext;
137+
declare public context: React.ContextType<typeof SDKContext>;
138+
139+
public constructor(props: IProps, context: React.ContextType<typeof SDKContext>) {
140+
super(props, context);
139141

140142
this.state = {
141143
syncErrorData: undefined,
@@ -281,15 +283,15 @@ class LoggedInView extends React.Component<IProps, IState> {
281283
},
282284
onResized: (size) => {
283285
panelSize = size;
284-
this.props.resizeNotifier.notifyLeftHandleResized();
286+
this.context.resizeNotifier.notifyLeftHandleResized();
285287
},
286288
onResizeStart: () => {
287-
this.props.resizeNotifier.startResizing();
289+
this.context.resizeNotifier.startResizing();
288290
},
289291
onResizeStop: () => {
290292
// Always save the lhs size for the new room list.
291293
if (useNewRoomList || !panelCollapsed) window.localStorage.setItem("mx_lhs_size", "" + panelSize);
292-
this.props.resizeNotifier.stopResizing();
294+
this.context.resizeNotifier.stopResizing();
293295
},
294296
isItemCollapsed: (domNode) => {
295297
// New rooms list does not support collapsing.
@@ -681,7 +683,6 @@ class LoggedInView extends React.Component<IProps, IState> {
681683
threepidInvite={this.props.threepidInvite}
682684
oobData={this.props.roomOobData}
683685
key={this.props.currentRoomId || "roomview"}
684-
resizeNotifier={this.props.resizeNotifier}
685686
justCreatedOpts={this.props.roomJustCreatedOpts}
686687
forceTimeline={this.props.forceTimeline}
687688
/>
@@ -695,7 +696,7 @@ class LoggedInView extends React.Component<IProps, IState> {
695696
case PageTypes.UserView:
696697
if (!!this.props.currentUserId) {
697698
pageElement = (
698-
<UserView userId={this.props.currentUserId} resizeNotifier={this.props.resizeNotifier} />
699+
<UserView userId={this.props.currentUserId} resizeNotifier={this.context.resizeNotifier} />
699700
);
700701
}
701702
break;
@@ -748,7 +749,7 @@ class LoggedInView extends React.Component<IProps, IState> {
748749
<LeftPanel
749750
pageType={this.props.page_type as PageTypes}
750751
isMinimized={shouldUseMinimizedUI || false}
751-
resizeNotifier={this.props.resizeNotifier}
752+
resizeNotifier={this.context.resizeNotifier}
752753
/>
753754
</div>
754755
</div>

src/components/structures/MainSplit.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ import { type NumberSize, Resizable } from "re-resizable";
1212
import { type Direction } from "re-resizable/lib/resizer";
1313
import { type WebPanelResize } from "@matrix-org/analytics-events/types/typescript/WebPanelResize";
1414

15-
import type ResizeNotifier from "../../utils/ResizeNotifier";
1615
import { PosthogAnalytics } from "../../PosthogAnalytics.ts";
16+
import { SDKContext } from "../../contexts/SDKContext.ts";
1717

1818
interface IProps {
19-
resizeNotifier: ResizeNotifier;
2019
collapsedRhs?: boolean;
2120
panel?: JSX.Element;
2221
children: ReactNode;
@@ -36,16 +35,23 @@ interface IProps {
3635
}
3736

3837
export default class MainSplit extends React.Component<IProps> {
38+
public static contextType = SDKContext;
39+
declare public context: React.ContextType<typeof SDKContext>;
40+
3941
public static defaultProps = {
4042
defaultSize: 320,
4143
};
4244

45+
public constructor(props: IProps, context: React.ContextType<typeof SDKContext>) {
46+
super(props, context);
47+
}
48+
4349
private onResizeStart = (): void => {
44-
this.props.resizeNotifier.startResizing();
50+
this.context.resizeNotifier.startResizing();
4551
};
4652

4753
private onResize = (): void => {
48-
this.props.resizeNotifier.notifyRightHandleResized();
54+
this.context.resizeNotifier.notifyRightHandleResized();
4955
};
5056

5157
private get sizeSettingStorageKey(): string {
@@ -63,7 +69,7 @@ export default class MainSplit extends React.Component<IProps> {
6369
delta: NumberSize,
6470
): void => {
6571
const newSize = this.loadSidePanelSize().width + delta.width;
66-
this.props.resizeNotifier.stopResizing();
72+
this.context.resizeNotifier.stopResizing();
6773
window.localStorage.setItem(this.sizeSettingStorageKey, newSize.toString());
6874

6975
PosthogAnalytics.instance.trackEvent<WebPanelResize>({

src/components/structures/MatrixChat.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ import { _t, _td } from "../../languageHandler";
4949
import SettingsStore from "../../settings/SettingsStore";
5050
import ThemeController from "../../settings/controllers/ThemeController";
5151
import { startAnyRegistrationFlow } from "../../Registration";
52-
import ResizeNotifier from "../../utils/ResizeNotifier";
5352
import AutoDiscoveryUtils from "../../utils/AutoDiscoveryUtils";
5453
import { calculateRoomVia, makeRoomPermalink } from "../../utils/permalinks/Permalinks";
5554
import ThemeWatcher, { ThemeWatcherEvent } from "../../settings/watchers/ThemeWatcher";
@@ -199,7 +198,6 @@ interface IState {
199198
// and disable it when there are no dialogs
200199
hideToSRUsers: boolean;
201200
syncError: Error | null;
202-
resizeNotifier: ResizeNotifier;
203201
serverConfig?: ValidatedServerConfig;
204202
ready: boolean;
205203
threepidInvite?: IThreepidInvite;
@@ -254,7 +252,6 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
254252
isMobileRegistration: false,
255253

256254
syncError: null, // If the current syncing status is ERROR, the error object, otherwise null.
257-
resizeNotifier: new ResizeNotifier(),
258255
ready: false,
259256
};
260257

@@ -459,7 +456,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
459456
UIStore.instance.on(UI_EVENTS.Resize, this.handleResize);
460457

461458
// For PersistentElement
462-
this.state.resizeNotifier.on("middlePanelResized", this.dispatchTimelineResize);
459+
this.stores.resizeNotifier.on("middlePanelResized", this.dispatchTimelineResize);
463460

464461
RoomNotificationStateStore.instance.on(UPDATE_STATUS_INDICATOR, this.onUpdateStatusIndicator);
465462

@@ -511,7 +508,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
511508
this.themeWatcher?.stop();
512509
this.fontWatcher?.stop();
513510
UIStore.destroy();
514-
this.state.resizeNotifier.removeListener("middlePanelResized", this.dispatchTimelineResize);
511+
this.stores.resizeNotifier.removeListener("middlePanelResized", this.dispatchTimelineResize);
515512
window.removeEventListener("resize", this.onWindowResized);
516513
}
517514

@@ -828,7 +825,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
828825
collapseLhs: true,
829826
},
830827
() => {
831-
this.state.resizeNotifier.notifyLeftHandleResized();
828+
this.stores.resizeNotifier.notifyLeftHandleResized();
832829
},
833830
);
834831
break;
@@ -838,7 +835,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
838835
collapseLhs: false,
839836
},
840837
() => {
841-
this.state.resizeNotifier.notifyLeftHandleResized();
838+
this.stores.resizeNotifier.notifyLeftHandleResized();
842839
},
843840
);
844841
break;
@@ -1957,7 +1954,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
19571954
}
19581955

19591956
this.prevWindowWidth = width;
1960-
this.state.resizeNotifier.notifyWindowResized();
1957+
this.stores.resizeNotifier.notifyWindowResized();
19611958
};
19621959

19631960
private dispatchTimelineResize(): void {

src/components/structures/MessagePanel.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import ScrollPanel, { type IScrollState } from "./ScrollPanel";
3939
import DateSeparator from "../views/messages/DateSeparator";
4040
import TimelineSeparator, { SeparatorKind } from "../views/messages/TimelineSeparator";
4141
import ErrorBoundary from "../views/elements/ErrorBoundary";
42-
import type ResizeNotifier from "../../utils/ResizeNotifier";
4342
import Spinner from "../views/elements/Spinner";
4443
import { type RoomPermalinkCreator } from "../../utils/permalinks/Permalinks";
4544
import type EditorStateTransfer from "../../utils/EditorStateTransfer";
@@ -167,7 +166,6 @@ interface IProps {
167166
// which layout to use
168167
layout?: Layout;
169168

170-
resizeNotifier?: ResizeNotifier;
171169
permalinkCreator?: RoomPermalinkCreator;
172170
editState?: EditorStateTransfer;
173171

@@ -1064,7 +1062,6 @@ export default class MessagePanel extends React.Component<IProps, IState> {
10641062
onUnfillRequest={this.props.onUnfillRequest}
10651063
style={style}
10661064
stickyBottom={this.props.stickyBottom}
1067-
resizeNotifier={this.props.resizeNotifier}
10681065
fixedChildren={ircResizer}
10691066
>
10701067
{topSpinner}

src/components/structures/RightPanel.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,7 @@ export default class RightPanel extends React.Component<Props, IState> {
224224
break;
225225
case RightPanelPhases.FilePanel:
226226
if (!!roomId) {
227-
card = (
228-
<FilePanel roomId={roomId} resizeNotifier={this.props.resizeNotifier} onClose={this.onClose} />
229-
);
227+
card = <FilePanel roomId={roomId} onClose={this.onClose} />;
230228
}
231229
break;
232230

src/components/structures/RoomSearchView.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { _t } from "../../languageHandler";
2121
import { haveRendererForEvent } from "../../events/EventTileFactory";
2222
import SearchResultTile from "../views/rooms/SearchResultTile";
2323
import { searchPagination, SearchScope } from "../../Searching";
24-
import type ResizeNotifier from "../../utils/ResizeNotifier";
2524
import MatrixClientContext from "../../contexts/MatrixClientContext";
2625
import { RoomPermalinkCreator } from "../../utils/permalinks/Permalinks";
2726
import { useScopedRoomContext } from "../../contexts/ScopedRoomContext.tsx";
@@ -41,7 +40,6 @@ interface Props {
4140
inProgress: boolean;
4241
promise: Promise<ISearchResults>;
4342
abortController?: AbortController;
44-
resizeNotifier: ResizeNotifier;
4543
className: string;
4644
onUpdate(inProgress: boolean, results: ISearchResults | null, error: Error | null): void;
4745
ref?: Ref<ScrollPanel>;
@@ -54,7 +52,6 @@ export const RoomSearchView = ({
5452
scope,
5553
promise,
5654
abortController,
57-
resizeNotifier,
5855
className,
5956
onUpdate,
6057
inProgress,
@@ -309,7 +306,6 @@ export const RoomSearchView = ({
309306
ref={onRef}
310307
className={"mx_RoomView_searchResultsPanel " + className}
311308
onFillRequest={onSearchResultsFillRequest}
312-
resizeNotifier={resizeNotifier}
313309
>
314310
<li className="mx_RoomView_scrollheader" />
315311
{ret}

0 commit comments

Comments
 (0)