diff --git a/screenshots/get-connected-ios.png b/screenshots/get-connected-ios.png index 8563bdf6..91a4ef97 100644 Binary files a/screenshots/get-connected-ios.png and b/screenshots/get-connected-ios.png differ diff --git a/screenshots/get-connected-windows.png b/screenshots/get-connected-windows.png index d611708d..80754b20 100644 Binary files a/screenshots/get-connected-windows.png and b/screenshots/get-connected-windows.png differ diff --git a/website/public/index.html b/website/public/index.html index c240d2ca..e8fe1b31 100644 --- a/website/public/index.html +++ b/website/public/index.html @@ -3,7 +3,7 @@
- + ({ + hidden: { + display: 'none', + }, + button: { + margin: theme.spacing(1), + }, + fabButton: { + position: 'absolute', + margin: '0 auto', + left: 0, + right: 0, + }, + paper: { + padding: theme.spacing(2), + }, +})); + +export default function AddDevice() { + const classes = useStyles(); + const [formOpen, setFormOpen] = React.useState(false); + const [dialogOpen, setDialogOpen] = React.useState(false); + const [error, setError] = React.useState(''); + const [name, setName] = React.useState(''); + const [qrCodeUri, setQrCodeUri] = React.useState(''); + const [configFileUri, setConfigFileUri] = React.useState(''); + + var closeForm = () => { + setFormOpen(false); + setName(''); }; - onAdd = async (event: React.FormEvent) => { + var addDevice = async (event: React.FormEvent) => { event.preventDefault(); + const keypair = box_keyPair(); const b64PublicKey = window.btoa(String.fromCharCode(...(new Uint8Array(keypair.publicKey) as any))); const b64PrivateKey = window.btoa(String.fromCharCode(...(new Uint8Array(keypair.secretKey) as any))); @@ -36,12 +66,12 @@ class AddDevice extends React.Component { const res = await fetch('/api/devices', { method: 'POST', body: JSON.stringify({ - name: this.state.name, + name: name, publicKey: b64PublicKey, }), }); if (res.status >= 400) { - this.setState({ error: await res.text() }); + setError(await res.text()); return; } const { device } = (await res.json()) as { device: IDevice }; @@ -60,49 +90,78 @@ class AddDevice extends React.Component { Endpoint = ${device.endpoint || `${window.location.hostname}:51820`} `; - this.setState({ - open: true, - qrCodeUri: await qrcode.toDataURL(configFile), - configFileUri: URL.createObjectURL(new Blob([configFile])), - }); - }; + setQrCodeUri(await qrcode.toDataURL(configFile)); + setConfigFileUri(URL.createObjectURL(new Blob([configFile]))); - render() { - return ( - - ); - } -} + closeForm(); + setDialogOpen(true); + }; -export default view(AddDevice); + return ( +