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

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 (31) 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/version.json +1 -1
  11. package/lib/module/components/ChannelList/ChannelList.js +4 -4
  12. package/lib/module/components/ChannelList/ChannelList.js.map +1 -1
  13. package/lib/module/components/ChannelList/ChannelListMessenger.js +4 -4
  14. package/lib/module/components/ChannelList/ChannelListMessenger.js.map +1 -1
  15. package/lib/module/components/ChannelList/hooks/useCreateChannelsContext.js +1 -1
  16. package/lib/module/components/ChannelList/hooks/useCreateChannelsContext.js.map +1 -1
  17. package/lib/module/components/ChannelList/hooks/usePaginatedChannels.js +6 -7
  18. package/lib/module/components/ChannelList/hooks/usePaginatedChannels.js.map +1 -1
  19. package/lib/module/contexts/channelsContext/ChannelsContext.js.map +1 -1
  20. package/lib/module/version.json +1 -1
  21. package/lib/typescript/components/ChannelList/hooks/usePaginatedChannels.d.ts +1 -1
  22. package/lib/typescript/contexts/channelsContext/ChannelsContext.d.ts +1 -1
  23. package/package.json +1 -1
  24. package/src/__tests__/offline-feature.test.js +3 -1
  25. package/src/components/ChannelList/ChannelList.tsx +3 -2
  26. package/src/components/ChannelList/ChannelListMessenger.tsx +3 -3
  27. package/src/components/ChannelList/__tests__/ChannelList.test.js +1 -1
  28. package/src/components/ChannelList/hooks/useCreateChannelsContext.ts +1 -1
  29. package/src/components/ChannelList/hooks/usePaginatedChannels.ts +12 -11
  30. package/src/contexts/channelsContext/ChannelsContext.tsx +1 -1
  31. package/src/version.json +1 -1
@@ -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/version.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "5.3.0-beta.1"
2
+ "version": "5.3.0-beta.2"
3
3
  }