Skip to content

Commit

Permalink
Extract focus_search dispatch action into enum (#12721)
Browse files Browse the repository at this point in the history
* Extract `focus_search` dispatch action into enum

Signed-off-by: Michael Telatynski <[email protected]>

* copypasta

Signed-off-by: Michael Telatynski <[email protected]>

---------

Signed-off-by: Michael Telatynski <[email protected]>
  • Loading branch information
t3chguy authored Jul 3, 2024
1 parent b0d2010 commit 6b90fe2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/components/structures/LoggedInView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,7 @@ class LoggedInView extends React.Component<IProps, IState> {
handled = true;
break;
case KeyBindingAction.SearchInRoom:
dis.dispatch({
action: "focus_search",
});
dis.fire(Action.FocusMessageSearch);
handled = true;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/structures/RoomView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
);
}
break;
case "focus_search":
case Action.FocusMessageSearch:
this.onSearchClick();
break;

Expand Down
5 changes: 5 additions & 0 deletions src/dispatcher/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,4 +388,9 @@ export enum Action {
* Opens right panel with 3pid invite information
*/
View3pidInvite = "view_3pid_invite",

/**
* Opens right panel room summary and focuses the search input
*/
FocusMessageSearch = "focus_search",
}
14 changes: 14 additions & 0 deletions test/components/structures/LoggedInView-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ import { render, RenderResult } from "@testing-library/react";
import { ConditionKind, EventType, IPushRule, MatrixEvent, ClientEvent, PushRuleKind } from "matrix-js-sdk/src/matrix";
import { MediaHandler } from "matrix-js-sdk/src/webrtc/mediaHandler";
import { logger } from "matrix-js-sdk/src/logger";
import userEvent from "@testing-library/user-event";

import LoggedInView from "../../../src/components/structures/LoggedInView";
import { SDKContext } from "../../../src/contexts/SDKContext";
import { StandardActions } from "../../../src/notifications/StandardActions";
import ResizeNotifier from "../../../src/utils/ResizeNotifier";
import { flushPromises, getMockClientWithEventEmitter, mockClientMethodsUser } from "../../test-utils";
import { TestSdkContext } from "../../TestSdkContext";
import defaultDispatcher from "../../../src/dispatcher/dispatcher";
import SettingsStore from "../../../src/settings/SettingsStore";
import { SettingLevel } from "../../../src/settings/SettingLevel";
import { Action } from "../../../src/dispatcher/actions";

describe("<LoggedInView />", () => {
const userId = "@alice:domain.org";
Expand Down Expand Up @@ -384,4 +389,13 @@ describe("<LoggedInView />", () => {
});
});
});

it("should fire FocusMessageSearch on Ctrl+F when enabled", async () => {
jest.spyOn(defaultDispatcher, "fire");
await SettingsStore.setValue("ctrlFForSearch", null, SettingLevel.DEVICE, true);

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

0 comments on commit 6b90fe2

Please sign in to comment.