simplify SearchContacts component
This commit is contained in:
+7
-19
@@ -1694,7 +1694,6 @@ class SidepanelView extends React.Component {
|
|||||||
|
|
||||||
view === 'newtpk' ?
|
view === 'newtpk' ?
|
||||||
<NewTopicView
|
<NewTopicView
|
||||||
contactsSearchQuery={this.props.contactsSearchQuery}
|
|
||||||
searchResults={this.props.searchResults}
|
searchResults={this.props.searchResults}
|
||||||
onInitFind={this.props.onInitFind}
|
onInitFind={this.props.onInitFind}
|
||||||
onSearchContacts={this.props.onSearchContacts}
|
onSearchContacts={this.props.onSearchContacts}
|
||||||
@@ -2436,7 +2435,6 @@ class NewTopicView extends React.Component {
|
|||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
tabSelected: "p2p",
|
tabSelected: "p2p",
|
||||||
searchQuery: props.contactsSearchQuery,
|
|
||||||
contactList: props.searchResults
|
contactList: props.searchResults
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -2452,7 +2450,6 @@ class NewTopicView extends React.Component {
|
|||||||
|
|
||||||
static getDerivedStateFromProps(nextProps, prevState) {
|
static getDerivedStateFromProps(nextProps, prevState) {
|
||||||
return {
|
return {
|
||||||
searchQuery: nextProps.contactsSearchQuery,
|
|
||||||
contactList: nextProps.searchResults
|
contactList: nextProps.searchResults
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -2502,7 +2499,6 @@ class NewTopicView extends React.Component {
|
|||||||
onError={this.props.onError} /> :
|
onError={this.props.onError} /> :
|
||||||
<div className="flex-column">
|
<div className="flex-column">
|
||||||
<SearchContacts type="p2p"
|
<SearchContacts type="p2p"
|
||||||
searchQuery={this.state.searchQuery}
|
|
||||||
onSearchContacts={this.props.onSearchContacts} />
|
onSearchContacts={this.props.onSearchContacts} />
|
||||||
<ContactList
|
<ContactList
|
||||||
contacts={this.state.contactList}
|
contacts={this.state.contactList}
|
||||||
@@ -2597,13 +2593,13 @@ class NewTopicGroup extends React.PureComponent {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class SearchContacts extends React.Component {
|
class SearchContacts extends React.PureComponent {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
edited: false,
|
edited: false,
|
||||||
search: props.searchQuery
|
search: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
this.handleSearchChange = this.handleSearchChange.bind(this);
|
this.handleSearchChange = this.handleSearchChange.bind(this);
|
||||||
@@ -2613,8 +2609,8 @@ class SearchContacts extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
if (this.state.search) {
|
if (this.state.edited) {
|
||||||
this.setState({search: ''});
|
this.setState({search: '', edited: false});
|
||||||
this.props.onSearchContacts(Tinode.DEL_CHAR);
|
this.props.onSearchContacts(Tinode.DEL_CHAR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2626,16 +2622,12 @@ class SearchContacts extends React.Component {
|
|||||||
handleSearch(e) {
|
handleSearch(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var query = this.state.search.trim();
|
var query = this.state.search.trim();
|
||||||
if (query.length > 0) {
|
this.setState({edited: (query.length > 0)});
|
||||||
this.setState({edited: true});
|
this.props.onSearchContacts(query.length > 0 ? query : Tinode.DEL_CHAR);
|
||||||
this.props.onSearchContacts(query);
|
|
||||||
} else if (this.props.searchQuery) {
|
|
||||||
this.props.onSearchContacts(Tinode.DEL_CHAR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleClear() {
|
handleClear() {
|
||||||
if (this.state.edited || this.state.search) {
|
if (this.state.edited) {
|
||||||
this.props.onSearchContacts(Tinode.DEL_CHAR);
|
this.props.onSearchContacts(Tinode.DEL_CHAR);
|
||||||
}
|
}
|
||||||
this.setState({search: '', edited: false});
|
this.setState({search: '', edited: false});
|
||||||
@@ -4402,7 +4394,6 @@ class TinodeWeb extends React.Component {
|
|||||||
contextMenuParams: null,
|
contextMenuParams: null,
|
||||||
contextMenuItems: [],
|
contextMenuItems: [],
|
||||||
|
|
||||||
contactsSearchQuery: '',
|
|
||||||
// Chats as shown in the ContactsView
|
// Chats as shown in the ContactsView
|
||||||
chatList: [],
|
chatList: [],
|
||||||
// Contacts returned by a search query.
|
// Contacts returned by a search query.
|
||||||
@@ -4816,7 +4807,6 @@ class TinodeWeb extends React.Component {
|
|||||||
tnInitFind() {
|
tnInitFind() {
|
||||||
let fnd = this.tinode.getFndTopic();
|
let fnd = this.tinode.getFndTopic();
|
||||||
if (fnd.isSubscribed()) {
|
if (fnd.isSubscribed()) {
|
||||||
this.setState({contactsSearchQuery: ''});
|
|
||||||
this.tnFndSubsUpdated();
|
this.tnFndSubsUpdated();
|
||||||
} else {
|
} else {
|
||||||
fnd.onSubsUpdated = this.tnFndSubsUpdated;
|
fnd.onSubsUpdated = this.tnFndSubsUpdated;
|
||||||
@@ -4843,7 +4833,6 @@ class TinodeWeb extends React.Component {
|
|||||||
*/
|
*/
|
||||||
handleSearchContacts(query) {
|
handleSearchContacts(query) {
|
||||||
var fnd = this.tinode.getFndTopic();
|
var fnd = this.tinode.getFndTopic();
|
||||||
this.setState({contactsSearchQuery: query == Tinode.DEL_CHAR ? '' : query});
|
|
||||||
fnd.setMeta({desc: {public: query}}).then((ctrl) => {
|
fnd.setMeta({desc: {public: query}}).then((ctrl) => {
|
||||||
return fnd.getMeta(fnd.startMetaQuery().withSub().build());
|
return fnd.getMeta(fnd.startMetaQuery().withSub().build());
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
@@ -5305,7 +5294,6 @@ class TinodeWeb extends React.Component {
|
|||||||
onValidateCredentials={this.handleValidateCredentialsRequest}
|
onValidateCredentials={this.handleValidateCredentialsRequest}
|
||||||
|
|
||||||
onInitFind={this.tnInitFind}
|
onInitFind={this.tnInitFind}
|
||||||
contactsSearchQuery={this.state.contactsSearchQuery}
|
|
||||||
searchResults={this.state.searchResults}
|
searchResults={this.state.searchResults}
|
||||||
onSearchContacts={this.handleSearchContacts}
|
onSearchContacts={this.handleSearchContacts}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user