Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.

Commit a941257

Browse files
feat(lib): react to changes in users atom and expose loading flags (#132)
* feat(lib): react to changes in users atom and expose loading flags --------- Co-authored-by: PubNub Release Bot <[email protected]>
1 parent 6447a8e commit a941257

13 files changed

+37
-19
lines changed

.pubnub.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
---
22
name: pubnub-react-chat-components
3-
version: v0.32.0
3+
version: v0.33.0
44
scm: github.com/pubnub/react-chat-components
55
schema: 1
66
files:
77
- lib/dist/index.js
88
- lib/dist/index.es.js
99
changelog:
10+
- date: 2023-12-11
11+
version: v0.33.0
12+
changes:
13+
- type: feature
14+
text: "Expose "isLoading" flags to hooks."
1015
- date: 2023-10-05
1116
version: v0.32.0
1217
changes:

packages/common/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pubnub/common-chat-components",
3-
"version": "0.32.0",
3+
"version": "0.33.0",
44
"main": "src/index.ts",
55
"license": "MIT",
66
"scripts": {

packages/common/src/hooks/use-channel-members.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { usePubNub } from "pubnub-react";
44
import { merge, cloneDeep } from "lodash";
55
import { UserEntityWithMembership } from "../types";
66

7-
type HookReturnValue = [UserEntityWithMembership[], () => void, () => void, number, Error];
7+
type HookReturnValue = [UserEntityWithMembership[], () => void, () => void, number, Error, boolean];
88

99
export const useChannelMembers = (options: GetChannelMembersParameters): HookReturnValue => {
1010
const jsonOptions = JSON.stringify(options);
@@ -110,5 +110,5 @@ export const useChannelMembers = (options: GetChannelMembersParameters): HookRet
110110
};
111111
}, [pubnub, paginatedOptions.channel]);
112112

113-
return [members, fetchMoreMembers, resetHook, totalCount, error];
113+
return [members, fetchMoreMembers, resetHook, totalCount, error, doFetch];
114114
};

packages/common/src/hooks/use-channels.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { usePubNub } from "pubnub-react";
44
import { merge, cloneDeep } from "lodash";
55
import { ChannelEntity } from "../types";
66

7-
type HookReturnValue = [ChannelEntity[], () => void, number, Error];
7+
type HookReturnValue = [ChannelEntity[], () => void, number, Error, boolean];
88

99
export const useChannels = (options: GetAllMetadataParameters = {}): HookReturnValue => {
1010
const pubnub = usePubNub();
@@ -79,5 +79,5 @@ export const useChannels = (options: GetAllMetadataParameters = {}): HookReturnV
7979
};
8080
}, [pubnub]);
8181

82-
return [channels, fetchMoreChannels, totalCount, error];
82+
return [channels, fetchMoreChannels, totalCount, error, doFetch];
8383
};

packages/common/src/hooks/use-presence.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { usePubNub } from "pubnub-react";
44
import { cloneDeep } from "lodash";
55

66
type ChannelsOccupancy = HereNowResponse["channels"];
7-
type HookReturnValue = [ChannelsOccupancy, () => void, number, Error];
7+
type HookReturnValue = [ChannelsOccupancy, () => void, number, Error, boolean];
88

99
export const usePresence = (options: HereNowParameters = {}): HookReturnValue => {
1010
const jsonOptions = JSON.stringify(options);
@@ -97,5 +97,5 @@ export const usePresence = (options: HereNowParameters = {}): HookReturnValue =>
9797
};
9898
}, [pubnub, options.includeUUIDs]);
9999

100-
return [presence, resetHook, total, error];
100+
return [presence, resetHook, total, error, doFetch];
101101
};

packages/common/src/hooks/use-user-memberships.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ import { usePubNub } from "pubnub-react";
44
import { merge, cloneDeep } from "lodash";
55
import { ChannelEntityWithMembership } from "../types";
66

7-
type HookReturnValue = [ChannelEntityWithMembership[], () => void, () => void, number, Error];
7+
type HookReturnValue = [
8+
ChannelEntityWithMembership[],
9+
() => void,
10+
() => void,
11+
number,
12+
Error,
13+
boolean
14+
];
815

916
export const useUserMemberships = (options: GetMembershipsParametersv2 = {}): HookReturnValue => {
1017
const jsonOptions = JSON.stringify(options);
@@ -111,5 +118,5 @@ export const useUserMemberships = (options: GetMembershipsParametersv2 = {}): Ho
111118
};
112119
}, [pubnub, paginatedOptions.uuid]);
113120

114-
return [channels, fetchMoreMemberships, resetHook, totalCount, error];
121+
return [channels, fetchMoreMemberships, resetHook, totalCount, error, doFetch];
115122
};

packages/common/src/hooks/use-user.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { usePubNub } from "pubnub-react";
44
import { cloneDeep } from "lodash";
55
import { UserEntity } from "../types";
66

7-
export const useUser = (options: GetUUIDMetadataParameters = {}): [UserEntity, Error] => {
7+
export const useUser = (options: GetUUIDMetadataParameters = {}): [UserEntity, Error, boolean] => {
88
const jsonOptions = JSON.stringify(options);
99

1010
const pubnub = usePubNub();
@@ -68,5 +68,5 @@ export const useUser = (options: GetUUIDMetadataParameters = {}): [UserEntity, E
6868
};
6969
}, [pubnub]);
7070

71-
return [user, error];
71+
return [user, error, doFetch];
7272
};

packages/common/src/hooks/use-users.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { usePubNub } from "pubnub-react";
44
import { merge, cloneDeep } from "lodash";
55
import { UserEntity } from "../types";
66

7-
type HookReturnValue = [UserEntity[], () => void, number, Error];
7+
type HookReturnValue = [UserEntity[], () => void, number, Error, boolean];
88

99
export const useUsers = (options: GetAllMetadataParameters = {}): HookReturnValue => {
1010
const pubnub = usePubNub();
@@ -79,5 +79,5 @@ export const useUsers = (options: GetAllMetadataParameters = {}): HookReturnValu
7979
};
8080
}, [pubnub]);
8181

82-
return [users, fetchMoreUsers, totalCount, error];
82+
return [users, fetchMoreUsers, totalCount, error, doFetch];
8383
};

packages/common/test/use-channel-members.test.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ describe("useChannelMembers", () => {
1414
const { result } = renderHook(() => useChannelMembers({ channel: "test-channel" }), {
1515
wrapper,
1616
});
17+
expect(result.current[5]).toBe(true);
1718

1819
await waitFor(() => {
19-
const [receivedMembers, fetchMore, resetHook, total, error] = result.current;
20+
const [receivedMembers, fetchMore, resetHook, total, error, loading] = result.current;
2021
expect(receivedMembers).toHaveLength(users.length);
2122
expect(typeof fetchMore).toEqual("function");
2223
expect(typeof resetHook).toEqual("function");
2324
expect(total).toEqual(users.length);
2425
expect(error).toEqual(undefined);
26+
expect(loading).toBe(false);
2527
});
2628
});
2729

packages/common/test/use-channels.test.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ const wrapper = ({ children }) => <PubNubProvider client={pubnub}>{children}</Pu
1212
describe("useChannels", () => {
1313
test("fetches and returns the full list of channels", async () => {
1414
const { result } = renderHook(() => useChannels(), { wrapper });
15+
expect(result.current[4]).toBe(true);
1516

1617
await waitFor(() => {
17-
const [receivedChannels, fetchMore, total, error] = result.current;
18+
const [receivedChannels, fetchMore, total, error, loading] = result.current;
1819
expect(receivedChannels).toHaveLength(channels.length);
1920
expect(typeof fetchMore).toEqual("function");
2021
expect(total).toEqual(channels.length);
2122
expect(error).toEqual(undefined);
23+
expect(loading).toEqual(false);
2224
});
2325
});
2426

@@ -27,9 +29,10 @@ describe("useChannels", () => {
2729
const { result } = renderHook(() => useChannels({ limit }), { wrapper });
2830

2931
await waitFor(() => {
30-
const [receivedChannels, fetchMore, total] = result.current;
32+
const [receivedChannels, fetchMore, total, , loading] = result.current;
3133
expect(receivedChannels).toHaveLength(limit);
3234
expect(total).toEqual(channels.length);
35+
expect(loading).toEqual(false);
3336
fetchMore();
3437
});
3538

packages/react-native/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pubnub/react-native-chat-components",
3-
"version": "0.32.0",
3+
"version": "0.33.0",
44
"description": "PubNub Chat Components is a development kit of React Native components that aims to help you to easily build Chat applications using PubNub infrastructure. It removes the complexicity of picking an adequate Chat engine, learning its APIs and dealing with its low-level internals. As the same time it allows you to create apps of various use cases, with different functionalities and customizable looks.",
55
"author": "PubNub <[email protected]>",
66
"main": "dist/commonjs/index",

packages/react/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pubnub/react-chat-components",
3-
"version": "0.32.0",
3+
"version": "0.33.0",
44
"description": "PubNub Chat Components is a development kit of React components that aims to help you to easily build Chat applications using PubNub infrastructure. It removes the complexicity of picking an adequate Chat engine, learning its APIs and dealing with its low-level internals. As the same time it allows you to create apps of various use cases, with different functionalities and customizable looks.",
55
"author": "PubNub <[email protected]>",
66
"main": "dist/index.js",

packages/react/src/message-list/message-item.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export type ItemProps = Pick<
4343
export const MessageListItem = React.memo(Item, (prev, next) => {
4444
if (prev.envelope.timetoken !== next.envelope.timetoken) return false;
4545
if (!isEqual(prev.envelope.actions, next.envelope.actions)) return false;
46+
if (!isEqual(prev.users, next.users)) return false;
4647
return true;
4748
});
4849

0 commit comments

Comments
 (0)