@bbearai/react 0.1.3 → 0.1.5
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/dist/index.js +16 -10
- package/dist/index.mjs +16 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -53,7 +53,7 @@ function useBugBear() {
|
|
|
53
53
|
return (0, import_react.useContext)(BugBearContext);
|
|
54
54
|
}
|
|
55
55
|
function BugBearProvider({ config, children, enabled = true }) {
|
|
56
|
-
const [client] = (0, import_react.useState)(
|
|
56
|
+
const [client, setClient] = (0, import_react.useState)(null);
|
|
57
57
|
const [isTester, setIsTester] = (0, import_react.useState)(false);
|
|
58
58
|
const [isQAEnabled, setIsQAEnabled] = (0, import_react.useState)(false);
|
|
59
59
|
const [testerInfo, setTesterInfo] = (0, import_react.useState)(null);
|
|
@@ -61,38 +61,44 @@ function BugBearProvider({ config, children, enabled = true }) {
|
|
|
61
61
|
const [isLoading, setIsLoading] = (0, import_react.useState)(true);
|
|
62
62
|
const hasInitialized = (0, import_react.useRef)(false);
|
|
63
63
|
const refreshAssignments = (0, import_react.useCallback)(async () => {
|
|
64
|
+
if (!client) return;
|
|
64
65
|
const newAssignments = await client.getAssignedTests();
|
|
65
66
|
setAssignments(newAssignments);
|
|
66
67
|
}, [client]);
|
|
67
|
-
const initializeBugBear = (0, import_react.useCallback)(async () => {
|
|
68
|
+
const initializeBugBear = (0, import_react.useCallback)(async (bugBearClient) => {
|
|
68
69
|
setIsLoading(true);
|
|
69
70
|
try {
|
|
70
71
|
const [qaEnabled, info] = await Promise.all([
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
bugBearClient.isQAEnabled(),
|
|
73
|
+
bugBearClient.getTesterInfo()
|
|
73
74
|
]);
|
|
74
75
|
console.log("BugBear: Init complete", { qaEnabled, testerInfo: info });
|
|
75
76
|
setIsQAEnabled(qaEnabled);
|
|
76
77
|
setTesterInfo(info);
|
|
77
78
|
setIsTester(!!info);
|
|
78
79
|
if (info && qaEnabled) {
|
|
79
|
-
await
|
|
80
|
+
const newAssignments = await bugBearClient.getAssignedTests();
|
|
81
|
+
setAssignments(newAssignments);
|
|
80
82
|
}
|
|
81
83
|
} catch (err) {
|
|
82
84
|
console.error("BugBear: Init error", err);
|
|
83
85
|
} finally {
|
|
84
86
|
setIsLoading(false);
|
|
85
87
|
}
|
|
86
|
-
}, [
|
|
88
|
+
}, []);
|
|
87
89
|
const refreshTesterStatus = (0, import_react.useCallback)(async () => {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
+
const freshClient = (0, import_core.createBugBear)(config);
|
|
91
|
+
setClient(freshClient);
|
|
92
|
+
await initializeBugBear(freshClient);
|
|
93
|
+
}, [config, initializeBugBear]);
|
|
90
94
|
(0, import_react.useEffect)(() => {
|
|
91
95
|
if (enabled && !hasInitialized.current) {
|
|
92
96
|
hasInitialized.current = true;
|
|
93
|
-
|
|
97
|
+
const newClient = (0, import_core.createBugBear)(config);
|
|
98
|
+
setClient(newClient);
|
|
99
|
+
initializeBugBear(newClient);
|
|
94
100
|
}
|
|
95
|
-
}, [enabled, initializeBugBear]);
|
|
101
|
+
}, [enabled, config, initializeBugBear]);
|
|
96
102
|
const currentAssignment = assignments.find(
|
|
97
103
|
(a) => a.status === "in_progress"
|
|
98
104
|
) || assignments[0] || null;
|
package/dist/index.mjs
CHANGED
|
@@ -23,7 +23,7 @@ function useBugBear() {
|
|
|
23
23
|
return useContext(BugBearContext);
|
|
24
24
|
}
|
|
25
25
|
function BugBearProvider({ config, children, enabled = true }) {
|
|
26
|
-
const [client] = useState(
|
|
26
|
+
const [client, setClient] = useState(null);
|
|
27
27
|
const [isTester, setIsTester] = useState(false);
|
|
28
28
|
const [isQAEnabled, setIsQAEnabled] = useState(false);
|
|
29
29
|
const [testerInfo, setTesterInfo] = useState(null);
|
|
@@ -31,38 +31,44 @@ function BugBearProvider({ config, children, enabled = true }) {
|
|
|
31
31
|
const [isLoading, setIsLoading] = useState(true);
|
|
32
32
|
const hasInitialized = useRef(false);
|
|
33
33
|
const refreshAssignments = useCallback(async () => {
|
|
34
|
+
if (!client) return;
|
|
34
35
|
const newAssignments = await client.getAssignedTests();
|
|
35
36
|
setAssignments(newAssignments);
|
|
36
37
|
}, [client]);
|
|
37
|
-
const initializeBugBear = useCallback(async () => {
|
|
38
|
+
const initializeBugBear = useCallback(async (bugBearClient) => {
|
|
38
39
|
setIsLoading(true);
|
|
39
40
|
try {
|
|
40
41
|
const [qaEnabled, info] = await Promise.all([
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
bugBearClient.isQAEnabled(),
|
|
43
|
+
bugBearClient.getTesterInfo()
|
|
43
44
|
]);
|
|
44
45
|
console.log("BugBear: Init complete", { qaEnabled, testerInfo: info });
|
|
45
46
|
setIsQAEnabled(qaEnabled);
|
|
46
47
|
setTesterInfo(info);
|
|
47
48
|
setIsTester(!!info);
|
|
48
49
|
if (info && qaEnabled) {
|
|
49
|
-
await
|
|
50
|
+
const newAssignments = await bugBearClient.getAssignedTests();
|
|
51
|
+
setAssignments(newAssignments);
|
|
50
52
|
}
|
|
51
53
|
} catch (err) {
|
|
52
54
|
console.error("BugBear: Init error", err);
|
|
53
55
|
} finally {
|
|
54
56
|
setIsLoading(false);
|
|
55
57
|
}
|
|
56
|
-
}, [
|
|
58
|
+
}, []);
|
|
57
59
|
const refreshTesterStatus = useCallback(async () => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
+
const freshClient = createBugBear(config);
|
|
61
|
+
setClient(freshClient);
|
|
62
|
+
await initializeBugBear(freshClient);
|
|
63
|
+
}, [config, initializeBugBear]);
|
|
60
64
|
useEffect(() => {
|
|
61
65
|
if (enabled && !hasInitialized.current) {
|
|
62
66
|
hasInitialized.current = true;
|
|
63
|
-
|
|
67
|
+
const newClient = createBugBear(config);
|
|
68
|
+
setClient(newClient);
|
|
69
|
+
initializeBugBear(newClient);
|
|
64
70
|
}
|
|
65
|
-
}, [enabled, initializeBugBear]);
|
|
71
|
+
}, [enabled, config, initializeBugBear]);
|
|
66
72
|
const currentAssignment = assignments.find(
|
|
67
73
|
(a) => a.status === "in_progress"
|
|
68
74
|
) || assignments[0] || null;
|