aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/Card.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/Card.js')
-rw-r--r--src/components/Card.js49
1 files changed, 37 insertions, 12 deletions
diff --git a/src/components/Card.js b/src/components/Card.js
index bbf29f9..4ec4430 100644
--- a/src/components/Card.js
+++ b/src/components/Card.js
@@ -1,13 +1,15 @@
1import QRCode from 'qrcode.react'; 1import QRCode from 'qrcode.react';
2import { useEffect, useState } from 'react'; 2import { useEffect, useRef, useState } from 'react';
3import './style.css'; 3import './style.css';
4 4
5export const Card = () => { 5export const Card = () => {
6 const firstLoad = useRef(true);
7 const [qrvalue, setQrvalue] = useState('');
6 const [network, setNetwork] = useState({ 8 const [network, setNetwork] = useState({
7 ssid: '', 9 ssid: '',
8 password: '', 10 password: '',
9 }); 11 });
10 const [qrvalue, setQrvalue] = useState(''); 12 const [portrait, setPortrait] = useState(false);
11 13
12 const escape = (v) => { 14 const escape = (v) => {
13 const needsEscape = ['"', ';', ',', ':', '\\']; 15 const needsEscape = ['"', ';', ',', ':', '\\'];
@@ -33,6 +35,11 @@ export const Card = () => {
33 }; 35 };
34 36
35 useEffect(() => { 37 useEffect(() => {
38 if (firstLoad.current && window.innerWidth < 500) {
39 firstLoad.current = false;
40 setPortrait(true);
41 }
42
36 const ssid = escape(network.ssid); 43 const ssid = escape(network.ssid);
37 const password = escape(network.password); 44 const password = escape(network.password);
38 setQrvalue(`WIFI:T:WPA;S:${ssid};P:${password};;`); 45 setQrvalue(`WIFI:T:WPA;S:${ssid};P:${password};;`);
@@ -40,16 +47,24 @@ export const Card = () => {
40 47
41 return ( 48 return (
42 <div> 49 <div>
43 <fieldset id="print-area"> 50 <fieldset
44 <legend></legend> 51 id="print-area"
45 52 style={{ maxWidth: portrait ? '350px' : '100%' }}
46 <h1>WiFi Login</h1> 53 >
47 <hr /> 54 <h1 style={{ textAlign: portrait ? 'center' : 'left' }}>WiFi Login</h1>
48 55
49 <div className="details"> 56 <div
50 <QRCode className="qrcode" value={qrvalue} size={175} /> 57 className="details"
58 style={{ flexDirection: portrait ? 'column' : 'row' }}
59 >
60 <QRCode
61 className="qrcode"
62 style={{ paddingRight: portrait ? '' : '1em' }}
63 value={qrvalue}
64 size={175}
65 />
51 66
52 <div className="text"> 67 <div className="inputs">
53 <label>Network name</label> 68 <label>Network name</label>
54 <textarea 69 <textarea
55 id="ssid" 70 id="ssid"
@@ -63,6 +78,10 @@ export const Card = () => {
63 <textarea 78 <textarea
64 id="password" 79 id="password"
65 type="text" 80 type="text"
81 style={{
82 height:
83 portrait && network.password.length > 40 ? '5em' : 'auto',
84 }}
66 maxLength="63" 85 maxLength="63"
67 placeholder="Password" 86 placeholder="Password"
68 value={network.password} 87 value={network.password}
@@ -80,8 +99,14 @@ export const Card = () => {
80 Point your phone's camera at the QR Code to connect automatically 99 Point your phone's camera at the QR Code to connect automatically
81 </p> 100 </p>
82 </fieldset> 101 </fieldset>
83 <div className="print-btn"> 102
84 <button onClick={onPrint}>Print</button> 103 <div className="buttons">
104 <button id="rotate" onClick={() => setPortrait(!portrait)}>
105 Rotate
106 </button>
107 <button id="print" onClick={onPrint}>
108 Print
109 </button>
85 </div> 110 </div>
86 </div> 111 </div>
87 ); 112 );