-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
72 lines (61 loc) · 1.94 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import React, {useState} from 'react';
import {
SafeAreaView,
StatusBar,
Text,
View,
ScrollView,
Alert,
} from 'react-native';
import {styles} from './utils/styles';
import {fetchDestination} from './utils/apis';
import {DestinationField} from './utils/components';
const App = () => {
const [destinationSearchItem, setDestinationSearchItem] = useState('');
const [destinationList, setDestinationList] = useState([]);
const [destinationLoading, setDestinationLoading] = useState(false);
const [typingId, setTypingId] = useState(null);
const autoCompleteDestinationField = (destination, code) => {
setDestinationSearchItem(destination);
setDestinationList([]);
};
const searchDestination = text => {
setDestinationSearchItem(text);
const destinationData = async () => {
try {
setDestinationLoading(true);
const result = await fetchDestination(destinationSearchItem);
setDestinationLoading(false);
setDestinationList(result);
} catch (error) {
setDestinationList([]);
Alert.alert('An error occured');
console.log('error', error.response.data);
setDestinationLoading(false);
}
};
clearTimeout(typingId);
const timeoutId = setTimeout(destinationData, 1000);
setTypingId(timeoutId);
};
return (
<SafeAreaView>
<View style={[styles.screenContainer]}>
<StatusBar barStyle={'dark-content'} />
<ScrollView>
<View style={styles.backgroundContainer}>
<Text style={[styles.header]}>Amadeus Hotel Booking</Text>
<DestinationField
onChange={searchDestination}
value={destinationSearchItem}
autoComplete={autoCompleteDestinationField}
destinationList={destinationList}
loading={destinationLoading}
/>
</View>
</ScrollView>
</View>
</SafeAreaView>
);
};
export default App;