stream-chat-react
Version:
React components to create chat conversations or livestream style chat
54 lines (53 loc) • 3.1 kB
TypeScript
import type React from 'react';
import type { ChannelOrUserResponse } from '../utils';
import type { Channel, ChannelFilters, ChannelOptions, ChannelSort, UserFilters, UserOptions, UserSort } from 'stream-chat';
import type { SearchBarController } from '../SearchBar';
import type { SearchInputController } from '../SearchInput';
import type { SearchResultsController } from '../SearchResults';
export type ChannelSearchFunctionParams = {
setQuery: React.Dispatch<React.SetStateAction<string>>;
setResults: React.Dispatch<React.SetStateAction<ChannelOrUserResponse[]>>;
setSearching: React.Dispatch<React.SetStateAction<boolean>>;
};
export type SearchController = SearchInputController & SearchBarController & SearchResultsController;
export type SearchQueryParams = {
channelFilters?: {
filters?: ChannelFilters;
options?: ChannelOptions;
sort?: ChannelSort;
};
userFilters?: {
filters?: UserFilters | ((query: string) => UserFilters);
options?: UserOptions;
sort?: UserSort;
};
};
export type ChannelSearchParams = {
/** The type of channel to create on user result select, defaults to `messaging` */
channelType?: string;
/** Clear search state / results on every click outside the search input, defaults to true */
clearSearchOnClickOutside?: boolean;
/** Disables execution of the search queries, defaults to false */
disabled?: boolean;
/** Callback invoked with every search input change handler */
onSearch?: SearchInputController['onSearch'];
/** Callback invoked when the search UI is deactivated */
onSearchExit?: () => void;
/** Custom handler function to run on search result item selection */
onSelectResult?: (params: ChannelSearchFunctionParams, result: ChannelOrUserResponse) => Promise<void> | void;
/** The number of milliseconds to debounce the search query. The default interval is 200ms. */
searchDebounceIntervalMs?: number;
/** Boolean to search for channels in the server query, default is false and just searches for users */
searchForChannels?: boolean;
/** Boolean to search for users in the server query, default is true and just searches for users */
searchForUsers?: boolean;
/** Custom search function to override the default implementation */
searchFunction?: (params: ChannelSearchFunctionParams, event: React.BaseSyntheticEvent) => Promise<void> | void;
/** Object containing filters/sort/options overrides for user / channel search */
searchQueryParams?: SearchQueryParams;
};
export type ChannelSearchControllerParams = ChannelSearchParams & {
/** Set the array of channels displayed in the ChannelList */
setChannels?: React.Dispatch<React.SetStateAction<Array<Channel>>>;
};
export declare const useChannelSearch: ({ channelType, clearSearchOnClickOutside, disabled, onSearch: onSearchCallback, onSearchExit, onSelectResult, searchDebounceIntervalMs, searchForChannels, searchForUsers, searchFunction, searchQueryParams, setChannels, }: ChannelSearchControllerParams) => SearchController;