Skip to content

Commit 21509b8

Browse files
committed
Updated README.md and trivial corrections in hook
1 parent 4c4e755 commit 21509b8

File tree

2 files changed

+75
-11
lines changed

2 files changed

+75
-11
lines changed

README.md

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
Collection of Hooks.
44

5-
65
## Install
76

87
> Note: React 16.8+ is required for Hooks.
@@ -22,10 +21,17 @@ yarn add hooks-toolbox
2221
## API
2322

2423
- [Hooks](#hooks)
25-
- [`useGoogleApiInit()`](#usegoogleapiinit)
24+
- [Google-API](#google-api)
25+
- [`useGoogleApiInit()`](#usegoogleapiinit)
26+
- [DYMO-API](#dymo-api)
27+
- [`useDymoCheckService()`](#usedymocheckservice)
28+
- [`useDymoFetchPrinters()`](#usedymofetchprinters)
29+
- [`useDymoOpenLabel()`](#usedymoopenlabel)
2630

2731
## Hooks
2832

33+
## Google-API
34+
2935
### `useGoogleApiInit()`
3036

3137
This Hook is designed for load https://apis.google.com/js/api.js, initialize Google API and handle sign status.
@@ -43,11 +49,71 @@ Object containing:
4349
- `signed: boolean`: `false` Sign status.
4450
- `userProfile: object`: `null` User's basic profile information and token.
4551

52+
## DYMO-API
53+
54+
### `useDymoCheckService()`
55+
56+
Return the status of DYMO Label Web Service
57+
58+
#### Arguments
59+
60+
`port: number`: The port of running DYMO Label Web Service.
61+
62+
#### Returns
63+
64+
Array containing:
65+
66+
- `message: string`: `""` The errors thrown.
67+
- `status: string`: `"init"`: `"init" | "loading" | "success" | "error"` Status of DYMO Label Web Service.
68+
69+
### `useDymoFetchPrinters()`
70+
71+
Returns the available DYMO Labelwriter Printer
72+
73+
#### Arguments
74+
75+
`port: number`: The port of running DYMO Label Web Service.
76+
`statusDymoService: string`: The status of DYMO Label Web Service.
4677

78+
#### Returns
79+
80+
Array containing:
81+
82+
- `printers: array`: `[]` The list of available DYMO Labelwriter Printer.
83+
- `status: string`: `"init"`: `"init" | "loading" | "success" | "error"` Status of loading printers.
84+
85+
### `useDymoOpenLabel()`
86+
87+
Render Label
88+
89+
#### Arguments
90+
91+
`labelXML: xml file`: XML file.
92+
`statusDymoService: string`: The status of DYMO Label Web Service.
93+
`port: number`: The port of running DYMO Label Web Service.
4794

48-
[build-badge]: https://img.shields.io/travis/user/repo/master.png?style=flat-square
49-
[build]: https://travis-ci.org/user/repo
50-
[npm-badge]: https://img.shields.io/npm/v/npm-package.png?style=flat-square
51-
[npm]: https://www.npmjs.org/package/npm-package
52-
[coveralls-badge]: https://img.shields.io/coveralls/user/repo/master.png?style=flat-square
53-
[coveralls]: https://coveralls.io/github/user/repo
95+
#### Returns
96+
97+
Array containing:
98+
99+
- `label`:
100+
- `status: string`: `"init"`: `"init" | "loading" | "success" | "error"` Status of render label.
101+
102+
#### Example
103+
104+
```js
105+
import { useDymoOpenLabel, useDymoCheckService } from "hooks-toolbox";
106+
107+
const DymoLabelPreview = () => {
108+
const [msg, statusDymoService] = useDymoCheckService();
109+
const [label, status] = useDymoOpenLabel(statusDymoService, xmlFile);
110+
111+
if (label) {
112+
return (
113+
<img src={"data:image/png;base64," + label} alt="dymo label preview" />
114+
);
115+
} else {
116+
return null;
117+
}
118+
};
119+
```

src/useDymoOpenLabel/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ import {getDymoUrl, dymoAxios} from "../utils/dymo";
66
export function useDymoOpenLabel(statusDymoService, labelXML, port = 41951) {
77
const [status, setStatus] = useState("init");
88
const [label, setLabel] = useState(null);
9-
const [xml, setXml] = useState(null);
109
useEffect(() => {
1110
if (statusDymoService === "success") {
1211
setStatus("loading");
13-
setXml(labelXML);
1412
dymoAxios
1513
.post(
1614
getDymoUrl("RenderLabel", port),
@@ -26,5 +24,5 @@ export function useDymoOpenLabel(statusDymoService, labelXML, port = 41951) {
2624
}
2725
}, [labelXML, port, statusDymoService]);
2826

29-
return [label, xml, status];
27+
return [label, status];
3028
}

0 commit comments

Comments
 (0)