Search stops working after some time (#3044)
This commit is contained in:
parent
5a800fe21d
commit
ecc0052c91
|
@ -29,7 +29,7 @@ import { showErrorAlert } from '../utils/info';
|
||||||
import { goRoom } from '../utils/goRoom';
|
import { goRoom } from '../utils/goRoom';
|
||||||
import I18n from '../i18n';
|
import I18n from '../i18n';
|
||||||
|
|
||||||
const API_FETCH_COUNT = 50;
|
const API_FETCH_COUNT = 25;
|
||||||
|
|
||||||
const getItemLayout = (data, index) => ({
|
const getItemLayout = (data, index) => ({
|
||||||
length: data.length,
|
length: data.length,
|
||||||
|
@ -57,10 +57,10 @@ class TeamChannelsView extends React.Component {
|
||||||
loading: true,
|
loading: true,
|
||||||
loadingMore: false,
|
loadingMore: false,
|
||||||
data: [],
|
data: [],
|
||||||
total: -1,
|
|
||||||
isSearching: false,
|
isSearching: false,
|
||||||
searchText: '',
|
searchText: '',
|
||||||
search: []
|
search: [],
|
||||||
|
end: false
|
||||||
};
|
};
|
||||||
this.loadTeam();
|
this.loadTeam();
|
||||||
}
|
}
|
||||||
|
@ -91,11 +91,11 @@ class TeamChannelsView extends React.Component {
|
||||||
|
|
||||||
load = debounce(async() => {
|
load = debounce(async() => {
|
||||||
const {
|
const {
|
||||||
loadingMore, total, data, search, isSearching, searchText
|
loadingMore, data, search, isSearching, searchText, end
|
||||||
} = this.state;
|
} = this.state;
|
||||||
|
|
||||||
const length = isSearching ? search.length : data.length;
|
const length = isSearching ? search.length : data.length;
|
||||||
if (loadingMore || length === total) {
|
if (loadingMore || end) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ class TeamChannelsView extends React.Component {
|
||||||
const newState = {
|
const newState = {
|
||||||
loading: false,
|
loading: false,
|
||||||
loadingMore: false,
|
loadingMore: false,
|
||||||
total: result.total
|
end: result.rooms.length < API_FETCH_COUNT
|
||||||
};
|
};
|
||||||
const rooms = result.rooms.map((room) => {
|
const rooms = result.rooms.map((room) => {
|
||||||
const record = this.teamChannels?.find(c => c.rid === room._id);
|
const record = this.teamChannels?.find(c => c.rid === room._id);
|
||||||
|
@ -219,7 +219,7 @@ class TeamChannelsView extends React.Component {
|
||||||
|
|
||||||
onSearchChangeText = debounce((searchText) => {
|
onSearchChangeText = debounce((searchText) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
searchText, search: [], loading: !!searchText, loadingMore: false, total: -1
|
searchText, search: [], loading: !!searchText, loadingMore: false, end: false
|
||||||
}, () => {
|
}, () => {
|
||||||
if (searchText) {
|
if (searchText) {
|
||||||
this.load();
|
this.load();
|
||||||
|
@ -234,7 +234,9 @@ class TeamChannelsView extends React.Component {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Keyboard.dismiss();
|
Keyboard.dismiss();
|
||||||
this.setState({ isSearching: false, search: [] }, () => {
|
this.setState({
|
||||||
|
searchText: null, isSearching: false, search: [], loadingMore: false, end: false
|
||||||
|
}, () => {
|
||||||
this.setHeader();
|
this.setHeader();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue