@stream-io/feeds-client 1.1.0 → 1.2.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.
@@ -1,498 +1,500 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const reactBindings = require("@stream-io/state-store/react-bindings");
4
- const react = require("react");
5
- const feedsClient = require("../feeds-client-C1c6lcS3.js");
6
- const jsxRuntime = require("react/jsx-runtime");
7
- const useCreateFeedsClient = ({
8
- apiKey,
9
- tokenOrProvider,
10
- userData: userDataOrAnonymous,
11
- options
12
- }) => {
13
- const userData = userDataOrAnonymous === "anonymous" ? void 0 : userDataOrAnonymous;
14
- if (userDataOrAnonymous !== "anonymous" && !tokenOrProvider) {
15
- throw new Error(
16
- 'Token provider can only be omitted when connecting anonymous user. If you want to connect as a guest, provide "guest" instead of a token provider.'
17
- );
18
- }
19
- const [client, setClient] = react.useState(null);
20
- const [error, setError] = react.useState(null);
21
- const [cachedUserData, setCachedUserData] = react.useState(userData);
22
- const [cachedOptions] = react.useState(options);
23
- if (error) {
24
- throw error;
25
- }
26
- if (userData?.id !== cachedUserData?.id) {
27
- setCachedUserData(userData);
28
- }
29
- react.useEffect(() => {
30
- const _client = new feedsClient.FeedsClient(apiKey, cachedOptions);
31
- let connectionPromise;
32
- if (!cachedUserData) {
33
- connectionPromise = _client.connectAnonymous();
34
- } else if (tokenOrProvider === "guest") {
35
- connectionPromise = _client.connectGuest({
36
- user: cachedUserData
37
- });
38
- } else {
39
- connectionPromise = _client.connectUser(cachedUserData, tokenOrProvider);
40
- }
41
- connectionPromise = connectionPromise.then(() => {
42
- setError(null);
43
- }).catch((err) => {
44
- setError(err);
45
- });
46
- setClient(_client);
47
- return () => {
48
- setClient(null);
49
- connectionPromise.then(() => {
50
- setError(null);
51
- return _client.disconnectUser();
52
- }).catch((err) => {
53
- setError(err);
54
- });
55
- };
56
- }, [apiKey, cachedUserData, cachedOptions, tokenOrProvider]);
57
- return client;
2
+ const require_feeds_client = require("../feeds-client-BP0fE4NZ.js");
3
+ let _stream_io_state_store_react_bindings = require("@stream-io/state-store/react-bindings");
4
+ let react = require("react");
5
+ let react_jsx_runtime = require("react/jsx-runtime");
6
+ //#region src/bindings/react/hooks/useCreateFeedsClient.ts
7
+ /**
8
+ * A React hook to create, connect and return an instance of `FeedsClient`.
9
+ */
10
+ var useCreateFeedsClient = ({ apiKey, tokenOrProvider, userData: userDataOrAnonymous, options }) => {
11
+ const userData = userDataOrAnonymous === "anonymous" ? void 0 : userDataOrAnonymous;
12
+ if (userDataOrAnonymous !== "anonymous" && !tokenOrProvider) throw new Error("Token provider can only be omitted when connecting anonymous user. If you want to connect as a guest, provide \"guest\" instead of a token provider.");
13
+ const [client, setClient] = (0, react.useState)(null);
14
+ const [error, setError] = (0, react.useState)(null);
15
+ const [cachedUserData, setCachedUserData] = (0, react.useState)(userData);
16
+ const [cachedOptions] = (0, react.useState)(options);
17
+ if (error) throw error;
18
+ if (userData?.id !== cachedUserData?.id) setCachedUserData(userData);
19
+ (0, react.useEffect)(() => {
20
+ const _client = new require_feeds_client.FeedsClient(apiKey, cachedOptions);
21
+ let connectionPromise;
22
+ if (!cachedUserData) connectionPromise = _client.connectAnonymous();
23
+ else if (tokenOrProvider === "guest") connectionPromise = _client.connectGuest({ user: cachedUserData });
24
+ else connectionPromise = _client.connectUser(cachedUserData, tokenOrProvider);
25
+ connectionPromise = connectionPromise.then(() => {
26
+ setError(null);
27
+ }).catch((err) => {
28
+ setError(err);
29
+ });
30
+ setClient(_client);
31
+ return () => {
32
+ setClient(null);
33
+ connectionPromise.then(() => {
34
+ setError(null);
35
+ return _client.disconnectUser();
36
+ }).catch((err) => {
37
+ setError(err);
38
+ });
39
+ };
40
+ }, [
41
+ apiKey,
42
+ cachedUserData,
43
+ cachedOptions,
44
+ tokenOrProvider
45
+ ]);
46
+ return client;
58
47
  };
59
- const StreamFeedsContext = react.createContext(void 0);
60
- const useFeedsClient = () => {
61
- return react.useContext(StreamFeedsContext);
48
+ //#endregion
49
+ //#region src/bindings/react/contexts/StreamFeedsContext.tsx
50
+ var StreamFeedsContext = (0, react.createContext)(void 0);
51
+ /**
52
+ * Hook to access the nearest FeedsClient instance.
53
+ */
54
+ var useFeedsClient = () => {
55
+ return (0, react.useContext)(StreamFeedsContext);
62
56
  };
63
- const useClientConnectedUser = () => {
64
- const client = useFeedsClient();
65
- const { user } = reactBindings.useStateStore(client?.state, selector$e) ?? {};
66
- return user;
57
+ //#endregion
58
+ //#region src/bindings/react/hooks/client-state-hooks/useClientConnectedUser.ts
59
+ /**
60
+ * A React hook that returns the currently connected user on a `FeedsClient` instance and null otherwise.
61
+ */
62
+ var useClientConnectedUser = () => {
63
+ const { user } = (0, _stream_io_state_store_react_bindings.useStateStore)(useFeedsClient()?.state, selector$14) ?? {};
64
+ return user;
67
65
  };
68
- const selector$e = (nextState) => ({
69
- user: nextState.connected_user
70
- });
71
- const useWsConnectionState = () => {
72
- const client = useFeedsClient();
73
- const { is_healthy } = reactBindings.useStateStore(client?.state, selector$d) ?? {};
74
- return { is_healthy };
66
+ var selector$14 = (nextState) => ({ user: nextState.connected_user });
67
+ //#endregion
68
+ //#region src/bindings/react/hooks/client-state-hooks/useWsConnectionState.ts
69
+ /**
70
+ * A React hook that returns the websocket connection state of `FeedsClient`.
71
+ */
72
+ var useWsConnectionState = () => {
73
+ const { is_healthy } = (0, _stream_io_state_store_react_bindings.useStateStore)(useFeedsClient()?.state, selector$13) ?? {};
74
+ return { is_healthy };
75
75
  };
76
- const selector$d = (nextState) => ({
77
- is_healthy: nextState.is_ws_connection_healthy
78
- });
79
- const StreamFeedContext = react.createContext(void 0);
80
- const useFeedContext = () => {
81
- return react.useContext(StreamFeedContext);
76
+ var selector$13 = (nextState) => ({ is_healthy: nextState.is_ws_connection_healthy });
77
+ //#endregion
78
+ //#region src/bindings/react/contexts/StreamFeedContext.tsx
79
+ var StreamFeedContext = (0, react.createContext)(void 0);
80
+ /**
81
+ * Hook to access the nearest Feed instance.
82
+ */
83
+ var useFeedContext = () => {
84
+ return (0, react.useContext)(StreamFeedContext);
82
85
  };
83
- const useStableCallback = (callback) => {
84
- const ref = react.useRef(callback);
85
- ref.current = callback;
86
- return react.useCallback((...args) => {
87
- return ref.current(...args);
88
- }, []);
86
+ //#endregion
87
+ //#region src/bindings/react/hooks/internal/useStableCallback.ts
88
+ /**
89
+ * A utility hook implementing a stable callback. It takes in an unstable method that
90
+ * is supposed to be invoked somewhere deeper in the DOM tree without making it
91
+ * change its reference every time the parent component rerenders. It will also return
92
+ * the value of the callback if it does return one.
93
+ * A common use-case would be having a function whose invocation depends on state
94
+ * somewhere high up in the DOM tree and wanting to use the same function deeper
95
+ * down, for example in a leaf node and simply using useCallback results in
96
+ * cascading dependency hell. If we wrap it in useStableCallback, we would be able
97
+ * to:
98
+ * - Use the same function as a dependency of another hook (since it is stable)
99
+ * - Still invoke it and get the latest state
100
+ *
101
+ * **Caveats:**
102
+ * - Never wrap a function that is supposed to return a React.ReactElement in
103
+ * useStableCallback, since React will not know that the DOM needs to be updated
104
+ * whenever the callback value changes (for example, renderItem from FlatList must
105
+ * never be wrapped in this hook)
106
+ * - Always prefer using a standard useCallback/stable function wherever possible
107
+ * (the purpose of useStableCallback is to bridge the gap between top level contexts
108
+ * and cascading rereders in downstream components - **not** as an escape hatch)
109
+ * @param callback - the callback we want to stabilize
110
+ */
111
+ var useStableCallback = (callback) => {
112
+ const ref = (0, react.useRef)(callback);
113
+ ref.current = callback;
114
+ return (0, react.useCallback)((...args) => {
115
+ return ref.current(...args);
116
+ }, []);
89
117
  };
90
- const useFeedActivities = (feedFromProps) => {
91
- const feedFromContext = useFeedContext();
92
- const feed = feedFromProps ?? feedFromContext;
93
- const data = reactBindings.useStateStore(feed?.state, selector$c);
94
- const loadNextPage = useStableCallback(async () => {
95
- if (!feed || !data?.has_next_page || data?.is_loading) {
96
- return;
97
- }
98
- await feed.getNextPage();
99
- });
100
- return react.useMemo(() => ({ ...data, loadNextPage }), [data, loadNextPage]);
118
+ //#endregion
119
+ //#region src/bindings/react/hooks/feed-state-hooks/useFeedActivities.ts
120
+ /**
121
+ * A React hook that returns a reactive object containing the current activities,
122
+ * loading state and whether there is a next page to paginate to or not.
123
+ */
124
+ var useFeedActivities = (feedFromProps) => {
125
+ const feedFromContext = useFeedContext();
126
+ const feed = feedFromProps ?? feedFromContext;
127
+ const data = (0, _stream_io_state_store_react_bindings.useStateStore)(feed?.state, selector$12);
128
+ const loadNextPage = useStableCallback(async () => {
129
+ if (!feed || !data?.has_next_page || data?.is_loading) return;
130
+ await feed.getNextPage();
131
+ });
132
+ return (0, react.useMemo)(() => ({
133
+ ...data,
134
+ loadNextPage
135
+ }), [data, loadNextPage]);
101
136
  };
102
- const selector$c = ({
103
- is_loading_activities,
104
- next,
105
- activities = []
106
- }) => ({
107
- is_loading: is_loading_activities,
108
- has_next_page: typeof next !== "undefined",
109
- activities
137
+ var selector$12 = ({ is_loading_activities, next, activities = [] }) => ({
138
+ is_loading: is_loading_activities,
139
+ has_next_page: typeof next !== "undefined",
140
+ activities
110
141
  });
111
- function useComments({
112
- feed: feedFromProps,
113
- parent
114
- }) {
115
- const feedFromContext = useFeedContext();
116
- const feed = feedFromProps ?? feedFromContext;
117
- const selector2 = react.useCallback(
118
- (state) => ({
119
- comments: state.comments_by_entity_id?.[parent.id]?.comments,
120
- comments_pagination: state.comments_by_entity_id?.[parent.id]?.pagination
121
- }),
122
- [parent.id]
123
- );
124
- const data = reactBindings.useStateStore(feed?.state, selector2);
125
- const loadNextPage = react.useMemo(() => {
126
- if (!feed) return void 0;
127
- return (request) => {
128
- if (feedsClient.isCommentResponse(parent)) {
129
- return feed.loadNextPageCommentReplies(parent, request);
130
- } else {
131
- return feed.loadNextPageActivityComments(parent, request);
132
- }
133
- };
134
- }, [feed, parent]);
135
- return react.useMemo(() => {
136
- if (!data) {
137
- return void 0;
138
- }
139
- return {
140
- ...data,
141
- has_next_page: feedsClient.checkHasAnotherPage(
142
- data.comments,
143
- data.comments_pagination?.next
144
- ),
145
- is_loading_next_page: data?.comments_pagination?.loading_next_page ?? false,
146
- loadNextPage
147
- };
148
- }, [data, loadNextPage]);
142
+ //#endregion
143
+ //#region src/bindings/react/hooks/feed-state-hooks/useComments.ts
144
+ function useComments({ feed: feedFromProps, parent }) {
145
+ const feedFromContext = useFeedContext();
146
+ const feed = feedFromProps ?? feedFromContext;
147
+ const selector = (0, react.useCallback)((state) => ({
148
+ comments: state.comments_by_entity_id?.[parent.id]?.comments,
149
+ comments_pagination: state.comments_by_entity_id?.[parent.id]?.pagination
150
+ }), [parent.id]);
151
+ const data = (0, _stream_io_state_store_react_bindings.useStateStore)(feed?.state, selector);
152
+ const loadNextPage = (0, react.useMemo)(() => {
153
+ if (!feed) return void 0;
154
+ return (request) => {
155
+ if (require_feeds_client.isCommentResponse(parent)) return feed.loadNextPageCommentReplies(parent, request);
156
+ else return feed.loadNextPageActivityComments(parent, request);
157
+ };
158
+ }, [feed, parent]);
159
+ return (0, react.useMemo)(() => {
160
+ if (!data) return;
161
+ return {
162
+ ...data,
163
+ has_next_page: require_feeds_client.checkHasAnotherPage(data.comments, data.comments_pagination?.next),
164
+ is_loading_next_page: data?.comments_pagination?.loading_next_page ?? false,
165
+ loadNextPage
166
+ };
167
+ }, [data, loadNextPage]);
149
168
  }
150
- const stableEmptyArray = [];
151
- const selector$b = (currentState) => {
152
- return {
153
- feedOwnCapabilities: currentState.own_capabilities ?? stableEmptyArray
154
- };
169
+ //#endregion
170
+ //#region src/bindings/react/hooks/feed-state-hooks/useOwnCapabilities.ts
171
+ var stableEmptyArray = [];
172
+ var selector$11 = (currentState) => {
173
+ return { feedOwnCapabilities: currentState.own_capabilities ?? stableEmptyArray };
155
174
  };
156
- const useOwnCapabilities = (feedFromProps) => {
157
- const client = useFeedsClient();
158
- const feedFromContext = useFeedContext();
159
- let feed = feedFromProps ?? feedFromContext;
160
- if (typeof feed === "string") {
161
- const [groupId, id] = feed.split(":");
162
- feed = groupId && id ? client?.feed(groupId, id) : void 0;
163
- }
164
- const { feedOwnCapabilities = stableEmptyArray } = reactBindings.useStateStore(feed?.state, selector$b) ?? {};
165
- return feedOwnCapabilities;
175
+ var useOwnCapabilities = (feedFromProps) => {
176
+ const client = useFeedsClient();
177
+ const feedFromContext = useFeedContext();
178
+ let feed = feedFromProps ?? feedFromContext;
179
+ if (typeof feed === "string") {
180
+ const [groupId, id] = feed.split(":");
181
+ feed = groupId && id ? client?.feed(groupId, id) : void 0;
182
+ }
183
+ const { feedOwnCapabilities = stableEmptyArray } = (0, _stream_io_state_store_react_bindings.useStateStore)(feed?.state, selector$11) ?? {};
184
+ return feedOwnCapabilities;
166
185
  };
167
- const selector$a = ({
168
- follower_count,
169
- followers,
170
- followers_pagination
171
- }) => ({
172
- follower_count,
173
- followers,
174
- followers_pagination
186
+ //#endregion
187
+ //#region src/bindings/react/hooks/feed-state-hooks/useFollowers.ts
188
+ var selector$10 = ({ follower_count, followers, followers_pagination }) => ({
189
+ follower_count,
190
+ followers,
191
+ followers_pagination
175
192
  });
176
193
  function useFollowers(feedFromProps) {
177
- const feedFromContext = useFeedContext();
178
- const feed = feedFromProps ?? feedFromContext;
179
- const data = reactBindings.useStateStore(feed?.state, selector$a);
180
- const loadNextPage = react.useCallback(
181
- (...options) => feed?.loadNextPageFollowers(...options),
182
- [feed]
183
- );
184
- return react.useMemo(() => {
185
- if (!data) {
186
- return void 0;
187
- }
188
- return {
189
- ...data,
190
- is_loading_next_page: data.followers_pagination?.loading_next_page ?? false,
191
- has_next_page: feedsClient.checkHasAnotherPage(
192
- data.followers,
193
- data.followers_pagination?.next
194
- ),
195
- loadNextPage
196
- };
197
- }, [data, loadNextPage]);
194
+ const feedFromContext = useFeedContext();
195
+ const feed = feedFromProps ?? feedFromContext;
196
+ const data = (0, _stream_io_state_store_react_bindings.useStateStore)(feed?.state, selector$10);
197
+ const loadNextPage = (0, react.useCallback)((...options) => feed?.loadNextPageFollowers(...options), [feed]);
198
+ return (0, react.useMemo)(() => {
199
+ if (!data) return;
200
+ return {
201
+ ...data,
202
+ is_loading_next_page: data.followers_pagination?.loading_next_page ?? false,
203
+ has_next_page: require_feeds_client.checkHasAnotherPage(data.followers, data.followers_pagination?.next),
204
+ loadNextPage
205
+ };
206
+ }, [data, loadNextPage]);
198
207
  }
199
- const selector$9 = ({
200
- following_count,
201
- following,
202
- following_pagination
203
- }) => ({
204
- following_count,
205
- following,
206
- following_pagination
208
+ //#endregion
209
+ //#region src/bindings/react/hooks/feed-state-hooks/useFollowing.ts
210
+ var selector$9 = ({ following_count, following, following_pagination }) => ({
211
+ following_count,
212
+ following,
213
+ following_pagination
207
214
  });
208
215
  function useFollowing(feedFromProps) {
209
- const feedFromContext = useFeedContext();
210
- const feed = feedFromProps ?? feedFromContext;
211
- const data = reactBindings.useStateStore(feed?.state, selector$9);
212
- const loadNextPage = react.useCallback(
213
- (...options) => feed?.loadNextPageFollowing(...options),
214
- [feed]
215
- );
216
- return react.useMemo(() => {
217
- if (!data) {
218
- return void 0;
219
- }
220
- return {
221
- ...data,
222
- is_loading_next_page: data.following_pagination?.loading_next_page ?? false,
223
- has_next_page: feedsClient.checkHasAnotherPage(
224
- data.following,
225
- data.following_pagination?.next
226
- ),
227
- loadNextPage
228
- };
229
- }, [data, loadNextPage]);
216
+ const feedFromContext = useFeedContext();
217
+ const feed = feedFromProps ?? feedFromContext;
218
+ const data = (0, _stream_io_state_store_react_bindings.useStateStore)(feed?.state, selector$9);
219
+ const loadNextPage = (0, react.useCallback)((...options) => feed?.loadNextPageFollowing(...options), [feed]);
220
+ return (0, react.useMemo)(() => {
221
+ if (!data) return;
222
+ return {
223
+ ...data,
224
+ is_loading_next_page: data.following_pagination?.loading_next_page ?? false,
225
+ has_next_page: require_feeds_client.checkHasAnotherPage(data.following, data.following_pagination?.next),
226
+ loadNextPage
227
+ };
228
+ }, [data, loadNextPage]);
230
229
  }
231
- const useFeedMetadata = (feedFromProps) => {
232
- const feedFromContext = useFeedContext();
233
- const feed = feedFromProps ?? feedFromContext;
234
- return reactBindings.useStateStore(feed?.state, selector$8);
230
+ //#endregion
231
+ //#region src/bindings/react/hooks/feed-state-hooks/useFeedMetadata.ts
232
+ /**
233
+ * A React hook that returns a reactive object containing some often used
234
+ * metadata for a feed.
235
+ */
236
+ var useFeedMetadata = (feedFromProps) => {
237
+ const feedFromContext = useFeedContext();
238
+ return (0, _stream_io_state_store_react_bindings.useStateStore)((feedFromProps ?? feedFromContext)?.state, selector$8);
235
239
  };
236
- const selector$8 = ({
237
- follower_count = 0,
238
- following_count = 0,
239
- created_by,
240
- created_at,
241
- updated_at
242
- }) => ({
243
- created_by,
244
- follower_count,
245
- following_count,
246
- created_at,
247
- updated_at
240
+ var selector$8 = ({ follower_count = 0, following_count = 0, created_by, created_at, updated_at }) => ({
241
+ created_by,
242
+ follower_count,
243
+ following_count,
244
+ created_at,
245
+ updated_at
248
246
  });
249
- const useOwnFollows = (feedFromProps) => {
250
- const feedFromContext = useFeedContext();
251
- const feed = feedFromProps ?? feedFromContext;
252
- return reactBindings.useStateStore(feed?.state, selector$7);
247
+ //#endregion
248
+ //#region src/bindings/react/hooks/feed-state-hooks/useOwnFollows.ts
249
+ /**
250
+ * A React hook that returns a reactive array of feeds that the current user
251
+ * owns and are following the respective feed that we are observing.
252
+ */
253
+ var useOwnFollows = (feedFromProps) => {
254
+ const feedFromContext = useFeedContext();
255
+ return (0, _stream_io_state_store_react_bindings.useStateStore)((feedFromProps ?? feedFromContext)?.state, selector$7);
253
256
  };
254
- const selector$7 = ({ own_follows }) => ({
255
- own_follows
256
- });
257
- const selector$6 = ({ notification_status }) => ({
258
- unread: notification_status?.unread ?? 0,
259
- unseen: notification_status?.unseen ?? 0,
260
- last_read_at: notification_status?.last_read_at,
261
- last_seen_at: notification_status?.last_seen_at,
262
- read_activities: notification_status?.read_activities,
263
- seen_activities: notification_status?.seen_activities
257
+ var selector$7 = ({ own_follows }) => ({ own_follows });
258
+ //#endregion
259
+ //#region src/bindings/react/hooks/feed-state-hooks/useNotificationStatus.ts
260
+ var selector$6 = ({ notification_status }) => ({
261
+ unread: notification_status?.unread ?? 0,
262
+ unseen: notification_status?.unseen ?? 0,
263
+ last_read_at: notification_status?.last_read_at,
264
+ last_seen_at: notification_status?.last_seen_at,
265
+ read_activities: notification_status?.read_activities,
266
+ seen_activities: notification_status?.seen_activities
264
267
  });
265
268
  function useNotificationStatus(feedFromProps) {
266
- const feedFromContext = useFeedContext();
267
- const feed = feedFromProps ?? feedFromContext;
268
- return reactBindings.useStateStore(feed?.state, selector$6);
269
+ const feedFromContext = useFeedContext();
270
+ return (0, _stream_io_state_store_react_bindings.useStateStore)((feedFromProps ?? feedFromContext)?.state, selector$6);
269
271
  }
270
- const selector$5 = ({
271
- is_loading_activities,
272
- next,
273
- aggregated_activities = []
274
- }) => ({
275
- is_loading: is_loading_activities,
276
- has_next_page: typeof next !== "undefined",
277
- aggregated_activities
272
+ //#endregion
273
+ //#region src/bindings/react/hooks/feed-state-hooks/useAggregatedActivities.ts
274
+ var selector$5 = ({ is_loading_activities, next, aggregated_activities = [] }) => ({
275
+ is_loading: is_loading_activities,
276
+ has_next_page: typeof next !== "undefined",
277
+ aggregated_activities
278
278
  });
279
279
  function useAggregatedActivities(feedFromProps) {
280
- const feedFromContext = useFeedContext();
281
- const feed = feedFromProps ?? feedFromContext;
282
- const data = reactBindings.useStateStore(feed?.state, selector$5);
283
- const loadNextPage = useStableCallback(async () => {
284
- if (!feed || !data?.has_next_page || data?.is_loading) {
285
- return;
286
- }
287
- await feed.getNextPage();
288
- });
289
- return react.useMemo(
290
- () => data ? { ...data, loadNextPage } : void 0,
291
- [data, loadNextPage]
292
- );
280
+ const feedFromContext = useFeedContext();
281
+ const feed = feedFromProps ?? feedFromContext;
282
+ const data = (0, _stream_io_state_store_react_bindings.useStateStore)(feed?.state, selector$5);
283
+ const loadNextPage = useStableCallback(async () => {
284
+ if (!feed || !data?.has_next_page || data?.is_loading) return;
285
+ await feed.getNextPage();
286
+ });
287
+ return (0, react.useMemo)(() => data ? {
288
+ ...data,
289
+ loadNextPage
290
+ } : void 0, [data, loadNextPage]);
293
291
  }
294
- const useIsAggregatedActivityRead = ({
295
- feed: _,
296
- aggregatedActivity
297
- }) => {
298
- return aggregatedActivity.is_read;
292
+ //#endregion
293
+ //#region src/bindings/react/hooks/feed-state-hooks/useIsAggregatedActivityRead.ts
294
+ /**
295
+ * @deprecated use aggregatedActivity.is_read instead
296
+ * @returns
297
+ */
298
+ var useIsAggregatedActivityRead = ({ feed: _, aggregatedActivity }) => {
299
+ return aggregatedActivity.is_read;
299
300
  };
300
- const useIsAggregatedActivitySeen = ({
301
- feed: _,
302
- aggregatedActivity
303
- }) => {
304
- return aggregatedActivity.is_seen;
301
+ //#endregion
302
+ //#region src/bindings/react/hooks/feed-state-hooks/useIsAggregatedActivitySeen.ts
303
+ /**
304
+ * @deprecated use aggregatedActivity.is_seen instead
305
+ * @returns
306
+ */
307
+ var useIsAggregatedActivitySeen = ({ feed: _, aggregatedActivity }) => {
308
+ return aggregatedActivity.is_seen;
305
309
  };
306
- const StreamActivityWithStateUpdatesContext = react.createContext(void 0);
307
- const useActivityWithStateUpdatesContext = () => {
308
- return react.useContext(StreamActivityWithStateUpdatesContext);
310
+ //#endregion
311
+ //#region src/bindings/react/contexts/StreamActivityWithStateUpdatesContext.tsx
312
+ var StreamActivityWithStateUpdatesContext = (0, react.createContext)(void 0);
313
+ /**
314
+ * Hook to access the nearest ActivityWithStateUpdates instance.
315
+ */
316
+ var useActivityWithStateUpdatesContext = () => {
317
+ return (0, react.useContext)(StreamActivityWithStateUpdatesContext);
309
318
  };
310
- const canLoadComments = (feedOrActivity) => {
311
- return "loadNextPageCommentReplies" in feedOrActivity && "loadNextPageActivityComments" in feedOrActivity;
319
+ //#endregion
320
+ //#region src/bindings/react/hooks/feed-state-hooks/useActivityComments.ts
321
+ var canLoadComments = (feedOrActivity) => {
322
+ return "loadNextPageCommentReplies" in feedOrActivity && "loadNextPageActivityComments" in feedOrActivity;
312
323
  };
313
- function useActivityComments({
314
- feed: feedFromProps,
315
- parentComment,
316
- activity: activityFromProps
317
- } = {}) {
318
- const feedFromContext = useFeedContext();
319
- const feed = feedFromProps ?? feedFromContext;
320
- const activityFromContext = useActivityWithStateUpdatesContext();
321
- const activity = activityFromProps ?? activityFromContext;
322
- const feedOrActivity = activity && canLoadComments(activity) ? activity : feed;
323
- if (!feedOrActivity) {
324
- throw new Error("Feed or activity is required");
325
- }
326
- if (!canLoadComments(feedOrActivity)) {
327
- throw new Error("Feed or activity does not support loading comments");
328
- }
329
- if (!(activity || parentComment)) {
330
- throw new Error("Activity or parent comment is required");
331
- }
332
- const entityId = parentComment?.id ?? activity?.id ?? "";
333
- const selector2 = react.useCallback(
334
- (state) => ({
335
- comments: state.comments_by_entity_id?.[entityId]?.comments,
336
- comments_pagination: state.comments_by_entity_id?.[entityId]?.pagination
337
- }),
338
- [entityId]
339
- );
340
- const data = reactBindings.useStateStore(
341
- feedOrActivity.state,
342
- selector2
343
- );
344
- const loadNextPage = react.useCallback(
345
- (request) => {
346
- if (parentComment) {
347
- return feedOrActivity.loadNextPageCommentReplies(
348
- parentComment,
349
- request
350
- );
351
- } else {
352
- if (activity && canLoadComments(activity)) {
353
- return activity.loadNextPageActivityComments(request);
354
- } else if (feed) {
355
- return feed.loadNextPageActivityComments(activity?.id ?? "", request);
356
- } else {
357
- throw new Error("Activity or feed is required");
358
- }
359
- }
360
- },
361
- [feedOrActivity, feed, parentComment, activity]
362
- );
363
- return react.useMemo(() => {
364
- return {
365
- ...data,
366
- has_next_page: feedsClient.checkHasAnotherPage(
367
- data.comments,
368
- data.comments_pagination?.next
369
- ),
370
- is_loading_next_page: data?.comments_pagination?.loading_next_page ?? false,
371
- loadNextPage
372
- };
373
- }, [data, loadNextPage]);
324
+ function useActivityComments({ feed: feedFromProps, parentComment, activity: activityFromProps } = {}) {
325
+ const feedFromContext = useFeedContext();
326
+ const feed = feedFromProps ?? feedFromContext;
327
+ const activityFromContext = useActivityWithStateUpdatesContext();
328
+ const activity = activityFromProps ?? activityFromContext;
329
+ const feedOrActivity = activity && canLoadComments(activity) ? activity : feed;
330
+ if (!feedOrActivity) throw new Error("Feed or activity is required");
331
+ if (!canLoadComments(feedOrActivity)) throw new Error("Feed or activity does not support loading comments");
332
+ if (!(activity || parentComment)) throw new Error("Activity or parent comment is required");
333
+ const entityId = parentComment?.id ?? activity?.id ?? "";
334
+ const selector = (0, react.useCallback)((state) => ({
335
+ comments: state.comments_by_entity_id?.[entityId]?.comments,
336
+ comments_pagination: state.comments_by_entity_id?.[entityId]?.pagination
337
+ }), [entityId]);
338
+ const data = (0, _stream_io_state_store_react_bindings.useStateStore)(feedOrActivity.state, selector);
339
+ const loadNextPage = (0, react.useCallback)((request) => {
340
+ if (parentComment) return feedOrActivity.loadNextPageCommentReplies(parentComment, request);
341
+ else if (activity && canLoadComments(activity)) return activity.loadNextPageActivityComments(request);
342
+ else if (feed) return feed.loadNextPageActivityComments(activity?.id ?? "", request);
343
+ else throw new Error("Activity or feed is required");
344
+ }, [
345
+ feedOrActivity,
346
+ feed,
347
+ parentComment,
348
+ activity
349
+ ]);
350
+ return (0, react.useMemo)(() => {
351
+ return {
352
+ ...data,
353
+ has_next_page: require_feeds_client.checkHasAnotherPage(data.comments, data.comments_pagination?.next),
354
+ is_loading_next_page: data?.comments_pagination?.loading_next_page ?? false,
355
+ loadNextPage
356
+ };
357
+ }, [data, loadNextPage]);
374
358
  }
375
- const useOwnFollowings = (feedFromProps) => {
376
- const feedFromContext = useFeedContext();
377
- const feed = feedFromProps ?? feedFromContext;
378
- return reactBindings.useStateStore(feed?.state, selector$4);
359
+ //#endregion
360
+ //#region src/bindings/react/hooks/feed-state-hooks/useOwnFollowings.ts
361
+ /**
362
+ * A React hook that returns a reactive array of feeds that the feeds's owner is following and is owned by the current user.
363
+ */
364
+ var useOwnFollowings = (feedFromProps) => {
365
+ const feedFromContext = useFeedContext();
366
+ return (0, _stream_io_state_store_react_bindings.useStateStore)((feedFromProps ?? feedFromContext)?.state, selector$4);
379
367
  };
380
- const selector$4 = ({ own_followings }) => ({
381
- own_followings
382
- });
383
- const selector$3 = ({
384
- member_count,
385
- members,
386
- member_pagination
387
- }) => ({
388
- member_count,
389
- members,
390
- member_pagination
368
+ var selector$4 = ({ own_followings }) => ({ own_followings });
369
+ //#endregion
370
+ //#region src/bindings/react/hooks/feed-state-hooks/useMembers.ts
371
+ var selector$3 = ({ member_count, members, member_pagination }) => ({
372
+ member_count,
373
+ members,
374
+ member_pagination
391
375
  });
392
376
  function useMembers(feedFromProps) {
393
- const feedFromContext = useFeedContext();
394
- const feed = feedFromProps ?? feedFromContext;
395
- const data = reactBindings.useStateStore(feed?.state, selector$3);
396
- const loadNextPage = react.useCallback(
397
- (...options) => feed?.loadNextPageMembers(...options),
398
- [feed]
399
- );
400
- return react.useMemo(() => {
401
- if (!data) {
402
- return void 0;
403
- }
404
- return {
405
- ...data,
406
- is_loading_next_page: data.member_pagination?.loading_next_page ?? false,
407
- has_next_page: feedsClient.checkHasAnotherPage(
408
- data.members,
409
- data.member_pagination?.next
410
- ),
411
- loadNextPage
412
- };
413
- }, [data, loadNextPage]);
377
+ const feedFromContext = useFeedContext();
378
+ const feed = feedFromProps ?? feedFromContext;
379
+ const data = (0, _stream_io_state_store_react_bindings.useStateStore)(feed?.state, selector$3);
380
+ const loadNextPage = (0, react.useCallback)((...options) => feed?.loadNextPageMembers(...options), [feed]);
381
+ return (0, react.useMemo)(() => {
382
+ if (!data) return;
383
+ return {
384
+ ...data,
385
+ is_loading_next_page: data.member_pagination?.loading_next_page ?? false,
386
+ has_next_page: require_feeds_client.checkHasAnotherPage(data.members, data.member_pagination?.next),
387
+ loadNextPage
388
+ };
389
+ }, [data, loadNextPage]);
414
390
  }
415
- const StreamSearchResultsContext = react.createContext(void 0);
416
- const useSearchResultsContext = () => {
417
- return react.useContext(StreamSearchResultsContext);
391
+ //#endregion
392
+ //#region src/bindings/react/contexts/StreamSearchResultsContext.tsx
393
+ var StreamSearchResultsContext = (0, react.createContext)(void 0);
394
+ /**
395
+ * Hook to access the nearest SearchSource instance.
396
+ */
397
+ var useSearchResultsContext = () => {
398
+ return (0, react.useContext)(StreamSearchResultsContext);
418
399
  };
419
- const useSearchResult = (sourceFromProps) => {
420
- const sourceFromContext = useSearchResultsContext();
421
- const source = sourceFromProps ?? sourceFromContext;
422
- const { items, error, isLoading, hasNext } = reactBindings.useStateStore(source?.state, selector$2) ?? {};
423
- const loadMore = useStableCallback(async () => {
424
- if (hasNext) {
425
- source?.search();
426
- }
427
- });
428
- return react.useMemo(
429
- () => ({ items, error, isLoading, hasNext, loadMore }),
430
- [error, hasNext, isLoading, items, loadMore]
431
- );
400
+ //#endregion
401
+ //#region src/bindings/react/hooks/search-state-hooks/useSearchResult.ts
402
+ var useSearchResult = (sourceFromProps) => {
403
+ const sourceFromContext = useSearchResultsContext();
404
+ const source = sourceFromProps ?? sourceFromContext;
405
+ const { items, error, isLoading, hasNext } = (0, _stream_io_state_store_react_bindings.useStateStore)(source?.state, selector$2) ?? {};
406
+ const loadMore = useStableCallback(async () => {
407
+ if (hasNext) source?.search();
408
+ });
409
+ return (0, react.useMemo)(() => ({
410
+ items,
411
+ error,
412
+ isLoading,
413
+ hasNext,
414
+ loadMore
415
+ }), [
416
+ error,
417
+ hasNext,
418
+ isLoading,
419
+ items,
420
+ loadMore
421
+ ]);
432
422
  };
433
- const selector$2 = ({
434
- items,
435
- isLoading,
436
- hasNext,
437
- lastQueryError
438
- }) => ({
439
- items,
440
- isLoading,
441
- hasNext,
442
- error: lastQueryError
423
+ var selector$2 = ({ items, isLoading, hasNext, lastQueryError }) => ({
424
+ items,
425
+ isLoading,
426
+ hasNext,
427
+ error: lastQueryError
443
428
  });
444
- const StreamSearchContext = react.createContext(void 0);
445
- const useSearchContext = () => {
446
- return react.useContext(StreamSearchContext);
429
+ //#endregion
430
+ //#region src/bindings/react/contexts/StreamSearchContext.tsx
431
+ var StreamSearchContext = (0, react.createContext)(void 0);
432
+ /**
433
+ * Hook to access the nearest SearchController instance.
434
+ */
435
+ var useSearchContext = () => {
436
+ return (0, react.useContext)(StreamSearchContext);
447
437
  };
448
- const useSearchQuery = (controllerFromProps) => {
449
- const controllerFromState = useSearchContext();
450
- const controller = controllerFromProps ?? controllerFromState;
451
- return reactBindings.useStateStore(controller?.state, selector$1);
438
+ //#endregion
439
+ //#region src/bindings/react/hooks/search-state-hooks/useSearchQuery.ts
440
+ var useSearchQuery = (controllerFromProps) => {
441
+ const controllerFromState = useSearchContext();
442
+ return (0, _stream_io_state_store_react_bindings.useStateStore)((controllerFromProps ?? controllerFromState)?.state, selector$1);
452
443
  };
453
- const selector$1 = ({ searchQuery }) => ({
454
- searchQuery
455
- });
456
- const useSearchSources = (controllerFromProps) => {
457
- const controllerFromState = useSearchContext();
458
- const controller = controllerFromProps ?? controllerFromState;
459
- return reactBindings.useStateStore(controller?.state, selector);
444
+ var selector$1 = ({ searchQuery }) => ({ searchQuery });
445
+ //#endregion
446
+ //#region src/bindings/react/hooks/search-state-hooks/useSearchSources.ts
447
+ var useSearchSources = (controllerFromProps) => {
448
+ const controllerFromState = useSearchContext();
449
+ return (0, _stream_io_state_store_react_bindings.useStateStore)((controllerFromProps ?? controllerFromState)?.state, selector);
460
450
  };
461
- const selector = ({ sources }) => ({
462
- sources
463
- });
464
- const StreamFeeds = ({ client, children }) => {
465
- return /* @__PURE__ */ jsxRuntime.jsx(StreamFeedsContext.Provider, { value: client, children });
451
+ var selector = ({ sources }) => ({ sources });
452
+ //#endregion
453
+ //#region src/bindings/react/wrappers/StreamFeeds.tsx
454
+ var StreamFeeds = ({ client, children }) => {
455
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StreamFeedsContext.Provider, {
456
+ value: client,
457
+ children
458
+ });
466
459
  };
467
460
  StreamFeeds.displayName = "StreamFeeds";
468
- const StreamFeed = ({
469
- feed,
470
- children
471
- }) => {
472
- return /* @__PURE__ */ jsxRuntime.jsx(StreamFeedContext.Provider, { value: feed, children });
461
+ //#endregion
462
+ //#region src/bindings/react/wrappers/StreamFeed.tsx
463
+ var StreamFeed = ({ feed, children }) => {
464
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StreamFeedContext.Provider, {
465
+ value: feed,
466
+ children
467
+ });
473
468
  };
474
469
  StreamFeed.displayName = "StreamFeed";
475
- const StreamActivityWithStateUpdates = ({
476
- activityWithStateUpdates,
477
- children
478
- }) => {
479
- return /* @__PURE__ */ jsxRuntime.jsx(StreamActivityWithStateUpdatesContext.Provider, { value: activityWithStateUpdates, children });
470
+ //#endregion
471
+ //#region src/bindings/react/wrappers/StreamActivityWithStateUpdates.tsx
472
+ var StreamActivityWithStateUpdates = ({ activityWithStateUpdates, children }) => {
473
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StreamActivityWithStateUpdatesContext.Provider, {
474
+ value: activityWithStateUpdates,
475
+ children
476
+ });
480
477
  };
481
478
  StreamActivityWithStateUpdates.displayName = "StreamActivityWithStateUpdates";
482
- const StreamSearch = ({
483
- searchController,
484
- children
485
- }) => {
486
- return /* @__PURE__ */ jsxRuntime.jsx(StreamSearchContext.Provider, { value: searchController, children });
479
+ //#endregion
480
+ //#region src/bindings/react/wrappers/StreamSearch.tsx
481
+ var StreamSearch = ({ searchController, children }) => {
482
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StreamSearchContext.Provider, {
483
+ value: searchController,
484
+ children
485
+ });
487
486
  };
488
487
  StreamSearch.displayName = "StreamSearch";
489
- const StreamSearchResults = ({
490
- source,
491
- children
492
- }) => {
493
- return /* @__PURE__ */ jsxRuntime.jsx(StreamSearchResultsContext.Provider, { value: source, children });
488
+ //#endregion
489
+ //#region src/bindings/react/wrappers/StreamSearchResults.tsx
490
+ var StreamSearchResults = ({ source, children }) => {
491
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StreamSearchResultsContext.Provider, {
492
+ value: source,
493
+ children
494
+ });
494
495
  };
495
496
  StreamSearchResults.displayName = "StreamSearchResults";
497
+ //#endregion
496
498
  exports.StreamActivityWithStateUpdates = StreamActivityWithStateUpdates;
497
499
  exports.StreamActivityWithStateUpdatesContext = StreamActivityWithStateUpdatesContext;
498
500
  exports.StreamFeed = StreamFeed;
@@ -528,10 +530,13 @@ exports.useSearchResult = useSearchResult;
528
530
  exports.useSearchResultsContext = useSearchResultsContext;
529
531
  exports.useSearchSources = useSearchSources;
530
532
  exports.useWsConnectionState = useWsConnectionState;
531
- Object.keys(reactBindings).forEach((k) => {
532
- if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
533
- enumerable: true,
534
- get: () => reactBindings[k]
535
- });
533
+ Object.keys(_stream_io_state_store_react_bindings).forEach(function(k) {
534
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
535
+ enumerable: true,
536
+ get: function() {
537
+ return _stream_io_state_store_react_bindings[k];
538
+ }
539
+ });
536
540
  });
537
- //# sourceMappingURL=react-bindings.js.map
541
+
542
+ //# sourceMappingURL=react-bindings.js.map