You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
2.4 KiB
TypeScript
94 lines
2.4 KiB
TypeScript
import React from 'react';
|
|
|
|
import { PropsData as ConversationListItemPropsType } from '../ConversationListItem';
|
|
import { PropsData as SearchResultsProps } from '../SearchResults';
|
|
import { debounce } from 'lodash';
|
|
import { cleanSearchTerm } from '../../util/cleanSearchTerm';
|
|
import { SearchOptions } from '../../types/Search';
|
|
import { LeftPane } from '../LeftPane';
|
|
|
|
export interface Props {
|
|
searchTerm: string;
|
|
isSecondaryDevice: boolean;
|
|
|
|
conversations?: Array<ConversationListItemPropsType>;
|
|
|
|
searchResults?: SearchResultsProps;
|
|
|
|
updateSearchTerm: (searchTerm: string) => void;
|
|
search: (query: string, options: SearchOptions) => void;
|
|
openConversationInternal: (id: string, messageId?: string) => void;
|
|
clearSearch: () => void;
|
|
}
|
|
|
|
export class LeftPaneContactSection extends React.Component<Props, any> {
|
|
private readonly debouncedSearch: (searchTerm: string) => void;
|
|
|
|
public constructor(props: Props) {
|
|
super(props);
|
|
|
|
this.debouncedSearch = debounce(this.search.bind(this), 20);
|
|
}
|
|
|
|
public componentWillUnmount() {
|
|
this.updateSearch('');
|
|
}
|
|
|
|
public renderHeader(): JSX.Element {
|
|
const labels = [window.i18n('contactsHeader'), window.i18n('lists')];
|
|
return LeftPane.renderHeader(labels, null, undefined, null);
|
|
}
|
|
|
|
public render(): JSX.Element {
|
|
return <div>{this.renderHeader()}</div>;
|
|
}
|
|
|
|
public updateSearch(searchTerm: string) {
|
|
const { updateSearchTerm, clearSearch } = this.props;
|
|
|
|
if (!searchTerm) {
|
|
clearSearch();
|
|
|
|
return;
|
|
}
|
|
// reset our pubKeyPasted, we can either have a pasted sessionID or a sessionID got from a search
|
|
this.setState({ pubKeyPasted: '' }, () => {
|
|
window.Session.emptyContentEditableDivs();
|
|
});
|
|
|
|
if (updateSearchTerm) {
|
|
updateSearchTerm(searchTerm);
|
|
}
|
|
|
|
if (searchTerm.length < 2) {
|
|
return;
|
|
}
|
|
|
|
const cleanedTerm = cleanSearchTerm(searchTerm);
|
|
if (!cleanedTerm) {
|
|
return;
|
|
}
|
|
|
|
this.debouncedSearch(cleanedTerm);
|
|
}
|
|
|
|
public clearSearch() {
|
|
this.props.clearSearch();
|
|
//this.setFocus();
|
|
}
|
|
|
|
public search() {
|
|
const { search } = this.props;
|
|
const { searchTerm, isSecondaryDevice } = this.props;
|
|
|
|
if (search) {
|
|
search(searchTerm, {
|
|
noteToSelf: window.i18n('noteToSelf').toLowerCase(),
|
|
ourNumber: window.textsecure.storage.user.getNumber(),
|
|
regionCode: '',
|
|
isSecondaryDevice,
|
|
});
|
|
}
|
|
}
|
|
}
|