import { useRef, useState } from "react"; import { Mgba, MgbaHandle } from "./mgba"; import { BindingsControl, DefaultBindingsSet, Bindings } from "./bindings"; import { styled } from "styled-components"; import { useOnKeyUp } from "./useOnKeyUp.hook"; import { useLocalStorage } from "./useLocalStorage.hook"; import { useAvoidItchIoScrolling } from "./useAvoidItchIoScrolling"; const BindingsDialog = styled.dialog` border-radius: 5px; margin-top: 20px; `; const VolumeLabel = styled.label` display: flex; gap: 10px; margin-bottom: 20px; `; const ActionButton = styled.button` width: 100%; margin-top: 20px; `; const AppContainer = styled.main` height: calc(100vh - 20px); padding: 10px; `; function App() { const [{ volume, bindings }, setState] = useLocalStorage( { volume: 1.0, bindings: DefaultBindingsSet() }, "agbrswebplayer" ); const setVolume = (newVolume: number) => setState({ volume: newVolume, bindings }); const setBindings = (newBindings: Bindings) => setState({ volume, bindings: newBindings }); const [paused, setPaused] = useState(false); const [showBindings, setShowBindings] = useState(false); const mgbaRef = useRef(null); useOnKeyUp("Escape", () => { setShowBindings(!showBindings); }); useAvoidItchIoScrolling(); return ( {showBindings && ( setShowBindings(false)} restart={() => mgbaRef.current?.restart()} /> )} ); } function BindingsWindow({ bindings, setBindings, setPaused, volume, setVolume, hide, restart, }: { bindings: Bindings; setBindings: (b: Bindings) => void; setPaused: (paused: boolean) => void; volume: number; setVolume: (v: number) => void; hide: () => void; restart: () => void; }) { return ( Volume: { console.log("e.target.value", e.target.value); console.log("volume", volume); setVolume(Number(e.target.value)); }} /> Restart Close ); } export default App;