stream-chat-react-native-core 5.3.0-beta.1 → 5.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/lib/commonjs/components/ChannelList/ChannelList.js +4 -4
  2. package/lib/commonjs/components/ChannelList/ChannelList.js.map +1 -1
  3. package/lib/commonjs/components/ChannelList/ChannelListMessenger.js +4 -4
  4. package/lib/commonjs/components/ChannelList/ChannelListMessenger.js.map +1 -1
  5. package/lib/commonjs/components/ChannelList/hooks/useCreateChannelsContext.js +1 -1
  6. package/lib/commonjs/components/ChannelList/hooks/useCreateChannelsContext.js.map +1 -1
  7. package/lib/commonjs/components/ChannelList/hooks/usePaginatedChannels.js +6 -7
  8. package/lib/commonjs/components/ChannelList/hooks/usePaginatedChannels.js.map +1 -1
  9. package/lib/commonjs/contexts/channelsContext/ChannelsContext.js.map +1 -1
  10. package/lib/commonjs/native.js.map +1 -1
  11. package/lib/commonjs/version.json +1 -1
  12. package/lib/module/components/ChannelList/ChannelList.js +4 -4
  13. package/lib/module/components/ChannelList/ChannelList.js.map +1 -1
  14. package/lib/module/components/ChannelList/ChannelListMessenger.js +4 -4
  15. package/lib/module/components/ChannelList/ChannelListMessenger.js.map +1 -1
  16. package/lib/module/components/ChannelList/hooks/useCreateChannelsContext.js +1 -1
  17. package/lib/module/components/ChannelList/hooks/useCreateChannelsContext.js.map +1 -1
  18. package/lib/module/components/ChannelList/hooks/usePaginatedChannels.js +6 -7
  19. package/lib/module/components/ChannelList/hooks/usePaginatedChannels.js.map +1 -1
  20. package/lib/module/contexts/channelsContext/ChannelsContext.js.map +1 -1
  21. package/lib/module/native.js.map +1 -1
  22. package/lib/module/version.json +1 -1
  23. package/lib/typescript/components/ChannelList/hooks/usePaginatedChannels.d.ts +1 -1
  24. package/lib/typescript/contexts/channelsContext/ChannelsContext.d.ts +1 -1
  25. package/lib/typescript/native.d.ts +2 -2
  26. package/package.json +1 -1
  27. package/src/__tests__/offline-feature.test.js +3 -1
  28. package/src/components/ChannelList/ChannelList.tsx +3 -2
  29. package/src/components/ChannelList/ChannelListMessenger.tsx +3 -3
  30. package/src/components/ChannelList/__tests__/ChannelList.test.js +1 -1
  31. package/src/components/ChannelList/hooks/useCreateChannelsContext.ts +1 -1
  32. package/src/components/ChannelList/hooks/usePaginatedChannels.ts +12 -11
  33. package/src/contexts/channelsContext/ChannelsContext.tsx +1 -1
  34. package/src/native.ts +2 -2
  35. package/src/version.json +1 -1
@@ -132,14 +132,14 @@ const ChannelListMessengerWithContext = <
132
132
  if (debugRef.current.setSendEventParams)
133
133
  debugRef.current.setSendEventParams({
134
134
  action: 'Channels',
135
- data: channels.map((channel) => ({
135
+ data: channels?.map((channel) => ({
136
136
  data: channel.data,
137
137
  members: channel.state.members,
138
138
  })),
139
139
  });
140
140
  }
141
141
 
142
- if (error && !refreshing && !loadingChannels && !channels?.length) {
142
+ if (error && !refreshing && !loadingChannels && channels === null) {
143
143
  return (
144
144
  <LoadingErrorIndicator
145
145
  error={error}
@@ -157,7 +157,7 @@ const ChannelListMessengerWithContext = <
157
157
  };
158
158
 
159
159
  const ListFooterComponent = () =>
160
- channels.length && ListHeaderComponent ? <ListHeaderComponent /> : null;
160
+ channels?.length && ListHeaderComponent ? <ListHeaderComponent /> : null;
161
161
 
162
162
  if (loadingChannels) {
163
163
  return <LoadingIndicator listType='channel' />;
@@ -43,7 +43,7 @@ const ChannelListComponent = (props) => {
43
43
  const { channels, onSelect } = useChannelsContext();
44
44
  return (
45
45
  <View testID='channel-list'>
46
- {channels.map((channel) => (
46
+ {channels?.map((channel) => (
47
47
  <ChannelPreviewComponent
48
48
  {...props}
49
49
  channel={channel}
@@ -38,7 +38,7 @@ export const useCreateChannelsContext = <
38
38
  Skeleton,
39
39
  }: ChannelsContextValue<StreamChatGenerics>) => {
40
40
  const channelValueString = channels
41
- .map(
41
+ ?.map(
42
42
  (channel) =>
43
43
  `${channel.data?.name ?? ''}${channel.id ?? ''}${Object.values(channel.state.members)
44
44
  .map((member) => member.user?.online)
@@ -44,11 +44,8 @@ export const usePaginatedChannels = <
44
44
  sort = {},
45
45
  }: Parameters<StreamChatGenerics>) => {
46
46
  const { client } = useChatContext<StreamChatGenerics>();
47
- const initialChannelsStateRef = useRef([]);
48
- const [channels, setChannels] = useState<Channel<StreamChatGenerics>[]>(
49
- initialChannelsStateRef.current,
50
- );
51
- const [staticChannelsActive, setStaticChannelsActive] = useState<boolean>(true);
47
+ const [channels, setChannels] = useState<Channel<StreamChatGenerics>[] | null>(null);
48
+ const [staticChannelsActive, setStaticChannelsActive] = useState<boolean>(false);
52
49
  const activeChannels = useActiveChannelsRefContext();
53
50
 
54
51
  const [error, setError] = useState<Error>();
@@ -95,7 +92,8 @@ export const usePaginatedChannels = <
95
92
 
96
93
  const newOptions = {
97
94
  limit: options?.limit ?? MAX_QUERY_CHANNELS_LIMIT,
98
- offset: queryType === 'loadChannels' && !staticChannelsActive ? channels.length : 0,
95
+ offset:
96
+ queryType === 'loadChannels' && !staticChannelsActive && channels ? channels.length : 0,
99
97
  ...options,
100
98
  };
101
99
 
@@ -108,7 +106,7 @@ export const usePaginatedChannels = <
108
106
  return;
109
107
  }
110
108
  const newChannels =
111
- queryType === 'loadChannels' && !staticChannelsActive
109
+ queryType === 'loadChannels' && !staticChannelsActive && channels
112
110
  ? [...channels, ...channelQueryResponse]
113
111
  : channelQueryResponse;
114
112
 
@@ -195,6 +193,7 @@ export const usePaginatedChannels = <
195
193
  offlineMode: true,
196
194
  }),
197
195
  );
196
+ setStaticChannelsActive(true);
198
197
  }
199
198
  } catch (e) {
200
199
  console.warn('Failed to get channels from database: ', e);
@@ -212,15 +211,17 @@ export const usePaginatedChannels = <
212
211
  error,
213
212
  hasNextPage,
214
213
  loadingChannels:
215
- activeQueryType === 'queryLocalDB'
216
- ? true
217
- : activeQueryType === 'reload' && channels === initialChannelsStateRef.current,
214
+ activeQueryType === 'queryLocalDB' ? true : activeQueryType === 'reload' && channels === null,
218
215
  loadingNextPage: activeQueryType === 'loadChannels',
219
216
  loadNextPage,
220
217
  refreshing: activeQueryType === 'refresh',
221
218
  refreshList,
222
219
  reloadList,
223
- setChannels,
220
+ // Although channels can be null, there is no practical case where channels will be null
221
+ // when setChannels is used. setChannels is only recommended to be used for overriding
222
+ // event handler. Thus instead of adding if check for channels === null, its better to
223
+ // simply reassign types here.
224
+ setChannels: setChannels as React.Dispatch<React.SetStateAction<Channel<StreamChatGenerics>[]>>,
224
225
  staticChannelsActive,
225
226
  };
226
227
  };
@@ -48,7 +48,7 @@ export type ChannelsContextValue<
48
48
  /**
49
49
  * Channels can be either an array of channels or a promise which resolves to an array of channels
50
50
  */
51
- channels: Channel<StreamChatGenerics>[];
51
+ channels: Channel<StreamChatGenerics>[] | null;
52
52
  /**
53
53
  * Custom indicator to use when channel list is empty
54
54
  *
package/src/native.ts CHANGED
@@ -27,7 +27,7 @@ export let compressImage: CompressImage = fail;
27
27
  type DeleteFile = ({ uri }: { uri: string }) => Promise<boolean> | never;
28
28
  export let deleteFile: DeleteFile = fail;
29
29
 
30
- type GetLocalAssetUri = (uriOrAssetId: string) => never;
30
+ type GetLocalAssetUri = (uriOrAssetId: string) => Promise<string> | never;
31
31
  export let getLocalAssetUri: GetLocalAssetUri = fail;
32
32
 
33
33
  type GetPhotos = ({ after, first }: { first: number; after?: string }) =>
@@ -157,7 +157,7 @@ export type SoundType = {
157
157
  source?: { uri: string },
158
158
  initialStatus?: Partial<AVPlaybackStatusToSet>,
159
159
  onPlaybackStatusUpdate?: (playbackStatus: PlaybackStatus) => void,
160
- ) => SoundReturnType | null;
160
+ ) => Promise<SoundReturnType | null>;
161
161
  Player: React.ComponentType<SoundReturnType> | null;
162
162
  };
163
163
 
package/src/version.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "5.3.0-beta.1"
2
+ "version": "5.3.0"
3
3
  }