-
Notifications
You must be signed in to change notification settings - Fork 2
/
Home.js
171 lines (150 loc) · 4.51 KB
/
Home.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import React, { useState, useEffect } from 'react';
import { View, Text, StyleSheet, TouchableOpacity, TextInput } from 'react-native';
import { LinearGradient } from 'expo-linear-gradient';
import LottieView from 'lottie-react-native';
import { useNavigation } from '@react-navigation/native';
import * as Permissions from 'expo-permissions';
import * as Location from 'expo-location';
const Home = () => {
const navigation = useNavigation();
const [name, setName] = useState('');
const [description, setDescription] = useState('');
const [location, setLocation] = useState(null);
// const [status, requestPermission] = Location.useBackgroundPermissions();
useEffect(() => {
requestLocationPermission();
}, []);
const requestLocationPermission = async () => {
try {
const { status } = await Location.requestForegroundPermissionsAsync();
if (status !== 'granted') {
console.error('Permission to access location was denied');
} else {
getLocation();
}
} catch (error) {
console.error('Error requesting location permission:', error);
}
};
const getLocation = async () => {
try {
let { status } = await Location.requestForegroundPermissionsAsync();
if (status !== 'granted') {
console.error('Permission to access location was denied');
return;
}
let location = await Location.getCurrentPositionAsync({});
setLocation(location.coords);
// Uncomment the following line if you want to get the location using the Google Geolocation API
// getGoogleGeolocation(location.coords.latitude, location.coords.longitude);
} catch (error) {
console.error('Error getting location:', error);
}
};
const handleButtonPress = async () => {
try {
if (!location) {
console.error('Location data not available');
return;
}
// Need to change --------------------------------------------------
const response = await fetch('http://206.12.45.58:3001/api/record', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
name,
description,
latitude: location.latitude,
longitude: location.longitude,
}),
});
// console.log(req);
if (response.ok) {
console.log('User data saved successfully');
navigation.navigate('MatchingScreen', {name, description});
} else {
console.error('Failed to save user data');
}
} catch (error) {
console.error('Error sending request:', error);
}
};
return (
<LinearGradient
style={styles.container}
colors={["#86F1F9", "#FDD0ED"]}
start={{ x: 0.1, y: 0.1 }}
end={{ x: 0.1, y: 1 }}
>
<View style={styles.container}>
<Text style={styles.title}>Love Alarm</Text>
<LottieView
source={require("./assets/heartAnime.json")}
autoPlay
loop
style={styles.animation}
/>
<TextInput
style={styles.input}
placeholder="Your Name"
placeholderTextColor="#fff"
value={name}
onChangeText={(text) => setName(text)}
/>
<TextInput
style={[styles.input, { marginTop: 10 }]}
placeholder="Short Description"
placeholderTextColor="#fff"
value={description}
onChangeText={(text) => setDescription(text)}
/>
<TouchableOpacity style={styles.button} onPress={handleButtonPress}>
<Text style={styles.buttonText}>Start Matching</Text>
</TouchableOpacity>
</View>
</LinearGradient> );
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
title: {
fontSize: 30, // Adjusted font size
fontFamily: 'Gill Sans',
marginBottom: 20,
color: 'white',
},
button: {
backgroundColor: '#F87B92',
padding: 10,
borderRadius: 5,
marginTop: 20,
},
buttonText: {
fontWeight: 'bold',
fontFamily: 'Gill Sans',
color: 'white',
fontSize: 18,
},
animation: {
width: 250, // Adjusted animation size
height: 250, // Adjusted animation size
},
input: {
fontFamily: 'Gill Sans',
height: 40,
borderColor: 'white',
borderWidth: 1,
borderRadius: 5,
backgroundColor: 'rgba(255, 255, 255, 0.3)',
color: 'white',
paddingHorizontal: 10,
width: '80%',
marginTop: 10,
},
});
export default Home;