Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Allow maintaining a different right panel width for thread panels #11064

Merged
merged 11 commits into from
Jun 15, 2023
15 changes: 12 additions & 3 deletions src/components/structures/MainSplit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ interface IProps {
collapsedRhs?: boolean;
panel?: JSX.Element;
children: ReactNode;
/**
* The optional string key to append onto the storage key to be able to save multiple panel widths.
*/
sizeKey?: string;
/**
* The size to use for the panel component if one isn't persisted in storage. Defaults to 350.
*/
defaultSize: number;
}

Expand All @@ -43,7 +49,7 @@ export default class MainSplit extends React.Component<IProps> {
this.props.resizeNotifier.notifyRightHandleResized();
};

private get storageKey(): string {
private get sizeSettingStorageKey(): string {
let key = "mx_rhs_size";
if (!!this.props.sizeKey) {
key += `_${this.props.sizeKey}`;
Expand All @@ -58,11 +64,14 @@ export default class MainSplit extends React.Component<IProps> {
delta: NumberSize,
): void => {
this.props.resizeNotifier.stopResizing();
window.localStorage.setItem(this.storageKey, (this.loadSidePanelSize().width + delta.width).toString());
window.localStorage.setItem(
this.sizeSettingStorageKey,
(this.loadSidePanelSize().width + delta.width).toString(),
);
};

private loadSidePanelSize(): { height: string | number; width: number } {
let rhsSize = parseInt(window.localStorage.getItem(this.storageKey)!, 10);
let rhsSize = parseInt(window.localStorage.getItem(this.sizeSettingStorageKey)!, 10);

if (isNaN(rhsSize)) {
rhsSize = this.props.defaultSize;
Expand Down
6 changes: 6 additions & 0 deletions src/components/structures/RoomView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ export interface IRoomState {
showApps: boolean;
isPeeking: boolean;
showRightPanel: boolean;
/**
* Whether the right panel shown is either of ThreadPanel or ThreadView.
* Always false when `showRightPanel` is false.
*/
threadRightPanel: boolean;
// error object, as from the matrix client/server API
// If we failed to load information about the room,
Expand Down Expand Up @@ -2454,6 +2458,8 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
<MainSplit
panel={rightPanel}
resizeNotifier={this.props.resizeNotifier}
// Override defaults when a thread is being shown to allow persisting a separate
// right panel width for thread panels as they tend to want to be wider.
sizeKey={this.state.threadRightPanel ? "thread" : undefined}
defaultSize={this.state.threadRightPanel ? 500 : undefined}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a comment explaining this logic wouldn't hurt.

I think the idea is: for a thread panel we default to 500px, for other panels we default to... something else?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to the IProps on MainSplit, defaultSize must be a number, not undefined?

Copy link
Member Author

@t3chguy t3chguy Jun 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its an optional prop, because of its presence in defaultProps and React's Defaultize behaviour on types, otherwise TSC strict would have been shouting at me

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise TSC strict would have been shouting at me

I did wonder!

>
Expand Down