import { useCallback, useState } from 'react'; import tw from 'twin.macro'; import { invoke } from '@tauri-apps/api/tauri'; import './App.css'; import { Configurator } from './configurator/configurator'; import { ButtonSwitch } from './commons/components/button'; import { fillParentCss } from './styles/fill-parent'; type Mode = 'Flowing' | 'Follow' | null; localStorage.setItem('debug', '*'); function App() { const [screenshots, setScreenshots] = useState([]); const [ledStripColors, setLedStripColors] = useState([]); const [currentMode, setCurrentMode] = useState(null); async function takeSnapshot() { const base64TextList: string[] = await invoke('take_snapshot'); setScreenshots(base64TextList.map((text) => `data:image/webp;base64,${text}`)); } const getLedStripColors = useCallback(async () => { setLedStripColors(await invoke('get_led_strip_colors')); }, []); const switchCurrentMode = useCallback( async (targetMode: Mode) => { console.log(targetMode, currentMode, currentMode === targetMode); if (currentMode === targetMode) { await invoke('play_mode', { targetMode: 'None' }); setCurrentMode(null); } else { await invoke('play_mode', { targetMode }); setCurrentMode(targetMode); } console.log(targetMode, currentMode, currentMode === targetMode); }, [currentMode, setCurrentMode], ); return (
{ledStripColors.map((it) => ( ))}
{screenshots.map((screenshot) => (
))}
takeSnapshot()}>Take Snapshot getLedStripColors()}>Get Colors switchCurrentMode('Flowing')}> Flowing Light switchCurrentMode('Follow')}>Follow
); } export default App;