import React, { useEffect, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import './App.css'; import TextField from '@mui/material/TextField'; import Select from '@mui/material/Select'; import MenuItem from '@mui/material/MenuItem'; type AudioDevice = { id: string; label: string; }; type Settings = { httpPort: string; inputDevice: AudioDevice; outputDevice: AudioDevice; recordingLength: number; outputFolder: string; }; const defaultSettings: Settings = { httpPort: '', inputDevice: { id: '', label: '' }, outputDevice: { id: '', label: '' }, recordingLength: 0, outputFolder: '', }; const fetchAudioDevices = async (): Promise => { // Replace with actual backend call // Example: return window.api.getAudioDevices(); return [ { id: 'default-in', label: 'Default Input' }, { id: 'mic-1', label: 'Microphone 1' }, { id: 'default-out', label: 'Default Output' }, { id: 'spk-1', label: 'Speakers 1' }, ]; }; const sendSettingsToBackend = (settings: Settings) => { // Replace with actual backend call // Example: window.api.updateSettings(settings); console.log('Settings updated:', settings); }; export default function SettingsPage() { const [settings, setSettings] = useState(defaultSettings); const [inputDevices, setInputDevices] = useState([]); const [outputDevices, setOutputDevices] = useState([]); const navigate = useNavigate(); useEffect(() => { fetchAudioDevices() .then((devices) => { // For demo, split devices by id setInputDevices(devices.filter((d) => d.id.includes('in'))); setOutputDevices(devices.filter((d) => d.id.includes('out'))); return devices; }) .catch((error) => { console.error('Error fetching audio devices:', error); }); }, []); useEffect(() => { sendSettingsToBackend(settings); }, [settings]); const handleChange = () => { // const { name, value } = e.target; // setSettings((prev) => ({ // ...prev, // [name]: value, // })); }; const handleFolderChange = async () => { // Replace with actual folder picker // Example: const folder = await window.api.selectFolder(); const folder = window.prompt( 'Enter output folder path:', settings.outputFolder, ); if (folder !== null) { setSettings((prev) => ({ ...prev, outputFolder: folder, })); } }; return (
{/* X Close Button */} Settings
HTTP Port: { setSettings((prev) => ({ ...prev, httpPort: e.target.value })); }} className="ml-2 text-white w-[150px]" />
Input Audio Device:
Output Audio Device:
Recording Length (seconds): { setSettings((prev) => ({ ...prev, recordingLength: e.target.value, })); }} className="ml-2 w-[150px]" />
Clip Output Folder:
); }