Skip to content

Commit

Permalink
Replace focus_room_filter dispatch by Action.OpenSpotlight (#29259)
Browse files Browse the repository at this point in the history
* refactor(room search): replace `focus_room_filter` dispatch by `Action.OpenSpotlight`

* test(LoggedInView): add test to Ctrl+k shortcut
  • Loading branch information
florianduros authored Feb 13, 2025
1 parent 4b9382f commit 85f80b1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
4 changes: 1 addition & 3 deletions src/components/structures/LoggedInView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,7 @@ class LoggedInView extends React.Component<IProps, IState> {
handled = true;
break;
case KeyBindingAction.FilterRooms:
dis.dispatch({
action: "focus_room_filter",
});
dis.fire(Action.OpenSpotlight);
handled = true;
break;
case KeyBindingAction.ToggleUserMenu:
Expand Down
17 changes: 0 additions & 17 deletions src/components/structures/RoomSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import * as React from "react";

import { ALTERNATE_KEY_NAME } from "../../accessibility/KeyboardShortcuts";
import defaultDispatcher from "../../dispatcher/dispatcher";
import { type ActionPayload } from "../../dispatcher/payloads";
import { IS_MAC, Key } from "../../Keyboard";
import { _t } from "../../languageHandler";
import AccessibleButton from "../views/elements/AccessibleButton";
Expand All @@ -22,26 +21,10 @@ interface IProps {
}

export default class RoomSearch extends React.PureComponent<IProps> {
private dispatcherRef?: string;

public componentDidMount(): void {
this.dispatcherRef = defaultDispatcher.register(this.onAction);
}

public componentWillUnmount(): void {
defaultDispatcher.unregister(this.dispatcherRef);
}

private openSpotlight(): void {
defaultDispatcher.fire(Action.OpenSpotlight);
}

private onAction = (payload: ActionPayload): void => {
if (payload.action === "focus_room_filter") {
this.openSpotlight();
}
};

public render(): React.ReactNode {
const classes = classNames(
{
Expand Down
8 changes: 8 additions & 0 deletions test/unit-tests/components/structures/LoggedInView-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,14 @@ describe("<LoggedInView />", () => {
expect(defaultDispatcher.dispatch).not.toHaveBeenCalledWith({ action: Action.ViewHomePage });
});

it("should open spotlight when Ctrl+k is fired", async () => {
jest.spyOn(defaultDispatcher, "fire");

getComponent();
await userEvent.keyboard("{Control>}k{/Control}");
expect(defaultDispatcher.fire).toHaveBeenCalledWith(Action.OpenSpotlight);
});

describe("timezone updates", () => {
const userTimezone = "Europe/London";
const originalController = SETTINGS["userTimezonePublish"].controller;
Expand Down

0 comments on commit 85f80b1

Please sign in to comment.