import React, { useState, useEffect } from 'react';
import './App.css';
const App = () => {
const [cameraInput, setCameraInput] = useState('');
useEffect(() => {
const fetchCameraInput = async () => {
try {
const response = await fetch('https://api.example.com/camera-input');
const data = await response.json();
setCameraInput(data.input);
} catch (error) {
console.error('Error fetching camera input:', error);
}
};
fetchCameraInput();
}, []);
const handleChangeCameraInput = (newInput) => {
setCameraInput(newInput);
fetch('https://api.example.com/camera-input', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ input: newInput }),
})
.then((response) => response.json())
.then((data) => console.log('Camera input updated:', data))
.catch((error) => console.error('Error updating camera input:', error));
};
return (
<div className="App bg-gray-100 min-h-screen p-8">
<header className="text-center mb-8">
<h1 className="text-4xl font-bold text-gray-800">Virtual Assistant Camera</h1>
<p className="text-gray-600">Change Camera Input on Android</p>
</header>
<main className="max-w-4xl mx-auto bg-white p-6 rounded-lg shadow-lg">
<section className="mb-8">
<h2 className="text-2xl font-semibold text-gray-800 mb-4">Current Camera Input</h2>
<p className="text-gray-700">{cameraInput || 'Loading...'}</p>
</section>
<section>
<h2 className="text-2xl font-semibold text-gray-800 mb-4">Change Camera Input</h2>
<div className="flex space-x-4">
<button
onClick={() => handleChangeCameraInput('Front Camera')}
className="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600 transition duration-300"
>
Front Camera
</button>
<button
onClick={() => handleChangeCameraInput('Back Camera')}
className="bg-green-500 text-white px-4 py-2 rounded hover:bg-green-600 transition duration-300"
>
Back Camera
</button>
</div>
</section>
</main>
<footer className="text-center mt-8 text-gray-600">
<p>© 2025 Virtual Assistant Camera. All rights reserved.</p>
</footer>
</div>
);
};
export default App;