1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
import { Button, Heading, Link, Pane, Paragraph } from 'evergreen-ui';
import React, { useEffect, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import logo from '../src/images/wifi.png';
import { Settings } from './components/Settings';
import { WifiCard } from './components/WifiCard';
import './style.css';
import { Translations } from './translations';
function App() {
const html = document.querySelector('html');
const { t, i18n } = useTranslation();
const firstLoad = useRef(true);
const [settings, setSettings] = useState({
// Network SSID name
ssid: '',
// Network password
password: '',
// Settings: Network encryption mode
encryptionMode: 'WPA',
// Settings: EAP Method
eapMethod: 'PWD',
// Settings: EAP identity
eapIdentity: '',
// Settings: Hide password on the printed card
hidePassword: false,
// Settings: Mark your network as hidden SSID
hiddenSSID: false,
// Settings: Portrait orientation
portrait: false,
// Settings: Additional cards
additionalCards: 0,
// Settings: Show tip (legend) on card
hideTip: false,
});
const [errors, setErrors] = useState({
ssidError: '',
passwordError: '',
eapIdentityError: '',
});
const htmlDirection = (languageID) => {
languageID = languageID || i18n.language;
const rtl = Translations.filter((t) => t.id === languageID)[0]?.rtl;
return rtl ? 'rtl' : 'ltr';
};
const onChangeLanguage = (language) => {
html.style.direction = htmlDirection(language);
i18n.changeLanguage(language);
};
const onPrint = () => {
if (!settings.ssid.length) {
setErrors({
...errors,
ssidError: t('wifi.alert.name'),
});
return;
}
if (settings.password.length < 8 && settings.encryptionMode === 'WPA') {
setErrors({
...errors,
passwordError: t('wifi.alert.password.length.8'),
});
return;
}
if (settings.password.length < 5 && settings.encryptionMode === 'WEP') {
setErrors({
...errors,
passwordError: t('wifi.alert.password.length.5'),
});
return;
}
if (
settings.password.length < 1 &&
settings.encryptionMode === 'WPA2-EAP'
) {
setErrors({
...errors,
passwordError: t('wifi.alert.password'),
});
return;
}
if (
settings.eapIdentity.length < 1 &&
settings.encryptionMode === 'WPA2-EAP'
) {
setErrors({
...errors,
eapIdentityError: t('wifi.alert.eapIdentity'),
});
return;
}
document.title = 'WiFi Card - ' + settings.ssid;
window.print();
};
const onSSIDChange = (ssid) => {
setErrors({ ...errors, ssidError: '' });
setSettings({ ...settings, ssid });
};
const onPasswordChange = (password) => {
setErrors({ ...errors, passwordError: '' });
setSettings({ ...settings, password });
};
const onEncryptionModeChange = (encryptionMode) => {
setErrors({ ...errors, passwordError: '' });
setSettings({ ...settings, encryptionMode });
};
const onEapMethodChange = (eapMethod) => {
setSettings({ ...settings, eapMethod });
};
const onEapIdentityChange = (eapIdentity) => {
setErrors({ ...errors, eapIdentityError: '' });
setSettings({ ...settings, eapIdentity });
};
const onOrientationChange = (portrait) => {
setSettings({ ...settings, portrait });
};
const onHidePasswordChange = (hidePassword) => {
setSettings({ ...settings, hidePassword });
};
const onHiddenSSIDChange = (hiddenSSID) => {
setSettings({ ...settings, hiddenSSID });
};
const onAdditionalCardsChange = (additionalCardsStr) => {
const amount = parseInt(additionalCardsStr);
amount >= 0 && setSettings({ ...settings, additionalCards: amount });
};
const onHideTipChange = (hideTip) => {
setSettings({ ...settings, hideTip });
};
const onFirstLoad = () => {
html.style.direction = htmlDirection();
firstLoad.current = false;
};
useEffect(() => {
// Ensure the page direction is set properly on first load
if (htmlDirection() === 'rtl') {
html.style.direction = 'rtl';
}
});
return (
<Pane>
<Pane display="flex">
<img alt="icon" src={logo} width="32" height="32" />
<Heading size={900} paddingRight={16} paddingLeft={16}>
{t('title')}
</Heading>
</Pane>
<Pane>
<Paragraph marginTop={12}>{t('desc.use')}</Paragraph>
<Paragraph marginTop={12}>
{t('desc.privacy')}{' '}
<Link href="https://github.com/bndw/wifi-card">
{t('desc.source')}
</Link>
.
</Paragraph>
</Pane>
<Pane>
<WifiCard
settings={settings}
ssidError={errors.ssidError}
passwordError={errors.passwordError}
eapIdentityError={errors.eapIdentityError}
onSSIDChange={onSSIDChange}
onEapIdentityChange={onEapIdentityChange}
onPasswordChange={onPasswordChange}
/>
</Pane>
<Settings
settings={settings}
firstLoad={firstLoad}
onFirstLoad={onFirstLoad}
onLanguageChange={onChangeLanguage}
onEncryptionModeChange={onEncryptionModeChange}
onEapMethodChange={onEapMethodChange}
onOrientationChange={onOrientationChange}
onHidePasswordChange={onHidePasswordChange}
onHiddenSSIDChange={onHiddenSSIDChange}
onAdditionalCardsChange={onAdditionalCardsChange}
onHideTipChange={onHideTipChange}
/>
<Button
id="print"
appearance="primary"
height={40}
marginRight={16}
onClick={onPrint}
>
{t('button.print')}
</Button>
<Pane id="print-area">
{settings.additionalCards >= 0 &&
[...Array(settings.additionalCards + 1)].map((el, idx) => (
<WifiCard
key={`card-nr-${idx}`}
settings={settings}
ssidError={errors.ssidError}
passwordError={errors.passwordError}
eapIdentityError={errors.eapIdentityError}
onSSIDChange={onSSIDChange}
onEapIdentityChange={onEapIdentityChange}
onPasswordChange={onPasswordChange}
/>
))}
</Pane>
</Pane>
);
}
export default App;
|