@dashx/react 0.3.5 → 0.3.6
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.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var E=Object.create;var
|
|
1
|
+
"use strict";var E=Object.create;var i=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var U=(e,s)=>{for(var o in s)i(e,o,{get:s[o],enumerable:!0})},M=(e,s,o,p)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of S(s))!D.call(e,n)&&n!==o&&i(e,n,{get:()=>s[n],enumerable:!(p=R(s,n))||p.enumerable});return e};var u=(e,s,o)=>(o=e!=null?E(w(e)):{},M(s||!e||!e.__esModule?i(o,"default",{value:e,enumerable:!0}):o,e)),X=e=>M(i({},"__esModule",{value:!0}),e);var W={};U(W,{default:()=>C});module.exports=X(W);var A=u(require("react-hot-toast")),r=require("react"),c=require("@dashx/browser"),f=u(require("./use-dashx-provider.js")),h=require("../providers/DashXProvider.js");const _=()=>{let e=(0,f.default)();const{subscribe:s}=(0,h.useWebSocket)(),[o,p]=(0,r.useState)([]),[n,k]=(0,r.useState)(null),[g,l]=(0,r.useState)(!1),[m,d]=(0,r.useState)(!1),b=a=>e.trackMessage({id:a,status:"READ"}).catch(t=>{console.error("DashX: failed to mark in-app message as read",t)}),I=a=>e.trackMessage({id:a,status:"UNREAD"}).catch(t=>{console.error("DashX: failed to mark in-app message as unread",t)}),y=()=>e.trackAllMessages().catch(a=>{console.error("DashX: failed to mark all in-app messages as read",a)}),P=async()=>{if(!(m||!g)){d(!0);try{const{hasMore:a}=await e.fetchMoreInAppMessages();l(a)}catch(a){console.error("DashX: failed to fetch more in-app messages",a)}finally{d(!1)}}};return(0,r.useEffect)(()=>{e.watchFetchInAppMessages(a=>{p(a),a.length<=c.IN_APP_MESSAGES_PAGE_SIZE&&l(a.length===c.IN_APP_MESSAGES_PAGE_SIZE)}),e.watchFetchInAppMessagesAggregate(k)},[e]),(0,r.useEffect)(()=>s(t=>{t?.type===c.WebsocketMessage.IN_APP_MESSAGE&&(0,A.default)(t.data.renderedContent.body)}),[s]),{messages:o,unreadMessagesCount:n,hasMore:g,isLoadingMore:m,loadMore:P,markMessageAsRead:b,markMessageAsUnread:I,markAllMessagesAsRead:y}};var C=_;
|
|
2
2
|
//# sourceMappingURL=use-in-app.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/use-in-app.ts"],
|
|
4
|
-
"sourcesContent": ["import toast from 'react-hot-toast';\nimport { useEffect, useState } from 'react';\nimport { WebsocketMessage, IN_APP_MESSAGES_PAGE_SIZE } from '@dashx/browser';\nimport type { InAppMessages, WebsocketMessageType } from '@dashx/browser';\n\nimport useDashXProvider from './use-dashx-provider.js';\nimport { useWebSocket } from '../providers/DashXProvider.js';\n\ntype UseInAppHookResponse = {\n messages: InAppMessages;\n unreadMessagesCount: number | null;\n hasMore: boolean;\n isLoadingMore: boolean;\n loadMore: () => Promise<void>;\n markMessageAsRead: (id: string) => Promise<any>;\n markMessageAsUnread: (id: string) => Promise<any>;\n markAllMessagesAsRead: () => Promise<any>;\n};\n\nconst useInApp = (): UseInAppHookResponse => {\n let dashX = useDashXProvider();\n const { subscribe } = useWebSocket();\n const [messages, setMessages] = useState<InAppMessages>([]);\n const [unreadMessagesCount, setUnreadMessagesCount] = useState<number | null>(null);\n const [hasMore, setHasMore] = useState(false);\n const [isLoadingMore, setIsLoadingMore] = useState(false);\n\n const markMessageAsRead = (id: string)
|
|
5
|
-
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkB,8BAClBC,EAAoC,iBACpCC,EAA4D,0BAG5DC,EAA6B,sCAC7BC,EAA6B,yCAa7B,MAAMC,EAAW,IAA4B,CAC3C,IAAIC,KAAQ,EAAAC,SAAiB,EAC7B,KAAM,CAAE,UAAAC,CAAU,KAAI,gBAAa,EAC7B,CAACC,EAAUC,CAAW,KAAI,YAAwB,CAAC,CAAC,EACpD,CAACC,EAAqBC,CAAsB,KAAI,YAAwB,IAAI,EAC5E,CAACC,EAASC,CAAU,KAAI,YAAS,EAAK,EACtC,CAACC,EAAeC,CAAgB,KAAI,YAAS,EAAK,EAElDC,EAAqBC,
|
|
6
|
-
"names": ["use_in_app_exports", "__export", "use_in_app_default", "__toCommonJS", "import_react_hot_toast", "import_react", "import_browser", "import_use_dashx_provider", "import_DashXProvider", "useInApp", "dashX", "useDashXProvider", "subscribe", "messages", "setMessages", "unreadMessagesCount", "setUnreadMessagesCount", "hasMore", "setHasMore", "isLoadingMore", "setIsLoadingMore", "markMessageAsRead", "id", "markMessageAsUnread", "markAllMessagesAsRead", "loadMore", "more", "nextMessages", "message", "toast"]
|
|
4
|
+
"sourcesContent": ["import toast from 'react-hot-toast';\nimport { useEffect, useState } from 'react';\nimport { WebsocketMessage, IN_APP_MESSAGES_PAGE_SIZE } from '@dashx/browser';\nimport type { InAppMessages, WebsocketMessageType } from '@dashx/browser';\n\nimport useDashXProvider from './use-dashx-provider.js';\nimport { useWebSocket } from '../providers/DashXProvider.js';\n\ntype UseInAppHookResponse = {\n messages: InAppMessages;\n unreadMessagesCount: number | null;\n hasMore: boolean;\n isLoadingMore: boolean;\n loadMore: () => Promise<void>;\n markMessageAsRead: (id: string) => Promise<any>;\n markMessageAsUnread: (id: string) => Promise<any>;\n markAllMessagesAsRead: () => Promise<any>;\n};\n\nconst useInApp = (): UseInAppHookResponse => {\n let dashX = useDashXProvider();\n const { subscribe } = useWebSocket();\n const [messages, setMessages] = useState<InAppMessages>([]);\n const [unreadMessagesCount, setUnreadMessagesCount] = useState<number | null>(null);\n const [hasMore, setHasMore] = useState(false);\n const [isLoadingMore, setIsLoadingMore] = useState(false);\n\n const markMessageAsRead = (id: string) =>\n dashX.trackMessage({ id, status: 'READ' }).catch((error: unknown) => {\n console.error('DashX: failed to mark in-app message as read', error);\n });\n\n const markMessageAsUnread = (id: string) =>\n dashX.trackMessage({ id, status: 'UNREAD' }).catch((error: unknown) => {\n console.error('DashX: failed to mark in-app message as unread', error);\n });\n\n const markAllMessagesAsRead = () =>\n dashX.trackAllMessages().catch((error: unknown) => {\n console.error('DashX: failed to mark all in-app messages as read', error);\n });\n\n const loadMore = async () => {\n if (isLoadingMore || !hasMore) return;\n setIsLoadingMore(true);\n try {\n const { hasMore: more } = await dashX.fetchMoreInAppMessages();\n setHasMore(more);\n } catch (error) {\n // hasMore stays true so a later scroll retries the page.\n console.error('DashX: failed to fetch more in-app messages', error);\n } finally {\n setIsLoadingMore(false);\n }\n };\n\n useEffect(() => {\n // Set up in-app message watchers (automatically refetch on WebSocket reconnection)\n dashX.watchFetchInAppMessages((nextMessages) => {\n setMessages(nextMessages);\n // While the list is a single page (initial load, empty inbox, or a reconnect\n // refetch of page 1), a full page implies more; past that, loadMore owns hasMore.\n if (nextMessages.length <= IN_APP_MESSAGES_PAGE_SIZE) {\n setHasMore(nextMessages.length === IN_APP_MESSAGES_PAGE_SIZE);\n }\n });\n dashX.watchFetchInAppMessagesAggregate(setUnreadMessagesCount);\n }, [dashX]);\n\n useEffect(() => {\n // Subscribe to WebSocket messages for in-app messages\n const unsubscribe = subscribe((message: WebsocketMessageType) => {\n // Handle only IN_APP_MESSAGE for toast display\n // The client handles all other message processing internally\n if (message?.type === WebsocketMessage.IN_APP_MESSAGE) {\n toast(message.data.renderedContent.body);\n }\n });\n\n return unsubscribe;\n }, [subscribe]);\n\n return {\n messages,\n unreadMessagesCount,\n hasMore,\n isLoadingMore,\n loadMore,\n markMessageAsRead,\n markMessageAsUnread,\n markAllMessagesAsRead,\n };\n};\n\nexport default useInApp;\n"],
|
|
5
|
+
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC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EAAG,CAACN,CAAK,CAAC,KAEV,aAAU,IAEYE,EAAWiB,GAAkC,CAG3DA,GAAS,OAAS,mBAAiB,mBACrC,EAAAC,SAAMD,EAAQ,KAAK,gBAAgB,IAAI,CAE3C,CAAC,EAGA,CAACjB,CAAS,CAAC,EAEP,CACL,SAAAC,EACA,oBAAAE,EACA,QAAAE,EACA,cAAAE,EACA,SAAAO,EACA,kBAAAL,EACA,oBAAAG,EACA,sBAAAC,CACF,CACF,EAEA,IAAOvB,EAAQO",
|
|
6
|
+
"names": ["use_in_app_exports", "__export", "use_in_app_default", "__toCommonJS", "import_react_hot_toast", "import_react", "import_browser", "import_use_dashx_provider", "import_DashXProvider", "useInApp", "dashX", "useDashXProvider", "subscribe", "messages", "setMessages", "unreadMessagesCount", "setUnreadMessagesCount", "hasMore", "setHasMore", "isLoadingMore", "setIsLoadingMore", "markMessageAsRead", "id", "error", "markMessageAsUnread", "markAllMessagesAsRead", "loadMore", "more", "nextMessages", "message", "toast"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import k from"react-hot-toast";import{useEffect as
|
|
1
|
+
import k from"react-hot-toast";import{useEffect as i,useState as o}from"react";import{WebsocketMessage as b,IN_APP_MESSAGES_PAGE_SIZE as g}from"@dashx/browser";import I from"./use-dashx-provider.js";import{useWebSocket as y}from"../providers/DashXProvider.js";const P=()=>{let s=I();const{subscribe:r}=y(),[l,m]=o([]),[d,M]=o(null),[n,t]=o(!1),[c,p]=o(!1),u=e=>s.trackMessage({id:e,status:"READ"}).catch(a=>{console.error("DashX: failed to mark in-app message as read",a)}),A=e=>s.trackMessage({id:e,status:"UNREAD"}).catch(a=>{console.error("DashX: failed to mark in-app message as unread",a)}),f=()=>s.trackAllMessages().catch(e=>{console.error("DashX: failed to mark all in-app messages as read",e)}),h=async()=>{if(!(c||!n)){p(!0);try{const{hasMore:e}=await s.fetchMoreInAppMessages();t(e)}catch(e){console.error("DashX: failed to fetch more in-app messages",e)}finally{p(!1)}}};return i(()=>{s.watchFetchInAppMessages(e=>{m(e),e.length<=g&&t(e.length===g)}),s.watchFetchInAppMessagesAggregate(M)},[s]),i(()=>r(a=>{a?.type===b.IN_APP_MESSAGE&&k(a.data.renderedContent.body)}),[r]),{messages:l,unreadMessagesCount:d,hasMore:n,isLoadingMore:c,loadMore:h,markMessageAsRead:u,markMessageAsUnread:A,markAllMessagesAsRead:f}};var U=P;export{U as default};
|
|
2
2
|
//# sourceMappingURL=use-in-app.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/use-in-app.ts"],
|
|
4
|
-
"sourcesContent": ["import toast from 'react-hot-toast';\nimport { useEffect, useState } from 'react';\nimport { WebsocketMessage, IN_APP_MESSAGES_PAGE_SIZE } from '@dashx/browser';\nimport type { InAppMessages, WebsocketMessageType } from '@dashx/browser';\n\nimport useDashXProvider from './use-dashx-provider.js';\nimport { useWebSocket } from '../providers/DashXProvider.js';\n\ntype UseInAppHookResponse = {\n messages: InAppMessages;\n unreadMessagesCount: number | null;\n hasMore: boolean;\n isLoadingMore: boolean;\n loadMore: () => Promise<void>;\n markMessageAsRead: (id: string) => Promise<any>;\n markMessageAsUnread: (id: string) => Promise<any>;\n markAllMessagesAsRead: () => Promise<any>;\n};\n\nconst useInApp = (): UseInAppHookResponse => {\n let dashX = useDashXProvider();\n const { subscribe } = useWebSocket();\n const [messages, setMessages] = useState<InAppMessages>([]);\n const [unreadMessagesCount, setUnreadMessagesCount] = useState<number | null>(null);\n const [hasMore, setHasMore] = useState(false);\n const [isLoadingMore, setIsLoadingMore] = useState(false);\n\n const markMessageAsRead = (id: string)
|
|
5
|
-
"mappings": "AAAA,OAAOA,MAAW,kBAClB,OAAS,aAAAC,EAAW,YAAAC,MAAgB,QACpC,OAAS,oBAAAC,EAAkB,6BAAAC,MAAiC,iBAG5D,OAAOC,MAAsB,0BAC7B,OAAS,gBAAAC,MAAoB,gCAa7B,MAAMC,EAAW,IAA4B,CAC3C,IAAIC,EAAQH,EAAiB,EAC7B,KAAM,CAAE,UAAAI,CAAU,EAAIH,EAAa,EAC7B,CAACI,EAAUC,CAAW,EAAIT,EAAwB,CAAC,CAAC,EACpD,CAACU,EAAqBC,CAAsB,EAAIX,EAAwB,IAAI,EAC5E,CAACY,EAASC,CAAU,EAAIb,EAAS,EAAK,EACtC,CAACc,EAAeC,CAAgB,EAAIf,EAAS,EAAK,EAElDgB,EAAqBC,
|
|
6
|
-
"names": ["toast", "useEffect", "useState", "WebsocketMessage", "IN_APP_MESSAGES_PAGE_SIZE", "useDashXProvider", "useWebSocket", "useInApp", "dashX", "subscribe", "messages", "setMessages", "unreadMessagesCount", "setUnreadMessagesCount", "hasMore", "setHasMore", "isLoadingMore", "setIsLoadingMore", "markMessageAsRead", "id", "markMessageAsUnread", "markAllMessagesAsRead", "loadMore", "more", "nextMessages", "message", "use_in_app_default"]
|
|
4
|
+
"sourcesContent": ["import toast from 'react-hot-toast';\nimport { useEffect, useState } from 'react';\nimport { WebsocketMessage, IN_APP_MESSAGES_PAGE_SIZE } from '@dashx/browser';\nimport type { InAppMessages, WebsocketMessageType } from '@dashx/browser';\n\nimport useDashXProvider from './use-dashx-provider.js';\nimport { useWebSocket } from '../providers/DashXProvider.js';\n\ntype UseInAppHookResponse = {\n messages: InAppMessages;\n unreadMessagesCount: number | null;\n hasMore: boolean;\n isLoadingMore: boolean;\n loadMore: () => Promise<void>;\n markMessageAsRead: (id: string) => Promise<any>;\n markMessageAsUnread: (id: string) => Promise<any>;\n markAllMessagesAsRead: () => Promise<any>;\n};\n\nconst useInApp = (): UseInAppHookResponse => {\n let dashX = useDashXProvider();\n const { subscribe } = useWebSocket();\n const [messages, setMessages] = useState<InAppMessages>([]);\n const [unreadMessagesCount, setUnreadMessagesCount] = useState<number | null>(null);\n const [hasMore, setHasMore] = useState(false);\n const [isLoadingMore, setIsLoadingMore] = useState(false);\n\n const markMessageAsRead = (id: string) =>\n dashX.trackMessage({ id, status: 'READ' }).catch((error: unknown) => {\n console.error('DashX: failed to mark in-app message as read', error);\n });\n\n const markMessageAsUnread = (id: string) =>\n dashX.trackMessage({ id, status: 'UNREAD' }).catch((error: unknown) => {\n console.error('DashX: failed to mark in-app message as unread', error);\n });\n\n const markAllMessagesAsRead = () =>\n dashX.trackAllMessages().catch((error: unknown) => {\n console.error('DashX: failed to mark all in-app messages as read', error);\n });\n\n const loadMore = async () => {\n if (isLoadingMore || !hasMore) return;\n setIsLoadingMore(true);\n try {\n const { hasMore: more } = await dashX.fetchMoreInAppMessages();\n setHasMore(more);\n } catch (error) {\n // hasMore stays true so a later scroll retries the page.\n console.error('DashX: failed to fetch more in-app messages', error);\n } finally {\n setIsLoadingMore(false);\n }\n };\n\n useEffect(() => {\n // Set up in-app message watchers (automatically refetch on WebSocket reconnection)\n dashX.watchFetchInAppMessages((nextMessages) => {\n setMessages(nextMessages);\n // While the list is a single page (initial load, empty inbox, or a reconnect\n // refetch of page 1), a full page implies more; past that, loadMore owns hasMore.\n if (nextMessages.length <= IN_APP_MESSAGES_PAGE_SIZE) {\n setHasMore(nextMessages.length === IN_APP_MESSAGES_PAGE_SIZE);\n }\n });\n dashX.watchFetchInAppMessagesAggregate(setUnreadMessagesCount);\n }, [dashX]);\n\n useEffect(() => {\n // Subscribe to WebSocket messages for in-app messages\n const unsubscribe = subscribe((message: WebsocketMessageType) => {\n // Handle only IN_APP_MESSAGE for toast display\n // The client handles all other message processing internally\n if (message?.type === WebsocketMessage.IN_APP_MESSAGE) {\n toast(message.data.renderedContent.body);\n }\n });\n\n return unsubscribe;\n }, [subscribe]);\n\n return {\n messages,\n unreadMessagesCount,\n hasMore,\n isLoadingMore,\n loadMore,\n markMessageAsRead,\n markMessageAsUnread,\n markAllMessagesAsRead,\n };\n};\n\nexport default useInApp;\n"],
|
|
5
|
+
"mappings": "AAAA,OAAOA,MAAW,kBAClB,OAAS,aAAAC,EAAW,YAAAC,MAAgB,QACpC,O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AAG,CAACL,CAAK,CAAC,EAEVP,EAAU,IAEYQ,EAAWiB,GAAkC,CAG3DA,GAAS,OAASvB,EAAiB,gBACrCH,EAAM0B,EAAQ,KAAK,gBAAgB,IAAI,CAE3C,CAAC,EAGA,CAACjB,CAAS,CAAC,EAEP,CACL,SAAAC,EACA,oBAAAE,EACA,QAAAE,EACA,cAAAE,EACA,SAAAO,EACA,kBAAAL,EACA,oBAAAG,EACA,sBAAAC,CACF,CACF,EAEA,IAAOK,EAAQpB",
|
|
6
|
+
"names": ["toast", "useEffect", "useState", "WebsocketMessage", "IN_APP_MESSAGES_PAGE_SIZE", "useDashXProvider", "useWebSocket", "useInApp", "dashX", "subscribe", "messages", "setMessages", "unreadMessagesCount", "setUnreadMessagesCount", "hasMore", "setHasMore", "isLoadingMore", "setIsLoadingMore", "markMessageAsRead", "id", "error", "markMessageAsUnread", "markAllMessagesAsRead", "loadMore", "more", "nextMessages", "message", "use_in_app_default"]
|
|
7
7
|
}
|
package/package.json
CHANGED
package/src/hooks/use-in-app.ts
CHANGED
|
@@ -25,14 +25,20 @@ const useInApp = (): UseInAppHookResponse => {
|
|
|
25
25
|
const [hasMore, setHasMore] = useState(false);
|
|
26
26
|
const [isLoadingMore, setIsLoadingMore] = useState(false);
|
|
27
27
|
|
|
28
|
-
const markMessageAsRead = (id: string) =>
|
|
28
|
+
const markMessageAsRead = (id: string) =>
|
|
29
|
+
dashX.trackMessage({ id, status: 'READ' }).catch((error: unknown) => {
|
|
30
|
+
console.error('DashX: failed to mark in-app message as read', error);
|
|
31
|
+
});
|
|
29
32
|
|
|
30
|
-
const markMessageAsUnread =
|
|
31
|
-
dashX.trackMessage({ id, status: 'UNREAD' })
|
|
33
|
+
const markMessageAsUnread = (id: string) =>
|
|
34
|
+
dashX.trackMessage({ id, status: 'UNREAD' }).catch((error: unknown) => {
|
|
35
|
+
console.error('DashX: failed to mark in-app message as unread', error);
|
|
36
|
+
});
|
|
32
37
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
const markAllMessagesAsRead = () =>
|
|
39
|
+
dashX.trackAllMessages().catch((error: unknown) => {
|
|
40
|
+
console.error('DashX: failed to mark all in-app messages as read', error);
|
|
41
|
+
});
|
|
36
42
|
|
|
37
43
|
const loadMore = async () => {
|
|
38
44
|
if (isLoadingMore || !hasMore) return;
|
|
@@ -40,6 +46,9 @@ const useInApp = (): UseInAppHookResponse => {
|
|
|
40
46
|
try {
|
|
41
47
|
const { hasMore: more } = await dashX.fetchMoreInAppMessages();
|
|
42
48
|
setHasMore(more);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
// hasMore stays true so a later scroll retries the page.
|
|
51
|
+
console.error('DashX: failed to fetch more in-app messages', error);
|
|
43
52
|
} finally {
|
|
44
53
|
setIsLoadingMore(false);
|
|
45
54
|
}
|
|
@@ -49,10 +58,8 @@ const useInApp = (): UseInAppHookResponse => {
|
|
|
49
58
|
// Set up in-app message watchers (automatically refetch on WebSocket reconnection)
|
|
50
59
|
dashX.watchFetchInAppMessages((nextMessages) => {
|
|
51
60
|
setMessages(nextMessages);
|
|
52
|
-
//
|
|
53
|
-
//
|
|
54
|
-
// reconnect (which resets the cache). A full first page implies more; a short or
|
|
55
|
-
// empty one doesn't. Once paged past the first page, fetchMoreInAppMessages owns it.
|
|
61
|
+
// While the list is a single page (initial load, empty inbox, or a reconnect
|
|
62
|
+
// refetch of page 1), a full page implies more; past that, loadMore owns hasMore.
|
|
56
63
|
if (nextMessages.length <= IN_APP_MESSAGES_PAGE_SIZE) {
|
|
57
64
|
setHasMore(nextMessages.length === IN_APP_MESSAGES_PAGE_SIZE);
|
|
58
65
|
}
|