Skip to content

Commit ee274f3

Browse files
committed
readme and corrected mistyping in the typescript definition
1 parent 072f9f9 commit ee274f3

File tree

3 files changed

+73
-68
lines changed

3 files changed

+73
-68
lines changed

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"cSpell.words": [
3+
"covid",
4+
"rgba"
5+
]
6+
}

README.md

Lines changed: 66 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ This React module allows you to introduce a mobile interoperability into React a
33

44
This module is particularly useful in the current new normal established by the COVID-19 pandemic, where businesses require visiting customers to communicate accurately with customer representatives while enforcing the rules of wearing masks and social distancing. Thanks to this library, you will be able to establish an instant and secure communication right within the business software you are using, allowing your customers to collaborate effectively, securely and safely. For example, you may provide one-click subscriptions through user mobiles by leveraging the [mobile secure storage](https://globalinput.co.uk/global-input-app/mobile-authentication). Alternative, you do not even have to collect users' personal data thanks to the ability to request data on-demand from the mobile app at the point of service, freeing yourself from the pains of privacy regulations. You may also choose to allow your customers to encrypt their own data using their mobiles, giving users full control over the security and privacy of their personal data.
55

6-
76
## Setup
87

98
```shell
@@ -18,27 +17,27 @@ import {useGlobalInputApp} from 'global-input-react';
1817
Then, ```useGlobalInputApp()``` function (which is a React hook) can be called with a parameter, defining a mobile user interface. For example, the following code displays a login screen on the user's mobile screen when connected to your application:
1918

2019
```JavaScript
21-
const usernameField={
22-
id: 'username',
23-
label: 'Username',
20+
const usernameField = {
21+
id: 'username',
22+
label: 'Username',
2423
};
2524

26-
const passwordField={
27-
id:'password',
28-
label: 'Password'
25+
const passwordField = {
26+
id:'password',
27+
label: 'Password'
2928
};
3029

31-
const loginButton={
32-
id: 'login',
33-
label: 'Sign In',
34-
type: 'button'
30+
const loginButton = {
31+
id: 'login',
32+
label: 'Sign In',
33+
type: 'button'
3534
};
3635

37-
const mobile=useGlobalInputApp({initData:{
38-
form:{
39-
title: 'Sign In',
40-
fields: [usernameField,passwordField,loginButton]
41-
}
36+
const mobile = useGlobalInputApp( {initData : {
37+
form: {
38+
title: 'Sign In',
39+
fields: [usernameField,passwordField,loginButton]
40+
}
4241
}});
4342
```
4443
The ```initData``` contains a ```form``` with a set of fields: ```usernameField```,```passwordField```, and ```loginButton```.
@@ -53,9 +52,9 @@ It displays an encrypted QR Code for mobile apps to scan to connect to your appl
5352

5453
When connected to your application, the mobile app displays a ```form``` specified in ```initData```. Also, when the user interacts with elements in the ```form```, your application can receive mobile events through ```mobile.field``` variable, with the ```mobile.field.id``` identifying the element that the user has interacted with, and with ```mobile.field.value``` holding the value that the user has entered. Actually, you can simply pass your callback function into the ```mobile.setOnchange()``` function to receive those mobile events instead of implementing the logic for monitoring the changes in the ```mobile.field``` variable:
5554
```JavaScript
56-
mobile.setOnchange(({field})=>{
57-
const {id, value}=field;
58-
switch(id){
55+
mobile.setOnchange( ( {field} ) => {
56+
const {id, value} = field;
57+
switch(id) {
5958
case usernameField.id:
6059
setUsername(value);
6160
break;
@@ -72,22 +71,22 @@ In the above code, You can implement the ```setUsername()``` and ```setPassword(
7271
```JavaScript
7372
import React, { useState } from 'react';
7473
...
75-
const [username, setUsername]=useState('');
76-
const [password, setPassword]=useState('');
74+
const [username, setUsername] = useState('');
75+
const [password, setPassword] = useState('');
7776
```
7877

7978
You can also send values from your application to the mobile app responding to local or remote events:
8079

8180
```JavaScript
8281
Username:
83-
<input onChange={event=>{
82+
<input onChange = { (event) => {
8483
setUsername(event.target.value);
85-
mobile.sendValue(usernameField.id,event.target.value);
84+
mobile.sendValue(usernameField.id, event.target.value);
8685
} value={username} type="text"/>
8786

88-
<input onChange={event=>{
87+
<input onChange={ (event) => {
8988
setPassword(event.target.value);
90-
mobile.sendValue(passwordField.id,event.target.value);
89+
mobile.sendValue(passwordField.id, event.target.value);
9190
} value={username} type="password"/>
9291

9392
```
@@ -98,15 +97,17 @@ Using this approach, you can turn a simple password-based authentication into a
9897
When ```mobile.sendInitData()``` function is called with a ```InitData``` parameter, the connected mobile app will switch to the user interface specified:
9998
10099
```JavaScript
101-
const login=(username,password)=>{
102-
const initData={
103-
};
104-
mobile.sendInitData(initData:{
105-
form: {
106-
title: "Welcome " +username,
107-
fields: [{type: "info", value: "Test Completed",}]
108-
}
109-
});
100+
const infoField = {
101+
type: "info",
102+
value: "Test Completed"
103+
};
104+
const login = (username,password) => {
105+
mobile.sendInitData({
106+
form: {
107+
title: "Welcome " +username,
108+
fields: [infoField]
109+
}
110+
});
110111
}
111112
```
112113
Another way is to place another instance of ```useGlobalInputApp``` in a component, and then switch to that component.
@@ -124,22 +125,22 @@ When ```useGlobalInputApp``` is invoked for the first time, the module will sta
124125
For an element in a ```form```, ```type``` attribute defines how to process/display the data contained in it. For example, if it is set to ```button```, the mobile app display a ```Button```:
125126
126127
```JavaScript
127-
const loginButton={
128-
id: 'login',
129-
label: 'Sign In',
130-
type: 'button'
131-
};
128+
const loginButton = {
129+
id: 'login',
130+
label: 'Sign In',
131+
type: 'button'
132+
};
132133
```
133134
134135
The default value of the ```type``` attribute is "text". In this case, it display either a text input or a text area, depending on the value of ```nLines```, which represents how many number of lines is visible:
135136
136137
```JavaScript
137-
const contentField={
138-
id: 'content',
139-
label: 'Content',
140-
type: "text",
141-
nLines:5,
142-
value:"This is a content in the text box"
138+
const contentField = {
139+
id: 'content',
140+
label: 'Content',
141+
type: "text",
142+
nLines:5,
143+
value:"This is a content in the text box"
143144
};
144145
```
145146
If the ```value``` attribute is set, it will be sent along with the form to pre-populate the the field when being displayed on the mobile screen.
@@ -151,24 +152,22 @@ If the ```value``` attribute is set, it will be sent along with the form to pre-
151152
If you set the value of ```type``` of element in a ```form``` to ```"encrypt"```, the connected mobile app encrypts the ```value``` of the element and send back the result to your application:
152153
153154
```JavaScript
154-
const contentToEncrypt="...";
155-
const encryptField={
156-
id: 'content',
157-
label: 'Content',
158-
type: "encrypt",
159-
value:contentToEncrypt
155+
const encryptField = {
156+
id: 'content',
157+
label: 'Content',
158+
type: "encrypt",
159+
value: contentToEncrypt
160160
};
161161
```
162162
163163
In a similar way, setting ```type``` to ```"decrypt"``` will lead to decryption:
164164
165165
```JavaScript
166-
const contentToDecrypt="...";
167-
const decryptField={
166+
const decryptField = {
168167
id: 'content',
169168
label: 'Content',
170169
type: "decrypt",
171-
value:contentToDecrypt
170+
value: contentToDecrypt
172171
};
173172

174173
```
@@ -178,7 +177,7 @@ const decryptField={
178177
The value attribute in an element can also be an object containing some styling information:
179178
180179
```JavaScript
181-
const infoField={
180+
const infoField = {
182181
id: "title",
183182
type: "info",
184183
value: {
@@ -194,12 +193,12 @@ const infoField={
194193
You can display a multi-line text using an array for ```content```:
195194
196195
```JavaScript
197-
const informationField={
198-
id: "informationText",
199-
type: "info",
200-
value: {
201-
type: "view",
202-
style: {
196+
const informationField = {
197+
id: "informationText",
198+
type: "info",
199+
value: {
200+
type: "view",
201+
style: {
203202
borderColor: "#rgba(72,128,237,0.5)",
204203
backgroundColor: "#rgba(72,128,237,0.5)",
205204
borderWidth: 1,
@@ -238,20 +237,20 @@ Finally, the examples in the [website](https://globalinput.co.uk/), and tests in
238237
As discussed previously, in order to connect to a device application, your mobile app needs to obtain the value of ```connectionCode``` through scanning a QR Code. Then, you can pass it to the ```connect()``` function to connect to your device application as its second parameter:
239238

240239
```JavaScript
241-
const mobileConnector=createMessageConnector();
242-
const {initData} = await mobileConnector.connect({
243-
onInput:(inputMessage)=>{
240+
const mobileConnector = createMessageConnector();
241+
const {initData} = await mobileConnector.connect( {
242+
onInput:(inputMessage) => {
244243
....
245244
}
246-
},connectionCode);
245+
}, connectionCode);
247246
```
248247
In the above code, ```initData``` contains a ```form``` provided by the connected device application, while ```onInput()``` function is called whenever a message is received from the device application.
249248
250249
You can also send messages to the device application, responding to the events generated when the user interacts with form elements:
251250
252251
```JavaScript
253-
const sendUsername=(username) => {
254-
mobileConnector.sendValue(initData.form.fields[0].id,username);
252+
const sendUsername = (username) => {
253+
mobileConnector.sendValue(initData.form.fields[0].id, username);
255254
}
256255
```
257256
There are two input parameters required for calling ```mobileConnector.sendValue()``` function: the first one identifies the target element that the value is being sent to, while the second parameter holds the value needs to be sent across.

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ declare module 'global-input-react' {
3232
type ConnectQRProps = {
3333
size: number,
3434
level: "L" | "M" | "Q" | "H",
35-
container?:
35+
container?:React.FC
3636
};
3737
interface GlobalInputData {
3838
ConnectQR: FunctionComponent<ConnectQRProps>,

0 commit comments

Comments
 (0)