@cstar.help/react 0.1.1 → 0.3.0

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.cjs CHANGED
@@ -231,9 +231,7 @@ function useMessages(ticketId) {
231
231
  try {
232
232
  const msg = await client.messages.send(ticketId, content);
233
233
  seenIdsRef.current.add(msg.id);
234
- setMessages(
235
- (prev) => prev.map((m) => m.id === optimistic.id ? msg : m)
236
- );
234
+ setMessages((prev) => prev.map((m) => m.id === optimistic.id ? msg : m));
237
235
  return msg;
238
236
  } catch (err) {
239
237
  setMessages((prev) => prev.filter((m) => m.id !== optimistic.id));
@@ -414,6 +412,13 @@ function useArticle(slug) {
414
412
  }
415
413
  }
416
414
  }, [client, slug]);
415
+ const recordView = (0, import_react10.useCallback)(async () => {
416
+ if (!slug) return;
417
+ try {
418
+ await client.recordView(slug);
419
+ } catch {
420
+ }
421
+ }, [client, slug]);
417
422
  (0, import_react10.useEffect)(() => {
418
423
  mountedRef.current = true;
419
424
  if (!slug) {
@@ -426,7 +431,7 @@ function useArticle(slug) {
426
431
  mountedRef.current = false;
427
432
  };
428
433
  }, [slug, refresh]);
429
- return { article, isLoading, error, refresh };
434
+ return { article, isLoading, error, refresh, recordView };
430
435
  }
431
436
 
432
437
  // src/library/useArticleSearch.ts
package/dist/index.d.cts CHANGED
@@ -185,6 +185,8 @@ interface UseArticleReturn {
185
185
  error: Error | null;
186
186
  /** Re-fetch the article. */
187
187
  refresh: () => Promise<void>;
188
+ /** Record a view for this article. Call once when the article page mounts. */
189
+ recordView: () => Promise<void>;
188
190
  }
189
191
  /**
190
192
  * Fetch a single article by slug.
package/dist/index.d.ts CHANGED
@@ -185,6 +185,8 @@ interface UseArticleReturn {
185
185
  error: Error | null;
186
186
  /** Re-fetch the article. */
187
187
  refresh: () => Promise<void>;
188
+ /** Record a view for this article. Call once when the article page mounts. */
189
+ recordView: () => Promise<void>;
188
190
  }
189
191
  /**
190
192
  * Fetch a single article by slug.
package/dist/index.js CHANGED
@@ -192,9 +192,7 @@ function useMessages(ticketId) {
192
192
  try {
193
193
  const msg = await client.messages.send(ticketId, content);
194
194
  seenIdsRef.current.add(msg.id);
195
- setMessages(
196
- (prev) => prev.map((m) => m.id === optimistic.id ? msg : m)
197
- );
195
+ setMessages((prev) => prev.map((m) => m.id === optimistic.id ? msg : m));
198
196
  return msg;
199
197
  } catch (err) {
200
198
  setMessages((prev) => prev.filter((m) => m.id !== optimistic.id));
@@ -375,6 +373,13 @@ function useArticle(slug) {
375
373
  }
376
374
  }
377
375
  }, [client, slug]);
376
+ const recordView = useCallback7(async () => {
377
+ if (!slug) return;
378
+ try {
379
+ await client.recordView(slug);
380
+ } catch {
381
+ }
382
+ }, [client, slug]);
378
383
  useEffect7(() => {
379
384
  mountedRef.current = true;
380
385
  if (!slug) {
@@ -387,7 +392,7 @@ function useArticle(slug) {
387
392
  mountedRef.current = false;
388
393
  };
389
394
  }, [slug, refresh]);
390
- return { article, isLoading, error, refresh };
395
+ return { article, isLoading, error, refresh, recordView };
391
396
  }
392
397
 
393
398
  // src/library/useArticleSearch.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cstar.help/react",
3
- "version": "0.1.1",
3
+ "version": "0.3.0",
4
4
  "description": "React hooks for the cStar customer support platform",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "peerDependencies": {
32
32
  "react": ">=18.0.0",
33
- "@cstar.help/js": ">=0.1.0"
33
+ "@cstar.help/js": ">=0.2.0"
34
34
  },
35
35
  "devDependencies": {
36
36
  "react": "^18.3.1",