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

Commit 8bd60d0

Browse files
authored
Fix search not being cleared when clicking on a result (#9635)
* Fix test naming * Fix search not being cleared when clicking on a result * Update RoomView.tsx * Update RoomView.tsx
1 parent 55d3522 commit 8bd60d0

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/components/structures/RoomView.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
534534
const roomId = this.context.roomViewStore.getRoomId();
535535
const room = this.context.client.getRoom(roomId);
536536

537-
// This convoluted type signature ensures we get IntelliSense *and* correct typing
538-
const newState: Partial<IRoomState> & Pick<IRoomState, any> = {
537+
const newState: Partial<IRoomState> = {
539538
roomId,
540539
roomAlias: this.context.roomViewStore.getRoomAlias(),
541540
roomLoading: this.context.roomViewStore.isRoomLoading(),
@@ -679,11 +678,15 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
679678

680679
// Clear the search results when clicking a search result (which changes the
681680
// currently scrolled to event, this.state.initialEventId).
682-
if (this.state.initialEventId !== newState.initialEventId) {
683-
newState.searchResults = null;
681+
if (this.state.timelineRenderingType === TimelineRenderingType.Search &&
682+
this.state.initialEventId !== newState.initialEventId
683+
) {
684+
newState.timelineRenderingType = TimelineRenderingType.Room;
685+
this.state.search?.abortController?.abort();
686+
newState.search = undefined;
684687
}
685688

686-
this.setState(newState);
689+
this.setState(newState as IRoomState);
687690
// At this point, newState.roomId could be null (e.g. the alias might not
688691
// have been resolved yet) so anything called here must handle this case.
689692

test/components/structures/SearchRoomView-test.tsx renamed to test/components/structures/RoomSearchView-test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jest.mock("../../../src/Searching", () => ({
3838
searchPagination: jest.fn(),
3939
}));
4040

41-
describe("<SearchRoomView/>", () => {
41+
describe("<RoomSearchView/>", () => {
4242
const eventMapper = (obj: Partial<IEvent>) => new MatrixEvent(obj);
4343
const resizeNotifier = new ResizeNotifier();
4444
let client: MatrixClient;

0 commit comments

Comments
 (0)