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

Fix search not being cleared when clicking on a result #9635

Merged
merged 4 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/components/structures/RoomView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
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<IRoomState> & Pick<IRoomState, any> = {
const newState: Partial<IRoomState> = {
roomId,
roomAlias: this.context.roomViewStore.getRoomAlias(),
roomLoading: this.context.roomViewStore.isRoomLoading(),
Expand Down Expand Up @@ -679,11 +678,15 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {

// 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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jest.mock("../../../src/Searching", () => ({
searchPagination: jest.fn(),
}));

describe("<SearchRoomView/>", () => {
describe("<RoomSearchView/>", () => {
const eventMapper = (obj: Partial<IEvent>) => new MatrixEvent(obj);
const resizeNotifier = new ResizeNotifier();
let client: MatrixClient;
Expand Down