@tugitark/react-widget 1.3.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +7 -15
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -4,12 +4,14 @@ import { useState, useCallback } from 'react';
|
|
|
4
4
|
|
|
5
5
|
import render from '@tugitark/declarative-widget';
|
|
6
6
|
|
|
7
|
-
function Widget({ onNotification, onReady,
|
|
7
|
+
function Widget({ onNotification, onReady, ...props }) {
|
|
8
8
|
// Is this the first time this component has been rendered ever?
|
|
9
9
|
const [firstTime, setFirstTime] = useState(true);
|
|
10
|
+
|
|
11
|
+
// Is this the free (FAQ) version of the widget?
|
|
10
12
|
const isFree = props.jwtFn == null && props.user == null;
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
props.onNotification = useCallback((hasNotification) => {
|
|
13
15
|
if (isFree && !firstTime) {
|
|
14
16
|
// Replicate FAQ internal behaviour at a per-component level.
|
|
15
17
|
return;
|
|
@@ -17,25 +19,15 @@ function Widget({ onNotification, onReady, onOpened, onClosed, onError, ...props
|
|
|
17
19
|
onNotification && onNotification(hasNotification);
|
|
18
20
|
}, [onNotification, firstTime, isFree]);
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
props.onReady = useCallback(() => {
|
|
23
|
+
// This is called every time the widget re-mounts internally. However, we only want to
|
|
24
|
+
// notify the caller the first time it re-mounts after this component was created.
|
|
21
25
|
if (firstTime) {
|
|
22
26
|
setFirstTime(false);
|
|
23
27
|
onReady && onReady();
|
|
24
28
|
}
|
|
25
29
|
}, [onReady, firstTime]);
|
|
26
30
|
|
|
27
|
-
rest.onOpened = useCallback(() => {
|
|
28
|
-
onOpened && onOpened();
|
|
29
|
-
}, [onOpened]);
|
|
30
|
-
|
|
31
|
-
rest.onClosed = useCallback(() => {
|
|
32
|
-
onClosed && onClosed();
|
|
33
|
-
}, [onClosed]);
|
|
34
|
-
|
|
35
|
-
rest.onError = useCallback((e) => {
|
|
36
|
-
onError && onError(e);
|
|
37
|
-
}, [onError]);
|
|
38
|
-
|
|
39
31
|
render(props);
|
|
40
32
|
|
|
41
33
|
return null;
|