diff options
| author | Ben Woodward <ben@bdw.to> | 2021-07-04 16:48:10 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-04 16:48:10 -0700 |
| commit | 52ff61635b1cbd4b024ae882b606cfb64d6cc897 (patch) | |
| tree | de906f5b551d28d92048dcb65a8048fc718d3b9f /src/components | |
| parent | 313e5f8146a1f853269c2958fbbf4aa26c2422a8 (diff) | |
Prettier formatting (#33)
* Add prettier
* Format code
Diffstat (limited to 'src/components')
| -rw-r--r-- | src/components/Card.js | 56 | ||||
| -rw-r--r-- | src/components/style.css | 5 |
2 files changed, 41 insertions, 20 deletions
diff --git a/src/components/Card.js b/src/components/Card.js index 6c2c745..16f94a4 100644 --- a/src/components/Card.js +++ b/src/components/Card.js | |||
| @@ -2,14 +2,16 @@ import React, { useState, useEffect } from 'react'; | |||
| 2 | import QRCode from 'qrcode.react'; | 2 | import QRCode from 'qrcode.react'; |
| 3 | import './style.css'; | 3 | import './style.css'; |
| 4 | 4 | ||
| 5 | const Card = () => { | 5 | export const Card = () => { |
| 6 | const [ssid, setSsid] = useState(''); | 6 | const [network, setNetwork] = useState({ |
| 7 | const [password, setPassword] = useState(''); | 7 | ssid: '', |
| 8 | password: '', | ||
| 9 | }); | ||
| 8 | const [qrvalue, setQrvalue] = useState(''); | 10 | const [qrvalue, setQrvalue] = useState(''); |
| 9 | 11 | ||
| 10 | const escape = (v) => { | 12 | const escape = (v) => { |
| 11 | const needsEscape = ['"', ';', ',', ':', '\\']; | 13 | const needsEscape = ['"', ';', ',', ':', '\\']; |
| 12 | 14 | ||
| 13 | let escaped = ''; | 15 | let escaped = ''; |
| 14 | for (let i = 0; i < v.length; i++) { | 16 | for (let i = 0; i < v.length; i++) { |
| 15 | let c = v[i]; | 17 | let c = v[i]; |
| @@ -20,14 +22,13 @@ const Card = () => { | |||
| 20 | } | 22 | } |
| 21 | 23 | ||
| 22 | return escaped; | 24 | return escaped; |
| 23 | } | 25 | }; |
| 24 | 26 | ||
| 25 | useEffect(() => { | 27 | useEffect(() => { |
| 26 | let _ssid = escape(ssid), | 28 | const ssid = escape(network.ssid); |
| 27 | _password = escape(password); | 29 | const password = escape(network.password); |
| 28 | 30 | setQrvalue(`WIFI:T:WPA;S:${ssid};P:${password};;`); | |
| 29 | setQrvalue(`WIFI:T:WPA;S:${_ssid};P:${_password};;`); | 31 | }, [network]); |
| 30 | }, [ssid, password]); | ||
| 31 | 32 | ||
| 32 | return ( | 33 | return ( |
| 33 | <div> | 34 | <div> |
| @@ -35,26 +36,45 @@ const Card = () => { | |||
| 35 | <legend></legend> | 36 | <legend></legend> |
| 36 | 37 | ||
| 37 | <h1>WiFi Login</h1> | 38 | <h1>WiFi Login</h1> |
| 38 | <hr/> | 39 | <hr /> |
| 39 | 40 | ||
| 40 | <div className="details"> | 41 | <div className="details"> |
| 41 | <QRCode className="qrcode" value={qrvalue} size={175} /> | 42 | <QRCode className="qrcode" value={qrvalue} size={175} /> |
| 42 | 43 | ||
| 43 | <div className="text"> | 44 | <div className="text"> |
| 44 | <label>Network name</label> | 45 | <label>Network name</label> |
| 45 | <input id="ssid" type="text" maxLength="32" placeholder="WiFi Network name" value={ssid} onChange={event => setSsid(event.target.value)} /> | 46 | <input |
| 47 | id="ssid" | ||
| 48 | type="text" | ||
| 49 | maxLength="32" | ||
| 50 | placeholder="WiFi Network name" | ||
| 51 | value={network.ssid} | ||
| 52 | onChange={(e) => setNetwork({ ...network, ssid: e.target.value })} | ||
| 53 | /> | ||
| 46 | <label>Password</label> | 54 | <label>Password</label> |
| 47 | <input id="password" type="text" maxLength="63" placeholder="Password" value={password} onChange={event => setPassword(event.target.value)} /> | 55 | <input |
| 56 | id="password" | ||
| 57 | type="text" | ||
| 58 | maxLength="63" | ||
| 59 | placeholder="Password" | ||
| 60 | value={network.password} | ||
| 61 | onChange={(e) => | ||
| 62 | setNetwork({ ...network, password: e.target.value }) | ||
| 63 | } | ||
| 64 | /> | ||
| 48 | </div> | 65 | </div> |
| 49 | </div> | 66 | </div> |
| 50 | 67 | ||
| 51 | <p><span role="img" aria-label="mobile-phone">πΈπ±</span>Point your phone's camera at the QR Code to connect automatically</p> | 68 | <p> |
| 69 | <span role="img" aria-label="mobile-phone"> | ||
| 70 | πΈπ± | ||
| 71 | </span> | ||
| 72 | Point your phone's camera at the QR Code to connect automatically | ||
| 73 | </p> | ||
| 52 | </fieldset> | 74 | </fieldset> |
| 53 | <div className="print-btn"> | 75 | <div className="print-btn"> |
| 54 | <button onClick={window.print}>Print</button> | 76 | <button onClick={window.print}>Print</button> |
| 55 | </div> | 77 | </div> |
| 56 | </div> | 78 | </div> |
| 57 | ) | 79 | ); |
| 58 | } | 80 | }; |
| 59 | |||
| 60 | export default Card; | ||
diff --git a/src/components/style.css b/src/components/style.css index 0f98052..d1440e2 100644 --- a/src/components/style.css +++ b/src/components/style.css | |||
| @@ -8,7 +8,7 @@ | |||
| 8 | display: flex; | 8 | display: flex; |
| 9 | padding: 1em; | 9 | padding: 1em; |
| 10 | } | 10 | } |
| 11 | .details .text{ | 11 | .details .text { |
| 12 | margin: 0; | 12 | margin: 0; |
| 13 | } | 13 | } |
| 14 | .details .text * { | 14 | .details .text * { |
| @@ -36,7 +36,8 @@ | |||
| 36 | body * { | 36 | body * { |
| 37 | visibility: hidden; | 37 | visibility: hidden; |
| 38 | } | 38 | } |
| 39 | #print-area, #print-area * { | 39 | #print-area, |
| 40 | #print-area * { | ||
| 40 | visibility: visible; | 41 | visibility: visible; |
| 41 | } | 42 | } |
| 42 | #print-area input { | 43 | #print-area input { |
