Skip to content

Commit 9c979f9

Browse files
feat(MessageInput): extend mentionQueryParams to accept filters function (#1900)
* [MessageInput] - added function for mentionQueryParams * docs(searchQueryParams): extend `filters` documentation Co-authored-by: Anton Arnautov <[email protected]>
1 parent f2aeeee commit 9c979f9

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

docusaurus/docs/React/components/utility-components/channel-search.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ Custom UI component to display the search loading state. Rendered within the `Se
313313

314314
Object containing filters/sort/options overrides for user / channel search.
315315

316+
The `filters` attribute (`SearchQueryParams.userFilters.filters`) can be either `UserFilters` object describing the filter query or a function with a single argument of the search / filter (query) string. The function is then expected to derive and return the `UserFilters` from the provided query string.
317+
316318
| Type |
317319
|-----------------------------------------|
318320
| `SearchQueryParams<StreamChatGenerics>` |

src/components/ChannelSearch/hooks/useChannelSearch.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ export type SearchQueryParams<
4242
sort?: ChannelSort<StreamChatGenerics>;
4343
};
4444
userFilters?: {
45-
filters?: UserFilters<StreamChatGenerics>;
45+
filters?:
46+
| UserFilters<StreamChatGenerics>
47+
| ((query: string) => UserFilters<StreamChatGenerics>);
4648
options?: UserOptions;
4749
sort?: UserSort<StreamChatGenerics>;
4850
};

src/components/MessageInput/hooks/useUserTrigger.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ export const useUserTrigger = <
103103
{
104104
$or: [{ id: { $autocomplete: query } }, { name: { $autocomplete: query } }],
105105
id: { $ne: client.userID },
106-
...mentionQueryParams.filters,
106+
...(typeof mentionQueryParams.filters === 'function'
107+
? mentionQueryParams.filters(query)
108+
: mentionQueryParams.filters),
107109
},
108110
Array.isArray(mentionQueryParams.sort)
109111
? [{ id: 1 }, ...mentionQueryParams.sort]

0 commit comments

Comments
 (0)