@bbearai/react-native 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 +27 -18
- package/dist/index.mjs +27 -18
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -69,7 +69,7 @@ function useBugBear() {
|
|
|
69
69
|
return (0, import_react.useContext)(BugBearContext);
|
|
70
70
|
}
|
|
71
71
|
function BugBearProvider({ config, children, appVersion, enabled = true }) {
|
|
72
|
-
const [client] = (0, import_react.useState)(
|
|
72
|
+
const [client, setClient] = (0, import_react.useState)(null);
|
|
73
73
|
const [isTester, setIsTester] = (0, import_react.useState)(false);
|
|
74
74
|
const [isQAEnabled, setIsQAEnabled] = (0, import_react.useState)(false);
|
|
75
75
|
const [testerInfo, setTesterInfo] = (0, import_react.useState)(null);
|
|
@@ -77,7 +77,6 @@ function BugBearProvider({ config, children, appVersion, enabled = true }) {
|
|
|
77
77
|
const [isLoading, setIsLoading] = (0, import_react.useState)(true);
|
|
78
78
|
const [threads, setThreads] = (0, import_react.useState)([]);
|
|
79
79
|
const [unreadCount, setUnreadCount] = (0, import_react.useState)(0);
|
|
80
|
-
const [initCount, setInitCount] = (0, import_react.useState)(0);
|
|
81
80
|
const hasInitialized = (0, import_react.useRef)(false);
|
|
82
81
|
const getDeviceInfo = (0, import_react.useCallback)(() => {
|
|
83
82
|
const { width, height } = import_react_native.Dimensions.get("window");
|
|
@@ -89,19 +88,23 @@ function BugBearProvider({ config, children, appVersion, enabled = true }) {
|
|
|
89
88
|
};
|
|
90
89
|
}, [appVersion]);
|
|
91
90
|
const refreshAssignments = (0, import_react.useCallback)(async () => {
|
|
91
|
+
if (!client) return;
|
|
92
92
|
const newAssignments = await client.getAssignedTests();
|
|
93
93
|
setAssignments(newAssignments);
|
|
94
94
|
}, [client]);
|
|
95
95
|
const refreshThreads = (0, import_react.useCallback)(async () => {
|
|
96
|
+
if (!client) return;
|
|
96
97
|
const newThreads = await client.getThreadsForTester();
|
|
97
98
|
setThreads(newThreads);
|
|
98
99
|
const totalUnread = newThreads.reduce((sum, t) => sum + t.unreadCount, 0);
|
|
99
100
|
setUnreadCount(totalUnread);
|
|
100
101
|
}, [client]);
|
|
101
102
|
const getThreadMessages = (0, import_react.useCallback)(async (threadId) => {
|
|
103
|
+
if (!client) return [];
|
|
102
104
|
return client.getThreadMessages(threadId);
|
|
103
105
|
}, [client]);
|
|
104
106
|
const sendMessage = (0, import_react.useCallback)(async (threadId, content) => {
|
|
107
|
+
if (!client) return false;
|
|
105
108
|
const success = await client.sendMessage(threadId, content);
|
|
106
109
|
if (success) {
|
|
107
110
|
await refreshThreads();
|
|
@@ -109,52 +112,58 @@ function BugBearProvider({ config, children, appVersion, enabled = true }) {
|
|
|
109
112
|
return success;
|
|
110
113
|
}, [client, refreshThreads]);
|
|
111
114
|
const markAsRead = (0, import_react.useCallback)(async (threadId) => {
|
|
115
|
+
if (!client) return;
|
|
112
116
|
await client.markThreadAsRead(threadId);
|
|
113
117
|
await refreshThreads();
|
|
114
118
|
}, [client, refreshThreads]);
|
|
115
119
|
const createThread = (0, import_react.useCallback)(async (options) => {
|
|
120
|
+
if (!client) return { success: false, error: "Client not initialized" };
|
|
116
121
|
const result = await client.createThread(options);
|
|
117
122
|
if (result.success) {
|
|
118
123
|
await refreshThreads();
|
|
119
124
|
}
|
|
120
125
|
return result;
|
|
121
126
|
}, [client, refreshThreads]);
|
|
122
|
-
const initializeBugBear = (0, import_react.useCallback)(async () => {
|
|
127
|
+
const initializeBugBear = (0, import_react.useCallback)(async (bugBearClient) => {
|
|
123
128
|
setIsLoading(true);
|
|
124
129
|
try {
|
|
125
130
|
const [qaEnabled, info] = await Promise.all([
|
|
126
|
-
|
|
127
|
-
|
|
131
|
+
bugBearClient.isQAEnabled(),
|
|
132
|
+
bugBearClient.getTesterInfo()
|
|
128
133
|
]);
|
|
134
|
+
console.log("BugBear: Init complete", { qaEnabled, testerInfo: info });
|
|
129
135
|
setIsQAEnabled(qaEnabled);
|
|
130
136
|
setTesterInfo(info);
|
|
131
137
|
setIsTester(!!info);
|
|
132
138
|
if (info && qaEnabled) {
|
|
133
|
-
await Promise.all([
|
|
134
|
-
|
|
135
|
-
|
|
139
|
+
const [newAssignments, newThreads] = await Promise.all([
|
|
140
|
+
bugBearClient.getAssignedTests(),
|
|
141
|
+
bugBearClient.getThreadsForTester()
|
|
136
142
|
]);
|
|
143
|
+
setAssignments(newAssignments);
|
|
144
|
+
setThreads(newThreads);
|
|
145
|
+
const totalUnread = newThreads.reduce((sum, t) => sum + t.unreadCount, 0);
|
|
146
|
+
setUnreadCount(totalUnread);
|
|
137
147
|
}
|
|
138
148
|
} catch (err) {
|
|
139
149
|
console.error("BugBear: Init error", err);
|
|
140
150
|
} finally {
|
|
141
151
|
setIsLoading(false);
|
|
142
152
|
}
|
|
143
|
-
}, [
|
|
153
|
+
}, []);
|
|
144
154
|
const refreshTesterStatus = (0, import_react.useCallback)(async () => {
|
|
145
|
-
|
|
146
|
-
|
|
155
|
+
const freshClient = (0, import_core.createBugBear)(config);
|
|
156
|
+
setClient(freshClient);
|
|
157
|
+
await initializeBugBear(freshClient);
|
|
158
|
+
}, [config, initializeBugBear]);
|
|
147
159
|
(0, import_react.useEffect)(() => {
|
|
148
160
|
if (enabled && !hasInitialized.current) {
|
|
149
161
|
hasInitialized.current = true;
|
|
150
|
-
|
|
162
|
+
const newClient = (0, import_core.createBugBear)(config);
|
|
163
|
+
setClient(newClient);
|
|
164
|
+
initializeBugBear(newClient);
|
|
151
165
|
}
|
|
152
|
-
}, [enabled, initializeBugBear]);
|
|
153
|
-
(0, import_react.useEffect)(() => {
|
|
154
|
-
if (initCount > 0) {
|
|
155
|
-
initializeBugBear();
|
|
156
|
-
}
|
|
157
|
-
}, [initCount, initializeBugBear]);
|
|
166
|
+
}, [enabled, config, initializeBugBear]);
|
|
158
167
|
const currentAssignment = assignments.find(
|
|
159
168
|
(a) => a.status === "in_progress"
|
|
160
169
|
) || assignments[0] || null;
|
package/dist/index.mjs
CHANGED
|
@@ -33,7 +33,7 @@ function useBugBear() {
|
|
|
33
33
|
return useContext(BugBearContext);
|
|
34
34
|
}
|
|
35
35
|
function BugBearProvider({ config, children, appVersion, enabled = true }) {
|
|
36
|
-
const [client] = useState(
|
|
36
|
+
const [client, setClient] = useState(null);
|
|
37
37
|
const [isTester, setIsTester] = useState(false);
|
|
38
38
|
const [isQAEnabled, setIsQAEnabled] = useState(false);
|
|
39
39
|
const [testerInfo, setTesterInfo] = useState(null);
|
|
@@ -41,7 +41,6 @@ function BugBearProvider({ config, children, appVersion, enabled = true }) {
|
|
|
41
41
|
const [isLoading, setIsLoading] = useState(true);
|
|
42
42
|
const [threads, setThreads] = useState([]);
|
|
43
43
|
const [unreadCount, setUnreadCount] = useState(0);
|
|
44
|
-
const [initCount, setInitCount] = useState(0);
|
|
45
44
|
const hasInitialized = useRef(false);
|
|
46
45
|
const getDeviceInfo = useCallback(() => {
|
|
47
46
|
const { width, height } = Dimensions.get("window");
|
|
@@ -53,19 +52,23 @@ function BugBearProvider({ config, children, appVersion, enabled = true }) {
|
|
|
53
52
|
};
|
|
54
53
|
}, [appVersion]);
|
|
55
54
|
const refreshAssignments = useCallback(async () => {
|
|
55
|
+
if (!client) return;
|
|
56
56
|
const newAssignments = await client.getAssignedTests();
|
|
57
57
|
setAssignments(newAssignments);
|
|
58
58
|
}, [client]);
|
|
59
59
|
const refreshThreads = useCallback(async () => {
|
|
60
|
+
if (!client) return;
|
|
60
61
|
const newThreads = await client.getThreadsForTester();
|
|
61
62
|
setThreads(newThreads);
|
|
62
63
|
const totalUnread = newThreads.reduce((sum, t) => sum + t.unreadCount, 0);
|
|
63
64
|
setUnreadCount(totalUnread);
|
|
64
65
|
}, [client]);
|
|
65
66
|
const getThreadMessages = useCallback(async (threadId) => {
|
|
67
|
+
if (!client) return [];
|
|
66
68
|
return client.getThreadMessages(threadId);
|
|
67
69
|
}, [client]);
|
|
68
70
|
const sendMessage = useCallback(async (threadId, content) => {
|
|
71
|
+
if (!client) return false;
|
|
69
72
|
const success = await client.sendMessage(threadId, content);
|
|
70
73
|
if (success) {
|
|
71
74
|
await refreshThreads();
|
|
@@ -73,52 +76,58 @@ function BugBearProvider({ config, children, appVersion, enabled = true }) {
|
|
|
73
76
|
return success;
|
|
74
77
|
}, [client, refreshThreads]);
|
|
75
78
|
const markAsRead = useCallback(async (threadId) => {
|
|
79
|
+
if (!client) return;
|
|
76
80
|
await client.markThreadAsRead(threadId);
|
|
77
81
|
await refreshThreads();
|
|
78
82
|
}, [client, refreshThreads]);
|
|
79
83
|
const createThread = useCallback(async (options) => {
|
|
84
|
+
if (!client) return { success: false, error: "Client not initialized" };
|
|
80
85
|
const result = await client.createThread(options);
|
|
81
86
|
if (result.success) {
|
|
82
87
|
await refreshThreads();
|
|
83
88
|
}
|
|
84
89
|
return result;
|
|
85
90
|
}, [client, refreshThreads]);
|
|
86
|
-
const initializeBugBear = useCallback(async () => {
|
|
91
|
+
const initializeBugBear = useCallback(async (bugBearClient) => {
|
|
87
92
|
setIsLoading(true);
|
|
88
93
|
try {
|
|
89
94
|
const [qaEnabled, info] = await Promise.all([
|
|
90
|
-
|
|
91
|
-
|
|
95
|
+
bugBearClient.isQAEnabled(),
|
|
96
|
+
bugBearClient.getTesterInfo()
|
|
92
97
|
]);
|
|
98
|
+
console.log("BugBear: Init complete", { qaEnabled, testerInfo: info });
|
|
93
99
|
setIsQAEnabled(qaEnabled);
|
|
94
100
|
setTesterInfo(info);
|
|
95
101
|
setIsTester(!!info);
|
|
96
102
|
if (info && qaEnabled) {
|
|
97
|
-
await Promise.all([
|
|
98
|
-
|
|
99
|
-
|
|
103
|
+
const [newAssignments, newThreads] = await Promise.all([
|
|
104
|
+
bugBearClient.getAssignedTests(),
|
|
105
|
+
bugBearClient.getThreadsForTester()
|
|
100
106
|
]);
|
|
107
|
+
setAssignments(newAssignments);
|
|
108
|
+
setThreads(newThreads);
|
|
109
|
+
const totalUnread = newThreads.reduce((sum, t) => sum + t.unreadCount, 0);
|
|
110
|
+
setUnreadCount(totalUnread);
|
|
101
111
|
}
|
|
102
112
|
} catch (err) {
|
|
103
113
|
console.error("BugBear: Init error", err);
|
|
104
114
|
} finally {
|
|
105
115
|
setIsLoading(false);
|
|
106
116
|
}
|
|
107
|
-
}, [
|
|
117
|
+
}, []);
|
|
108
118
|
const refreshTesterStatus = useCallback(async () => {
|
|
109
|
-
|
|
110
|
-
|
|
119
|
+
const freshClient = createBugBear(config);
|
|
120
|
+
setClient(freshClient);
|
|
121
|
+
await initializeBugBear(freshClient);
|
|
122
|
+
}, [config, initializeBugBear]);
|
|
111
123
|
useEffect(() => {
|
|
112
124
|
if (enabled && !hasInitialized.current) {
|
|
113
125
|
hasInitialized.current = true;
|
|
114
|
-
|
|
126
|
+
const newClient = createBugBear(config);
|
|
127
|
+
setClient(newClient);
|
|
128
|
+
initializeBugBear(newClient);
|
|
115
129
|
}
|
|
116
|
-
}, [enabled, initializeBugBear]);
|
|
117
|
-
useEffect(() => {
|
|
118
|
-
if (initCount > 0) {
|
|
119
|
-
initializeBugBear();
|
|
120
|
-
}
|
|
121
|
-
}, [initCount, initializeBugBear]);
|
|
130
|
+
}, [enabled, config, initializeBugBear]);
|
|
122
131
|
const currentAssignment = assignments.find(
|
|
123
132
|
(a) => a.status === "in_progress"
|
|
124
133
|
) || assignments[0] || null;
|