Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion apps/web/src/viewmodels/structures/ResizerViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ export class ResizerViewModel
}, 50);

public onLeftPanelResized = (newSize: number): void => {
// We don't want the panels to have fractional widths as that can cause blurry UI elements.
if (!Number.isInteger(newSize)) {
this.panelHandle?.resize(`${Math.round(newSize)}%`);
return;
}

const isCollapsed = newSize === 0;
// Store the size if the panel isn't collapsed.
if (!isCollapsed) {
Expand All @@ -76,7 +82,7 @@ export class ResizerViewModel
public onSeparatorClick = (): void => {
if (this.panelHandle?.isCollapsed()) {
const lastSize = SettingsStore.getValue("RoomList.panelSize");
this.panelHandle.resize(`${lastSize}%`);
this.panelHandle.resize(`${lastSize ?? 100}%`);
}
};

Expand Down
46 changes: 36 additions & 10 deletions apps/web/test/viewmodels/structures/ResizerViewModel-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,33 @@ describe("LeftPanelResizerViewModel", () => {
expect(() => vm.onSeparatorClick()).not.toThrow();
});

it("should expand panel on onSeparatorClick()", () => {
const vm = new ResizerViewModel();
SettingsStore.setValue("RoomList.panelSize", null, SettingLevel.DEVICE, 34);
const mockHandle = {
resize: jest.fn(),
isCollapsed: jest.fn().mockReturnValue(true),
} as unknown as PanelImperativeHandle;
vm.setPanelHandle(mockHandle);
describe("should expand panel on onSeparatorClick()", () => {
it("to last non-zero width that the user set", () => {
const vm = new ResizerViewModel();
SettingsStore.setValue("RoomList.panelSize", null, SettingLevel.DEVICE, 34);
const mockHandle = {
resize: jest.fn(),
isCollapsed: jest.fn().mockReturnValue(true),
} as unknown as PanelImperativeHandle;
vm.setPanelHandle(mockHandle);

vm.onSeparatorClick();

vm.onSeparatorClick();
expect(mockHandle.resize).toHaveBeenCalledWith("34%");
});

it("to maximum size of the panel", () => {
const vm = new ResizerViewModel();
const mockHandle = {
resize: jest.fn(),
isCollapsed: jest.fn().mockReturnValue(true),
} as unknown as PanelImperativeHandle;
vm.setPanelHandle(mockHandle);

expect(mockHandle.resize).toHaveBeenCalledWith("34%");
vm.onSeparatorClick();

expect(mockHandle.resize).toHaveBeenCalledWith("100%");
});
});

it("should set isFocusedViaKeyboard state correctly", () => {
Expand All @@ -90,4 +105,15 @@ describe("LeftPanelResizerViewModel", () => {
vm.onBlur();
expect(vm.getSnapshot().isFocusedViaKeyboard).toStrictEqual(false);
});

it("should resize to nearest whole number", () => {
const vm = new ResizerViewModel();
const mockHandle = {
resize: jest.fn(),
} as unknown as PanelImperativeHandle;
vm.setPanelHandle(mockHandle);

vm.onLeftPanelResized(25.515);
expect(mockHandle.resize).toHaveBeenCalledWith("26%");
});
});
Loading