I'm using the React Native Elements Search Bar. Every time I call him, the dataSuccess function is called. When searching, only the searchLead function needs to work.
I have read the React native elements search bar documentation. It still didn't work. I think I have a problem with my algorithm. I hope I can tell. Is there a better example of using a Search Bar?
I share all the code with you.
Thanks in advance for your help.
export default class Lead extends Component {
constructor (props) {
super(props);
this.state = {
isLoading: true,
isRefreshing: false,
searchText: '',
isSearch: false,
offset: 0,
maxSize: 10,
leadList: [],
searchData: []
};
}
componentWillMount () {
this.setState({ isLoading: true });
}
componentDidMount () {
this.loadData();
}
handleRefresh = () => {
this.setState({
offset: 0,
maxSize: 10,
isSearch: false,
isRefreshing: true
}, () => {
this.loadData();
});
};
handleLoadMore = () => {
this.setState({
maxSize: this.state.maxSize + 5
}, () => {
this.loadData();
});
};
keyExtractor = (item, index) => index.toString();
loadData = async () => {
try {
const { offset, maxSize } = this.state;
const username = await AsyncStorage.getItem('username');
const token = await AsyncStorage.getItem('token');
var credentials = Base64.btoa(username + ':' + token);
var URL = `
http://demo.espocrm.com/advanced/api/v1/Lead?sortBy=createdAt&asc&offset=${offset}&maxSize=${maxSize}`;
axios.get(URL, { headers: { 'Espo-Authorization': credentials } })
.then(this.dataSuccess.bind(this))
.catch(this.dataFail.bind(this));
} catch (error) {
Alert.alert(
'Hata',
'Bir hata meydana geldi. Lütfen yöneticiye başvurunuz.',
[
{ text: 'Tamam', onPress: () => null }
]
);
}
};
searchLead = async (text) => {
try {
if (text) {
this.setState({ searchText: text, isSearch: true, isLoading: true });
const { searchText, maxSize } = this.state;
const username = await AsyncStorage.getItem('username');
const token = await AsyncStorage.getItem('token');
var credentials = Base64.btoa(username + ':' + token);
var URL = `
http://demo.espocrm.com/advanced/api/v1/Lead?select=name&orderBy=createdAt&order=desc&where[0][type]=textFilter&where[0][value]=${searchText}&maxSize=${maxSize}`;
axios.get(URL, { headers: { 'Espo-Authorization': credentials } })
.then(this.dataSearch.bind(this))
.catch(this.dataFail.bind(this));
}
} catch (error) {
Alert.alert(
'Hata',
'Arama başarısız oldu. Lütfen yöneticiniz ile görüşün.',
[
{ text: 'Tamam', onPress: () => null }
]
);
}
}
dataSuccess (response) {
console.log('test');
this.setState({ isRefreshing: false, isLoading: false, leadList: response.data.list });
}
dataSearch (response) {
this.setState({ isRefreshing: false, isLoading: false, isSearch: true, searchData: response.data.list });
}
dataFail (error) {
this.setState({ isLoading: false });
Alert.alert(
'Hata',
'Beklenmedik bir hata oluştu',
[
{ text: 'Tamam', onPress: () => null }
]
);
}
render () {
const { isLoading, isRefreshing, searchText, isSearch, leadList, searchData } = this.state;
return (
{
isLoading ?
: isSearch
?
}
keyExtractor={this.keyExtractor}
refreshing={isRefreshing}
onRefresh={this.handleRefresh}
onEndReached={this.handleLoadMore}
onEndReachedThreshold={0.5}
/>
:
}
keyExtractor={this.keyExtractor}
refreshing={isRefreshing}
onRefresh={this.handleRefresh}
onEndReached={this.handleLoadMore}
onEndReachedThreshold={0.5}
/>
}
);
}
}
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)