import * as ImagePicker from "expo-image-picker"; import { useState } from "react"; import { ActivityIndicator, Button, Image, StyleSheet, Text, TextInput, View } from "react-native"; const BASE_URL = "https://shsf-api.reversed.dev/api/exec/15/1c44d8b5-4065-4a54-b259-748561021329"; export function ImagePage() { const [caption, setCaption] = useState(""); const [uploading, setUploading] = useState(false); const [previewUri, setPreviewUri] = useState(null); const handleTakePhoto = async () => { const { granted } = await ImagePicker.requestCameraPermissionsAsync(); if (!granted) { alert("Camera permission is required to take photos."); return; } const result = await ImagePicker.launchCameraAsync({ mediaTypes: "images", quality: 1, base64: true, }); if (result.canceled) return; const asset = result.assets[0]; setPreviewUri(asset.uri); setUploading(true); try { const res = await fetch(`${BASE_URL}/push_image`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ image_b64: asset.base64, caption }), }); const data = await res.json(); if (data.status !== "success") throw new Error(data.message ?? "Upload failed"); } catch (error) { console.error("Upload error:", error); alert("Failed to upload image."); } finally { setUploading(false); } }; const handleDismiss = () => { fetch(`${BASE_URL}/push_dismiss_image`, { method: "POST" }) .then((r) => r.json()) .then((data) => { if (data.status !== "success") alert("Failed to dismiss image."); }) .catch((error) => { console.error("Error dismissing image:", error); alert("Error dismissing image."); }); }; return ( Image Popup Show a photo on the TV with an optional caption. Caption (optional) {previewUri && ( )} {uploading ? ( ) : (