import { useUser } from '@clerk/clerk-react' import { CameraView, useCameraPermissions } from 'expo-camera' import React, { useRef, useState } from 'react' import { Button, Image, Modal, StyleSheet, Text, TextInput, TouchableOpacity, View } from 'react-native' export default function App() { const { user } = useUser() const [permission, requestPermission] = useCameraPermissions() const [photo, setPhoto] = useState('') const [address, setAddress] = useState('') const [notes, setNotes] = useState('') const [showConfirmation, setShowConfirmation] = useState(false) const cameraRef = useRef(null) async function resetState() { setPhoto('') setAddress('') setNotes('') } async function _takePhoto() { if (cameraRef.current) { let pic = await cameraRef.current.takePictureAsync({ quality: 0.1, base64: true }) console.log(pic) setPhoto(pic.base64 || '') } } async function sendData() { await fetch('http://localhost:3000/api/v1/posts', { method: 'POST', headers: { Accept: 'application/json, text/plain, */*', 'Content-Type': 'application/json' }, body: JSON.stringify({ clerkUserID: user?.id, date: new Date(), photo, address, notes }) }).then((res) => { console.log(res.status) if (res.status === 200) { setShowConfirmation(true) resetState() } }) } if (!permission) { // Camera permissions are still loading. return } if (!permission.granted) { // Camera permissions are not granted yet. return ( We need your permission to show the camera