From 8bd60d09dcfda1d3ba8d10176d518a09472c3662 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 29 Nov 2022 10:36:59 +0000 Subject: [PATCH] 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 --- src/components/structures/RoomView.tsx | 13 ++++++++----- ...rchRoomView-test.tsx => RoomSearchView-test.tsx} | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) rename test/components/structures/{SearchRoomView-test.tsx => RoomSearchView-test.tsx} (99%) diff --git a/src/components/structures/RoomView.tsx b/src/components/structures/RoomView.tsx index a73082129b..b9150624fe 100644 --- a/src/components/structures/RoomView.tsx +++ b/src/components/structures/RoomView.tsx @@ -534,8 +534,7 @@ export class RoomView extends React.Component { const roomId = this.context.roomViewStore.getRoomId(); const room = this.context.client.getRoom(roomId); - // This convoluted type signature ensures we get IntelliSense *and* correct typing - const newState: Partial & Pick = { + const newState: Partial = { roomId, roomAlias: this.context.roomViewStore.getRoomAlias(), roomLoading: this.context.roomViewStore.isRoomLoading(), @@ -679,11 +678,15 @@ export class RoomView extends React.Component { // Clear the search results when clicking a search result (which changes the // currently scrolled to event, this.state.initialEventId). - if (this.state.initialEventId !== newState.initialEventId) { - newState.searchResults = null; + if (this.state.timelineRenderingType === TimelineRenderingType.Search && + this.state.initialEventId !== newState.initialEventId + ) { + newState.timelineRenderingType = TimelineRenderingType.Room; + this.state.search?.abortController?.abort(); + newState.search = undefined; } - this.setState(newState); + this.setState(newState as IRoomState); // At this point, newState.roomId could be null (e.g. the alias might not // have been resolved yet) so anything called here must handle this case. diff --git a/test/components/structures/SearchRoomView-test.tsx b/test/components/structures/RoomSearchView-test.tsx similarity index 99% rename from test/components/structures/SearchRoomView-test.tsx rename to test/components/structures/RoomSearchView-test.tsx index c3b07a148c..941b933015 100644 --- a/test/components/structures/SearchRoomView-test.tsx +++ b/test/components/structures/RoomSearchView-test.tsx @@ -38,7 +38,7 @@ jest.mock("../../../src/Searching", () => ({ searchPagination: jest.fn(), })); -describe("", () => { +describe("", () => { const eventMapper = (obj: Partial) => new MatrixEvent(obj); const resizeNotifier = new ResizeNotifier(); let client: MatrixClient;