From 9ba6051fc3fff165323cade51660707b26406aa8 Mon Sep 17 00:00:00 2001 From: Boluwatife Omosowon Date: Sun, 10 Apr 2022 16:50:34 +0100 Subject: [PATCH] fix: allow full link search Signed-off-by: Boluwatife Omosowon --- src/components/structures/RoomDirectory.tsx | 8 ++++++-- src/components/structures/RoomSearch.tsx | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/components/structures/RoomDirectory.tsx b/src/components/structures/RoomDirectory.tsx index 5577bc29e70..9b75ff7812b 100644 --- a/src/components/structures/RoomDirectory.tsx +++ b/src/components/structures/RoomDirectory.tsx @@ -164,6 +164,10 @@ export default class RoomDirectory extends React.Component { this.getMoreRooms(); }; + private transformSearchTerm(term: string): string { + return term.substring(term.lastIndexOf("#")); + }; + private getMoreRooms(): Promise { if (!MatrixClientPeg.get()) return Promise.resolve(false); @@ -186,7 +190,7 @@ export default class RoomDirectory extends React.Component { opts.third_party_instance_id = this.state.instanceId as string; } if (this.nextBatch) opts.since = this.nextBatch; - if (filterString) opts.filter = { generic_search_term: filterString }; + if (filterString) opts.filter = { generic_search_term: this.transformSearchTerm(filterString) }; return MatrixClientPeg.get().publicRooms(opts).then((data) => { if ( filterString != this.state.filterString || @@ -322,7 +326,7 @@ export default class RoomDirectory extends React.Component { private onFilterChange = (alias: string) => { this.setState({ - filterString: alias?.trim() || "", + filterString: this.transformSearchTerm(alias?.trim()) || "", }); // don't send the request for a little bit, diff --git a/src/components/structures/RoomSearch.tsx b/src/components/structures/RoomSearch.tsx index 94212927641..6d540d33e08 100644 --- a/src/components/structures/RoomSearch.tsx +++ b/src/components/structures/RoomSearch.tsx @@ -134,9 +134,13 @@ export default class RoomSearch extends React.PureComponent { } }; + private transformSearchTerm(term: string): string { + return term.substring(term.lastIndexOf("#")); + }; + private onChange = () => { if (this.elementRef.current?.tagName !== "INPUT") return; - this.setState({ query: (this.elementRef.current as HTMLInputElement).value }); + this.setState({ query: this.transformSearchTerm((this.elementRef.current as HTMLInputElement).value) }); }; private onFocus = (ev: React.FocusEvent) => {