@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.
- package/CHANGELOG.md +12 -0
- package/dist/cjs/index.js +477 -466
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/react-bindings.js +454 -449
- package/dist/cjs/react-bindings.js.map +1 -1
- package/dist/es/index.mjs +440 -466
- package/dist/es/index.mjs.map +1 -1
- package/dist/es/react-bindings.mjs +447 -479
- package/dist/es/react-bindings.mjs.map +1 -1
- package/dist/feeds-client-ACVPbpUP.mjs +8752 -0
- package/dist/feeds-client-ACVPbpUP.mjs.map +1 -0
- package/dist/feeds-client-BP0fE4NZ.js +8918 -0
- package/dist/feeds-client-BP0fE4NZ.js.map +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/types/feed/event-handlers/notification-feed/handle-notification-feed-updated.d.ts.map +1 -1
- package/dist/types/feeds-client/feeds-client.d.ts +1 -0
- package/dist/types/feeds-client/feeds-client.d.ts.map +1 -1
- package/package.json +15 -15
- package/src/feed/event-handlers/notification-feed/handle-notification-feed-updated.ts +1 -5
- package/src/feeds-client/feeds-client.ts +104 -45
- package/dist/feeds-client-C1c6lcS3.js +0 -8799
- package/dist/feeds-client-C1c6lcS3.js.map +0 -1
- package/dist/feeds-client-jtUTE4AC.mjs +0 -8783
- package/dist/feeds-client-jtUTE4AC.mjs.map +0 -1
|
@@ -1,532 +1,500 @@
|
|
|
1
|
+
import { t as FeedsClient, u as isCommentResponse, v as checkHasAnotherPage } from "../feeds-client-ACVPbpUP.mjs";
|
|
1
2
|
import { useStateStore } from "@stream-io/state-store/react-bindings";
|
|
2
|
-
|
|
3
|
-
import { useState, useEffect, createContext, useContext, useRef, useCallback, useMemo } from "react";
|
|
4
|
-
import { F as FeedsClient, h as isCommentResponse, e as checkHasAnotherPage } from "../feeds-client-jtUTE4AC.mjs";
|
|
3
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
5
4
|
import { jsx } from "react/jsx-runtime";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
connectionPromise.then(() => {
|
|
49
|
-
setError(null);
|
|
50
|
-
return _client.disconnectUser();
|
|
51
|
-
}).catch((err) => {
|
|
52
|
-
setError(err);
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
}, [apiKey, cachedUserData, cachedOptions, tokenOrProvider]);
|
|
56
|
-
return client;
|
|
5
|
+
export * from "@stream-io/state-store/react-bindings";
|
|
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] = useState(null);
|
|
14
|
+
const [error, setError] = useState(null);
|
|
15
|
+
const [cachedUserData, setCachedUserData] = useState(userData);
|
|
16
|
+
const [cachedOptions] = useState(options);
|
|
17
|
+
if (error) throw error;
|
|
18
|
+
if (userData?.id !== cachedUserData?.id) setCachedUserData(userData);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
const _client = new 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;
|
|
57
47
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/bindings/react/contexts/StreamFeedsContext.tsx
|
|
50
|
+
var StreamFeedsContext = createContext(void 0);
|
|
51
|
+
/**
|
|
52
|
+
* Hook to access the nearest FeedsClient instance.
|
|
53
|
+
*/
|
|
54
|
+
var useFeedsClient = () => {
|
|
55
|
+
return useContext(StreamFeedsContext);
|
|
61
56
|
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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 } = useStateStore(useFeedsClient()?.state, selector$14) ?? {};
|
|
64
|
+
return user;
|
|
66
65
|
};
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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 } = useStateStore(useFeedsClient()?.state, selector$13) ?? {};
|
|
74
|
+
return { is_healthy };
|
|
74
75
|
};
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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 = createContext(void 0);
|
|
80
|
+
/**
|
|
81
|
+
* Hook to access the nearest Feed instance.
|
|
82
|
+
*/
|
|
83
|
+
var useFeedContext = () => {
|
|
84
|
+
return useContext(StreamFeedContext);
|
|
81
85
|
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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 = useRef(callback);
|
|
113
|
+
ref.current = callback;
|
|
114
|
+
return useCallback((...args) => {
|
|
115
|
+
return ref.current(...args);
|
|
116
|
+
}, []);
|
|
88
117
|
};
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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 = 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 useMemo(() => ({
|
|
133
|
+
...data,
|
|
134
|
+
loadNextPage
|
|
135
|
+
}), [data, loadNextPage]);
|
|
100
136
|
};
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}) => ({
|
|
106
|
-
is_loading: is_loading_activities,
|
|
107
|
-
has_next_page: typeof next !== "undefined",
|
|
108
|
-
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
|
|
109
141
|
});
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
return void 0;
|
|
137
|
-
}
|
|
138
|
-
return {
|
|
139
|
-
...data,
|
|
140
|
-
has_next_page: checkHasAnotherPage(
|
|
141
|
-
data.comments,
|
|
142
|
-
data.comments_pagination?.next
|
|
143
|
-
),
|
|
144
|
-
is_loading_next_page: data?.comments_pagination?.loading_next_page ?? false,
|
|
145
|
-
loadNextPage
|
|
146
|
-
};
|
|
147
|
-
}, [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 = 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 = useStateStore(feed?.state, selector);
|
|
152
|
+
const loadNextPage = useMemo(() => {
|
|
153
|
+
if (!feed) return void 0;
|
|
154
|
+
return (request) => {
|
|
155
|
+
if (isCommentResponse(parent)) return feed.loadNextPageCommentReplies(parent, request);
|
|
156
|
+
else return feed.loadNextPageActivityComments(parent, request);
|
|
157
|
+
};
|
|
158
|
+
}, [feed, parent]);
|
|
159
|
+
return useMemo(() => {
|
|
160
|
+
if (!data) return;
|
|
161
|
+
return {
|
|
162
|
+
...data,
|
|
163
|
+
has_next_page: 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]);
|
|
148
168
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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 };
|
|
154
174
|
};
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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 } = useStateStore(feed?.state, selector$11) ?? {};
|
|
184
|
+
return feedOwnCapabilities;
|
|
165
185
|
};
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
followers,
|
|
173
|
-
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
|
|
174
192
|
});
|
|
175
193
|
function useFollowers(feedFromProps) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
is_loading_next_page: data.followers_pagination?.loading_next_page ?? false,
|
|
190
|
-
has_next_page: checkHasAnotherPage(
|
|
191
|
-
data.followers,
|
|
192
|
-
data.followers_pagination?.next
|
|
193
|
-
),
|
|
194
|
-
loadNextPage
|
|
195
|
-
};
|
|
196
|
-
}, [data, loadNextPage]);
|
|
194
|
+
const feedFromContext = useFeedContext();
|
|
195
|
+
const feed = feedFromProps ?? feedFromContext;
|
|
196
|
+
const data = useStateStore(feed?.state, selector$10);
|
|
197
|
+
const loadNextPage = useCallback((...options) => feed?.loadNextPageFollowers(...options), [feed]);
|
|
198
|
+
return 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: checkHasAnotherPage(data.followers, data.followers_pagination?.next),
|
|
204
|
+
loadNextPage
|
|
205
|
+
};
|
|
206
|
+
}, [data, loadNextPage]);
|
|
197
207
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
following,
|
|
205
|
-
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
|
|
206
214
|
});
|
|
207
215
|
function useFollowing(feedFromProps) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
is_loading_next_page: data.following_pagination?.loading_next_page ?? false,
|
|
222
|
-
has_next_page: checkHasAnotherPage(
|
|
223
|
-
data.following,
|
|
224
|
-
data.following_pagination?.next
|
|
225
|
-
),
|
|
226
|
-
loadNextPage
|
|
227
|
-
};
|
|
228
|
-
}, [data, loadNextPage]);
|
|
216
|
+
const feedFromContext = useFeedContext();
|
|
217
|
+
const feed = feedFromProps ?? feedFromContext;
|
|
218
|
+
const data = useStateStore(feed?.state, selector$9);
|
|
219
|
+
const loadNextPage = useCallback((...options) => feed?.loadNextPageFollowing(...options), [feed]);
|
|
220
|
+
return 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: checkHasAnotherPage(data.following, data.following_pagination?.next),
|
|
226
|
+
loadNextPage
|
|
227
|
+
};
|
|
228
|
+
}, [data, loadNextPage]);
|
|
229
229
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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 useStateStore((feedFromProps ?? feedFromContext)?.state, selector$8);
|
|
234
239
|
};
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}) => ({
|
|
242
|
-
created_by,
|
|
243
|
-
follower_count,
|
|
244
|
-
following_count,
|
|
245
|
-
created_at,
|
|
246
|
-
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
|
|
247
246
|
});
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
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 useStateStore((feedFromProps ?? feedFromContext)?.state, selector$7);
|
|
252
256
|
};
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
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
|
|
263
267
|
});
|
|
264
268
|
function useNotificationStatus(feedFromProps) {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
return useStateStore(feed?.state, selector$6);
|
|
269
|
+
const feedFromContext = useFeedContext();
|
|
270
|
+
return useStateStore((feedFromProps ?? feedFromContext)?.state, selector$6);
|
|
268
271
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
has_next_page: typeof next !== "undefined",
|
|
276
|
-
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
|
|
277
278
|
});
|
|
278
279
|
function useAggregatedActivities(feedFromProps) {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
[data, loadNextPage]
|
|
291
|
-
);
|
|
280
|
+
const feedFromContext = useFeedContext();
|
|
281
|
+
const feed = feedFromProps ?? feedFromContext;
|
|
282
|
+
const data = 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 useMemo(() => data ? {
|
|
288
|
+
...data,
|
|
289
|
+
loadNextPage
|
|
290
|
+
} : void 0, [data, loadNextPage]);
|
|
292
291
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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;
|
|
298
300
|
};
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
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;
|
|
304
309
|
};
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
310
|
+
//#endregion
|
|
311
|
+
//#region src/bindings/react/contexts/StreamActivityWithStateUpdatesContext.tsx
|
|
312
|
+
var StreamActivityWithStateUpdatesContext = createContext(void 0);
|
|
313
|
+
/**
|
|
314
|
+
* Hook to access the nearest ActivityWithStateUpdates instance.
|
|
315
|
+
*/
|
|
316
|
+
var useActivityWithStateUpdatesContext = () => {
|
|
317
|
+
return useContext(StreamActivityWithStateUpdatesContext);
|
|
308
318
|
};
|
|
309
|
-
|
|
310
|
-
|
|
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;
|
|
311
323
|
};
|
|
312
|
-
function useActivityComments({
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
return feedOrActivity.loadNextPageCommentReplies(
|
|
347
|
-
parentComment,
|
|
348
|
-
request
|
|
349
|
-
);
|
|
350
|
-
} else {
|
|
351
|
-
if (activity && canLoadComments(activity)) {
|
|
352
|
-
return activity.loadNextPageActivityComments(request);
|
|
353
|
-
} else if (feed) {
|
|
354
|
-
return feed.loadNextPageActivityComments(activity?.id ?? "", request);
|
|
355
|
-
} else {
|
|
356
|
-
throw new Error("Activity or feed is required");
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
},
|
|
360
|
-
[feedOrActivity, feed, parentComment, activity]
|
|
361
|
-
);
|
|
362
|
-
return useMemo(() => {
|
|
363
|
-
return {
|
|
364
|
-
...data,
|
|
365
|
-
has_next_page: checkHasAnotherPage(
|
|
366
|
-
data.comments,
|
|
367
|
-
data.comments_pagination?.next
|
|
368
|
-
),
|
|
369
|
-
is_loading_next_page: data?.comments_pagination?.loading_next_page ?? false,
|
|
370
|
-
loadNextPage
|
|
371
|
-
};
|
|
372
|
-
}, [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 = 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 = useStateStore(feedOrActivity.state, selector);
|
|
339
|
+
const loadNextPage = 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 useMemo(() => {
|
|
351
|
+
return {
|
|
352
|
+
...data,
|
|
353
|
+
has_next_page: 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]);
|
|
373
358
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
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 useStateStore((feedFromProps ?? feedFromContext)?.state, selector$4);
|
|
378
367
|
};
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
}) => ({
|
|
387
|
-
member_count,
|
|
388
|
-
members,
|
|
389
|
-
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
|
|
390
375
|
});
|
|
391
376
|
function useMembers(feedFromProps) {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
is_loading_next_page: data.member_pagination?.loading_next_page ?? false,
|
|
406
|
-
has_next_page: checkHasAnotherPage(
|
|
407
|
-
data.members,
|
|
408
|
-
data.member_pagination?.next
|
|
409
|
-
),
|
|
410
|
-
loadNextPage
|
|
411
|
-
};
|
|
412
|
-
}, [data, loadNextPage]);
|
|
377
|
+
const feedFromContext = useFeedContext();
|
|
378
|
+
const feed = feedFromProps ?? feedFromContext;
|
|
379
|
+
const data = useStateStore(feed?.state, selector$3);
|
|
380
|
+
const loadNextPage = useCallback((...options) => feed?.loadNextPageMembers(...options), [feed]);
|
|
381
|
+
return 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: checkHasAnotherPage(data.members, data.member_pagination?.next),
|
|
387
|
+
loadNextPage
|
|
388
|
+
};
|
|
389
|
+
}, [data, loadNextPage]);
|
|
413
390
|
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
391
|
+
//#endregion
|
|
392
|
+
//#region src/bindings/react/contexts/StreamSearchResultsContext.tsx
|
|
393
|
+
var StreamSearchResultsContext = createContext(void 0);
|
|
394
|
+
/**
|
|
395
|
+
* Hook to access the nearest SearchSource instance.
|
|
396
|
+
*/
|
|
397
|
+
var useSearchResultsContext = () => {
|
|
398
|
+
return useContext(StreamSearchResultsContext);
|
|
417
399
|
};
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
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 } = useStateStore(source?.state, selector$2) ?? {};
|
|
406
|
+
const loadMore = useStableCallback(async () => {
|
|
407
|
+
if (hasNext) source?.search();
|
|
408
|
+
});
|
|
409
|
+
return useMemo(() => ({
|
|
410
|
+
items,
|
|
411
|
+
error,
|
|
412
|
+
isLoading,
|
|
413
|
+
hasNext,
|
|
414
|
+
loadMore
|
|
415
|
+
}), [
|
|
416
|
+
error,
|
|
417
|
+
hasNext,
|
|
418
|
+
isLoading,
|
|
419
|
+
items,
|
|
420
|
+
loadMore
|
|
421
|
+
]);
|
|
431
422
|
};
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
}) => ({
|
|
438
|
-
items,
|
|
439
|
-
isLoading,
|
|
440
|
-
hasNext,
|
|
441
|
-
error: lastQueryError
|
|
423
|
+
var selector$2 = ({ items, isLoading, hasNext, lastQueryError }) => ({
|
|
424
|
+
items,
|
|
425
|
+
isLoading,
|
|
426
|
+
hasNext,
|
|
427
|
+
error: lastQueryError
|
|
442
428
|
});
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
429
|
+
//#endregion
|
|
430
|
+
//#region src/bindings/react/contexts/StreamSearchContext.tsx
|
|
431
|
+
var StreamSearchContext = createContext(void 0);
|
|
432
|
+
/**
|
|
433
|
+
* Hook to access the nearest SearchController instance.
|
|
434
|
+
*/
|
|
435
|
+
var useSearchContext = () => {
|
|
436
|
+
return useContext(StreamSearchContext);
|
|
446
437
|
};
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
438
|
+
//#endregion
|
|
439
|
+
//#region src/bindings/react/hooks/search-state-hooks/useSearchQuery.ts
|
|
440
|
+
var useSearchQuery = (controllerFromProps) => {
|
|
441
|
+
const controllerFromState = useSearchContext();
|
|
442
|
+
return useStateStore((controllerFromProps ?? controllerFromState)?.state, selector$1);
|
|
451
443
|
};
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
return 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 useStateStore((controllerFromProps ?? controllerFromState)?.state, selector);
|
|
459
450
|
};
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
451
|
+
var selector = ({ sources }) => ({ sources });
|
|
452
|
+
//#endregion
|
|
453
|
+
//#region src/bindings/react/wrappers/StreamFeeds.tsx
|
|
454
|
+
var StreamFeeds = ({ client, children }) => {
|
|
455
|
+
return /* @__PURE__ */ jsx(StreamFeedsContext.Provider, {
|
|
456
|
+
value: client,
|
|
457
|
+
children
|
|
458
|
+
});
|
|
465
459
|
};
|
|
466
460
|
StreamFeeds.displayName = "StreamFeeds";
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
461
|
+
//#endregion
|
|
462
|
+
//#region src/bindings/react/wrappers/StreamFeed.tsx
|
|
463
|
+
var StreamFeed = ({ feed, children }) => {
|
|
464
|
+
return /* @__PURE__ */ jsx(StreamFeedContext.Provider, {
|
|
465
|
+
value: feed,
|
|
466
|
+
children
|
|
467
|
+
});
|
|
472
468
|
};
|
|
473
469
|
StreamFeed.displayName = "StreamFeed";
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
470
|
+
//#endregion
|
|
471
|
+
//#region src/bindings/react/wrappers/StreamActivityWithStateUpdates.tsx
|
|
472
|
+
var StreamActivityWithStateUpdates = ({ activityWithStateUpdates, children }) => {
|
|
473
|
+
return /* @__PURE__ */ jsx(StreamActivityWithStateUpdatesContext.Provider, {
|
|
474
|
+
value: activityWithStateUpdates,
|
|
475
|
+
children
|
|
476
|
+
});
|
|
479
477
|
};
|
|
480
478
|
StreamActivityWithStateUpdates.displayName = "StreamActivityWithStateUpdates";
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
479
|
+
//#endregion
|
|
480
|
+
//#region src/bindings/react/wrappers/StreamSearch.tsx
|
|
481
|
+
var StreamSearch = ({ searchController, children }) => {
|
|
482
|
+
return /* @__PURE__ */ jsx(StreamSearchContext.Provider, {
|
|
483
|
+
value: searchController,
|
|
484
|
+
children
|
|
485
|
+
});
|
|
486
486
|
};
|
|
487
487
|
StreamSearch.displayName = "StreamSearch";
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
488
|
+
//#endregion
|
|
489
|
+
//#region src/bindings/react/wrappers/StreamSearchResults.tsx
|
|
490
|
+
var StreamSearchResults = ({ source, children }) => {
|
|
491
|
+
return /* @__PURE__ */ jsx(StreamSearchResultsContext.Provider, {
|
|
492
|
+
value: source,
|
|
493
|
+
children
|
|
494
|
+
});
|
|
493
495
|
};
|
|
494
496
|
StreamSearchResults.displayName = "StreamSearchResults";
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
StreamFeedContext,
|
|
500
|
-
StreamFeeds,
|
|
501
|
-
StreamFeedsContext,
|
|
502
|
-
StreamSearch,
|
|
503
|
-
StreamSearchContext,
|
|
504
|
-
StreamSearchResults,
|
|
505
|
-
StreamSearchResultsContext,
|
|
506
|
-
useActivityComments,
|
|
507
|
-
useActivityWithStateUpdatesContext,
|
|
508
|
-
useAggregatedActivities,
|
|
509
|
-
useClientConnectedUser,
|
|
510
|
-
useComments,
|
|
511
|
-
useCreateFeedsClient,
|
|
512
|
-
useFeedActivities,
|
|
513
|
-
useFeedContext,
|
|
514
|
-
useFeedMetadata,
|
|
515
|
-
useFeedsClient,
|
|
516
|
-
useFollowers,
|
|
517
|
-
useFollowing,
|
|
518
|
-
useIsAggregatedActivityRead,
|
|
519
|
-
useIsAggregatedActivitySeen,
|
|
520
|
-
useMembers,
|
|
521
|
-
useNotificationStatus,
|
|
522
|
-
useOwnCapabilities,
|
|
523
|
-
useOwnFollowings,
|
|
524
|
-
useOwnFollows,
|
|
525
|
-
useSearchContext,
|
|
526
|
-
useSearchQuery,
|
|
527
|
-
useSearchResult,
|
|
528
|
-
useSearchResultsContext,
|
|
529
|
-
useSearchSources,
|
|
530
|
-
useWsConnectionState
|
|
531
|
-
};
|
|
532
|
-
//# sourceMappingURL=react-bindings.mjs.map
|
|
497
|
+
//#endregion
|
|
498
|
+
export { StreamActivityWithStateUpdates, StreamActivityWithStateUpdatesContext, StreamFeed, StreamFeedContext, StreamFeeds, StreamFeedsContext, StreamSearch, StreamSearchContext, StreamSearchResults, StreamSearchResultsContext, useActivityComments, useActivityWithStateUpdatesContext, useAggregatedActivities, useClientConnectedUser, useComments, useCreateFeedsClient, useFeedActivities, useFeedContext, useFeedMetadata, useFeedsClient, useFollowers, useFollowing, useIsAggregatedActivityRead, useIsAggregatedActivitySeen, useMembers, useNotificationStatus, useOwnCapabilities, useOwnFollowings, useOwnFollows, useSearchContext, useSearchQuery, useSearchResult, useSearchResultsContext, useSearchSources, useWsConnectionState };
|
|
499
|
+
|
|
500
|
+
//# sourceMappingURL=react-bindings.mjs.map
|