Skip to content

Commit 85f80b1

Browse files
authored
Replace focus_room_filter dispatch by Action.OpenSpotlight (#29259)
* refactor(room search): replace `focus_room_filter` dispatch by `Action.OpenSpotlight` * test(LoggedInView): add test to Ctrl+k shortcut
1 parent 4b9382f commit 85f80b1

File tree

3 files changed

+9
-20
lines changed

3 files changed

+9
-20
lines changed

src/components/structures/LoggedInView.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,7 @@ class LoggedInView extends React.Component<IProps, IState> {
501501
handled = true;
502502
break;
503503
case KeyBindingAction.FilterRooms:
504-
dis.dispatch({
505-
action: "focus_room_filter",
506-
});
504+
dis.fire(Action.OpenSpotlight);
507505
handled = true;
508506
break;
509507
case KeyBindingAction.ToggleUserMenu:

src/components/structures/RoomSearch.tsx

-17
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import * as React from "react";
1111

1212
import { ALTERNATE_KEY_NAME } from "../../accessibility/KeyboardShortcuts";
1313
import defaultDispatcher from "../../dispatcher/dispatcher";
14-
import { type ActionPayload } from "../../dispatcher/payloads";
1514
import { IS_MAC, Key } from "../../Keyboard";
1615
import { _t } from "../../languageHandler";
1716
import AccessibleButton from "../views/elements/AccessibleButton";
@@ -22,26 +21,10 @@ interface IProps {
2221
}
2322

2423
export default class RoomSearch extends React.PureComponent<IProps> {
25-
private dispatcherRef?: string;
26-
27-
public componentDidMount(): void {
28-
this.dispatcherRef = defaultDispatcher.register(this.onAction);
29-
}
30-
31-
public componentWillUnmount(): void {
32-
defaultDispatcher.unregister(this.dispatcherRef);
33-
}
34-
3524
private openSpotlight(): void {
3625
defaultDispatcher.fire(Action.OpenSpotlight);
3726
}
3827

39-
private onAction = (payload: ActionPayload): void => {
40-
if (payload.action === "focus_room_filter") {
41-
this.openSpotlight();
42-
}
43-
};
44-
4528
public render(): React.ReactNode {
4629
const classes = classNames(
4730
{

test/unit-tests/components/structures/LoggedInView-test.tsx

+8
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,14 @@ describe("<LoggedInView />", () => {
421421
expect(defaultDispatcher.dispatch).not.toHaveBeenCalledWith({ action: Action.ViewHomePage });
422422
});
423423

424+
it("should open spotlight when Ctrl+k is fired", async () => {
425+
jest.spyOn(defaultDispatcher, "fire");
426+
427+
getComponent();
428+
await userEvent.keyboard("{Control>}k{/Control}");
429+
expect(defaultDispatcher.fire).toHaveBeenCalledWith(Action.OpenSpotlight);
430+
});
431+
424432
describe("timezone updates", () => {
425433
const userTimezone = "Europe/London";
426434
const originalController = SETTINGS["userTimezonePublish"].controller;

0 commit comments

Comments
 (0)