render header from static method in LeftPane.tsx to be reused on subsection
parent
8b40bacc70
commit
1bbb3cedd4
@ -0,0 +1,93 @@
|
|||||||
|
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,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue