Skip to content

Commit 39d4e40

Browse files
authored
Merge pull request #973 from GetStream/channel-search-prop-fix
add needed params to channel search search function
2 parents fdd1495 + 1624916 commit 39d4e40

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ Custom UI component to display empty search results.
6363

6464
Custom search function to override default.
6565

66-
| Type |
67-
| ------------------------------------------------------------ |
68-
| (event: React.BaseSyntheticEvent) => Promise\<void\> \| void |
66+
| Type |
67+
| ------------------------------------------------------------------------------------------- |
68+
| (ChannelSearchFunctionParams, event: React.BaseSyntheticEvent ) =\> Promise\<void\> \| void |
6969

7070
### SearchLoading
7171

src/components/ChannelSearch/ChannelSearch.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ import type {
1818
DefaultUserType,
1919
} from '../../types/types';
2020

21+
export type ChannelSearchFunctionParams<Us extends DefaultUserType<Us> = DefaultUserType> = {
22+
setQuery: React.Dispatch<React.SetStateAction<string>>;
23+
setResults: React.Dispatch<React.SetStateAction<Array<UserResponse<Us>>>>;
24+
setResultsOpen: React.Dispatch<React.SetStateAction<boolean>>;
25+
setSearching: React.Dispatch<React.SetStateAction<boolean>>;
26+
};
27+
2128
export type SearchQueryParams<Us extends DefaultUserType<Us> = DefaultUserType> = {
2229
filters?: UserFilters<Us>;
2330
options?: UserOptions;
@@ -34,7 +41,10 @@ export type ChannelSearchProps<Us extends DefaultUserType<Us> = DefaultUserType>
3441
/** Custom UI component to display empty search results */
3542
SearchEmpty?: React.ComponentType;
3643
/** Custom search function to override default */
37-
searchFunction?: (event: React.BaseSyntheticEvent) => Promise<void> | void;
44+
searchFunction?: (
45+
params: ChannelSearchFunctionParams<Us>,
46+
event: React.BaseSyntheticEvent,
47+
) => Promise<void> | void;
3848
/** Custom UI component to display the search loading state */
3949
SearchLoading?: React.ComponentType;
4050
/** Object containing filters/sort/options overrides for user search */
@@ -144,10 +154,19 @@ const UnMemoizedChannelSearch = <
144154
getChannelsThrottled(event.target.value);
145155
};
146156

157+
const channelSearchParams = {
158+
setQuery,
159+
setResults,
160+
setResultsOpen,
161+
setSearching,
162+
};
163+
147164
return (
148165
<div className='str-chat__channel-search'>
149166
<input
150-
onChange={searchFunction || onSearch}
167+
onChange={(event) =>
168+
searchFunction ? searchFunction(channelSearchParams, event) : onSearch(event)
169+
}
151170
placeholder={t('Search')}
152171
ref={inputRef}
153172
type='text'

0 commit comments

Comments
 (0)