From 093f025de3e97339750dc3df5be626a0315507dc Mon Sep 17 00:00:00 2001 From: Ben Woodward Date: Thu, 5 Aug 2021 12:12:17 -0700 Subject: Style and code refactor (#166) * Move all settings below card * refactor components; lifting state up * background color * Evergreen components for everything * password error * Tighten card size * Simply hide password to basic toggle, never disable * Hide password label, too * Maximize mobile portrait width * Make wifi tip smaller * Small style tweaks * Copy: update password length error text to include helpful instructions This will need a backfill for other translations * Remove unused css * Use empty string for EncryptionMode=None value * Remove light.min.css * Include logo on wificard * Cleanup after rebase * Clean-up comments on state * Padding for mobile --- src/components/Card.js | 225 ------------------------------------------------- 1 file changed, 225 deletions(-) delete mode 100644 src/components/Card.js (limited to 'src/components/Card.js') diff --git a/src/components/Card.js b/src/components/Card.js deleted file mode 100644 index 601b760..0000000 --- a/src/components/Card.js +++ /dev/null @@ -1,225 +0,0 @@ -import QRCode from 'qrcode.react'; -import { useEffect, useRef, useState } from 'react'; -import { useTranslation } from 'react-i18next'; -import './style.css'; - -export const Card = ({ direction = 'ltr' }) => { - const firstLoad = useRef(true); - const [qrvalue, setQrvalue] = useState(''); - const [network, setNetwork] = useState({ - ssid: '', - encryptionMode: 'WPA', - password: '', - hidePassword: false, - }); - const [portrait, setPortrait] = useState(false); - const { t } = useTranslation(); - const escape = (v) => { - const needsEscape = ['"', ';', ',', ':', '\\']; - - let escaped = ''; - for (const c of v) { - if (needsEscape.includes(c)) { - escaped += `\\${c}`; - } else { - escaped += c; - } - } - return escaped; - }; - - const onPrint = () => { - if (network.ssid.length > 0) { - if (network.password.length < 8 && network.encryptionMode === 'WPA') { - alert(t('wifi.alert.password.length.8')); - } else if ( - network.password.length < 5 && - network.encryptionMode === 'WEP' - ) { - alert(t('wifi.alert.password.length.5')); - } else { - document.title = 'WiFi Card - ' + network.ssid; - window.print(); - } - } else { - alert(t('wifi.alert.name')); - } - }; - - const disableHidePassword = () => { - const isWEPWithPasswordLengthShorterThat5Characters = () => { - return network.encryptionMode === 'WEP' && network.password.length < 5 - ? true - : false; - }; - - return network.encryptionMode === 'WPA' && network.password.length < 8 - ? true - : isWEPWithPasswordLengthShorterThat5Characters(); - }; - - useEffect(() => { - if (firstLoad.current && window.innerWidth < 500) { - firstLoad.current = false; - setPortrait(true); - } - - const ssid = escape(network.ssid); - const password = - network.encryptionMode === 'nopass' ? '' : escape(network.password); - setQrvalue(`WIFI:T:${network.encryptionMode};S:${ssid};P:${password};;`); - }, [network]); - - const setEncryptionMode = (e) => - setNetwork({ - ...network, - encryptionMode: e.target.value, - }); - - const checkDirectionAndSetPadding = - direction === 'ltr' ? { paddingRight: '1em' } : { paddingLeft: '1em' }; - - return ( -
-