2025-07-26 20:36:14 -05:00
|
|
|
import { CameraView, useCameraPermissions } from 'expo-camera'
|
|
|
|
|
import { useRef, useState } from 'react'
|
|
|
|
|
import { Button, Image, StyleSheet, Text, TouchableOpacity, View } from 'react-native'
|
2025-07-24 13:04:06 -05:00
|
|
|
|
2025-07-24 18:08:31 -05:00
|
|
|
export default function App() {
|
2025-07-26 20:36:14 -05:00
|
|
|
const [permission, requestPermission] = useCameraPermissions()
|
|
|
|
|
const [photo, setPhoto] = useState('')
|
|
|
|
|
const cameraRef = useRef<CameraView>(null)
|
2025-07-24 13:04:06 -05:00
|
|
|
|
2025-07-24 18:08:31 -05:00
|
|
|
async function _takePhoto() {
|
|
|
|
|
if (cameraRef.current) {
|
|
|
|
|
const pic = await cameraRef.current.takePictureAsync()
|
2025-07-26 20:36:14 -05:00
|
|
|
setPhoto(pic.base64 || '')
|
2025-07-24 18:08:31 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-26 13:06:35 -05:00
|
|
|
async function sendData() {
|
2025-07-26 20:36:14 -05:00
|
|
|
await fetch('http://localhost:3000/api/v1/posts', {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
Accept: 'application/json, text/plain, */*',
|
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
|
},
|
2025-07-26 13:06:35 -05:00
|
|
|
body: JSON.stringify({
|
2025-07-26 16:41:38 -05:00
|
|
|
userID: '6883ddb2640ebaa1a12e3791',
|
2025-07-26 13:06:35 -05:00
|
|
|
date: new Date(),
|
|
|
|
|
photo: photo,
|
|
|
|
|
notes: '3333 W Smoochie St'
|
2025-07-26 20:36:14 -05:00
|
|
|
})
|
|
|
|
|
})
|
2025-07-26 13:06:35 -05:00
|
|
|
}
|
|
|
|
|
|
2025-07-24 18:08:31 -05:00
|
|
|
if (!permission) {
|
|
|
|
|
// Camera permissions are still loading.
|
2025-07-26 20:36:14 -05:00
|
|
|
return <View />
|
2025-07-24 18:08:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!permission.granted) {
|
|
|
|
|
// Camera permissions are not granted yet.
|
|
|
|
|
return (
|
|
|
|
|
<View style={styles.container}>
|
|
|
|
|
<Text style={styles.message}>We need your permission to show the camera</Text>
|
2025-07-26 20:36:14 -05:00
|
|
|
<Button onPress={requestPermission} title='grant permission' />
|
2025-07-24 18:08:31 -05:00
|
|
|
</View>
|
2025-07-26 20:36:14 -05:00
|
|
|
)
|
2025-07-24 18:08:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<View style={styles.container}>
|
|
|
|
|
{photo ? (
|
|
|
|
|
<View style={styles.cameraContainer}>
|
|
|
|
|
<Image source={{ uri: photo }} style={styles.camera} />
|
|
|
|
|
<View style={styles.buttonContainer}>
|
|
|
|
|
<TouchableOpacity style={styles.button} onPress={() => setPhoto('')}>
|
2025-07-26 20:36:14 -05:00
|
|
|
<Text style={styles.text}>Retake</Text>
|
2025-07-24 18:08:31 -05:00
|
|
|
</TouchableOpacity>
|
2025-07-26 13:06:35 -05:00
|
|
|
<TouchableOpacity style={styles.button} onPress={sendData}>
|
2025-07-26 20:36:14 -05:00
|
|
|
<Text style={styles.text}>Continue</Text>
|
2025-07-24 18:08:31 -05:00
|
|
|
</TouchableOpacity>
|
|
|
|
|
</View>
|
|
|
|
|
</View>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
<View style={styles.cameraContainer}>
|
2025-07-26 20:36:14 -05:00
|
|
|
<CameraView style={styles.camera} facing={'back'} ref={cameraRef}></CameraView>
|
2025-07-24 18:08:31 -05:00
|
|
|
</View>
|
|
|
|
|
<View style={styles.buttonContainer}>
|
|
|
|
|
<TouchableOpacity style={styles.button} onPress={_takePhoto}>
|
|
|
|
|
<Text style={styles.text}>Take Photo</Text>
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
</View>
|
2025-07-26 20:36:14 -05:00
|
|
|
</>
|
|
|
|
|
)}
|
2025-07-24 18:08:31 -05:00
|
|
|
</View>
|
2025-07-26 20:36:14 -05:00
|
|
|
)
|
2025-07-24 13:04:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
2025-07-24 18:08:31 -05:00
|
|
|
container: {
|
|
|
|
|
flex: 1,
|
|
|
|
|
backgroundColor: '#25292e',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
paddingHorizontal: 25,
|
|
|
|
|
paddingVertical: 200
|
|
|
|
|
},
|
|
|
|
|
cameraContainer: {
|
2025-07-26 20:36:14 -05:00
|
|
|
flex: 1
|
2025-07-24 18:08:31 -05:00
|
|
|
},
|
|
|
|
|
message: {
|
|
|
|
|
textAlign: 'center',
|
2025-07-26 20:36:14 -05:00
|
|
|
paddingBottom: 10
|
2025-07-24 18:08:31 -05:00
|
|
|
},
|
|
|
|
|
camera: {
|
2025-07-26 20:36:14 -05:00
|
|
|
flex: 1
|
2025-07-24 18:08:31 -05:00
|
|
|
},
|
|
|
|
|
buttonContainer: {
|
|
|
|
|
flex: 0.2,
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
backgroundColor: 'orange',
|
|
|
|
|
marginTop: 15,
|
2025-07-26 20:36:14 -05:00
|
|
|
borderRadius: 5
|
2025-07-24 18:08:31 -05:00
|
|
|
},
|
|
|
|
|
button: {
|
|
|
|
|
flex: 1,
|
|
|
|
|
alignSelf: 'center',
|
2025-07-26 20:36:14 -05:00
|
|
|
alignItems: 'center'
|
2025-07-24 18:08:31 -05:00
|
|
|
},
|
|
|
|
|
text: {
|
|
|
|
|
fontSize: 24,
|
|
|
|
|
fontWeight: 'bold',
|
2025-07-26 20:36:14 -05:00
|
|
|
color: 'white'
|
|
|
|
|
}
|
|
|
|
|
})
|