stream-chat-react-native-core 4.3.1-beta.2 → 4.4.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 (76) hide show
  1. package/README.md +1 -1
  2. package/lib/commonjs/components/Attachment/Card.js +25 -28
  3. package/lib/commonjs/components/Attachment/Card.js.map +1 -1
  4. package/lib/commonjs/components/Attachment/FileAttachment.js +19 -24
  5. package/lib/commonjs/components/Attachment/FileAttachment.js.map +1 -1
  6. package/lib/commonjs/components/Attachment/Giphy.js +27 -25
  7. package/lib/commonjs/components/Attachment/Giphy.js.map +1 -1
  8. package/lib/commonjs/components/Attachment/hooks/useGoToURL.js +42 -0
  9. package/lib/commonjs/components/Attachment/hooks/useGoToURL.js.map +1 -0
  10. package/lib/commonjs/components/AttachmentPicker/AttachmentPicker.js +11 -7
  11. package/lib/commonjs/components/AttachmentPicker/AttachmentPicker.js.map +1 -1
  12. package/lib/commonjs/components/Chat/Chat.js +4 -8
  13. package/lib/commonjs/components/Chat/Chat.js.map +1 -1
  14. package/lib/commonjs/components/Chat/hooks/useCreateChatContext.js +1 -3
  15. package/lib/commonjs/components/Chat/hooks/useCreateChatContext.js.map +1 -1
  16. package/lib/commonjs/components/Message/MessageSimple/utils/renderText.js +20 -14
  17. package/lib/commonjs/components/Message/MessageSimple/utils/renderText.js.map +1 -1
  18. package/lib/commonjs/components/MessageList/ScrollToBottomButton.js +8 -6
  19. package/lib/commonjs/components/MessageList/ScrollToBottomButton.js.map +1 -1
  20. package/lib/commonjs/contexts/chatContext/ChatContext.js +2 -2
  21. package/lib/commonjs/contexts/chatContext/ChatContext.js.map +1 -1
  22. package/lib/commonjs/contexts/themeContext/utils/theme.js.map +1 -1
  23. package/lib/commonjs/version.json +1 -1
  24. package/lib/module/components/Attachment/Card.js +25 -28
  25. package/lib/module/components/Attachment/Card.js.map +1 -1
  26. package/lib/module/components/Attachment/FileAttachment.js +19 -24
  27. package/lib/module/components/Attachment/FileAttachment.js.map +1 -1
  28. package/lib/module/components/Attachment/Giphy.js +27 -25
  29. package/lib/module/components/Attachment/Giphy.js.map +1 -1
  30. package/lib/module/components/Attachment/hooks/useGoToURL.js +42 -0
  31. package/lib/module/components/Attachment/hooks/useGoToURL.js.map +1 -0
  32. package/lib/module/components/AttachmentPicker/AttachmentPicker.js +11 -7
  33. package/lib/module/components/AttachmentPicker/AttachmentPicker.js.map +1 -1
  34. package/lib/module/components/Chat/Chat.js +4 -8
  35. package/lib/module/components/Chat/Chat.js.map +1 -1
  36. package/lib/module/components/Chat/hooks/useCreateChatContext.js +1 -3
  37. package/lib/module/components/Chat/hooks/useCreateChatContext.js.map +1 -1
  38. package/lib/module/components/Message/MessageSimple/utils/renderText.js +20 -14
  39. package/lib/module/components/Message/MessageSimple/utils/renderText.js.map +1 -1
  40. package/lib/module/components/MessageList/ScrollToBottomButton.js +8 -6
  41. package/lib/module/components/MessageList/ScrollToBottomButton.js.map +1 -1
  42. package/lib/module/contexts/chatContext/ChatContext.js +2 -2
  43. package/lib/module/contexts/chatContext/ChatContext.js.map +1 -1
  44. package/lib/module/contexts/themeContext/utils/theme.js.map +1 -1
  45. package/lib/module/version.json +1 -1
  46. package/lib/typescript/components/Attachment/FileAttachment.d.ts +0 -1
  47. package/lib/typescript/components/Attachment/hooks/useGoToURL.d.ts +2 -0
  48. package/lib/typescript/components/Chat/hooks/useCreateChatContext.d.ts +1 -1
  49. package/lib/typescript/contexts/chatContext/ChatContext.d.ts +1 -5
  50. package/lib/typescript/contexts/themeContext/utils/theme.d.ts +1 -0
  51. package/package.json +2 -2
  52. package/src/components/Attachment/Card.tsx +5 -13
  53. package/src/components/Attachment/FileAttachment.tsx +5 -13
  54. package/src/components/Attachment/Giphy.tsx +3 -1
  55. package/src/components/Attachment/__tests__/Attachment.test.js +39 -0
  56. package/src/components/Attachment/hooks/useGoToURL.ts +27 -0
  57. package/src/components/AttachmentPicker/AttachmentPicker.tsx +23 -13
  58. package/src/components/ChannelList/hooks/listeners/__tests__/useChannelUpdated.test.tsx +0 -1
  59. package/src/components/Chat/Chat.tsx +0 -4
  60. package/src/components/Chat/hooks/useCreateChatContext.ts +0 -2
  61. package/src/components/Message/MessageSimple/utils/renderText.tsx +8 -2
  62. package/src/components/MessageInput/__tests__/__snapshots__/FileUploadPreview.test.js.snap +8 -8
  63. package/src/components/MessageInput/__tests__/__snapshots__/MessageInput.test.js.snap +2 -2
  64. package/src/components/MessageList/ScrollToBottomButton.tsx +2 -1
  65. package/src/components/MessageList/__tests__/__snapshots__/ScrollToBottomButton.test.js.snap +1 -0
  66. package/src/contexts/chatContext/ChatContext.tsx +1 -5
  67. package/src/contexts/themeContext/utils/theme.ts +1 -0
  68. package/src/version.json +1 -1
  69. package/lib/commonjs/components/Chat/hooks/useAppSettings.js +0 -80
  70. package/lib/commonjs/components/Chat/hooks/useAppSettings.js.map +0 -1
  71. package/lib/module/components/Chat/hooks/useAppSettings.js +0 -80
  72. package/lib/module/components/Chat/hooks/useAppSettings.js.map +0 -1
  73. package/lib/typescript/components/Chat/hooks/__tests__/useAppSettings.test.d.ts +0 -1
  74. package/lib/typescript/components/Chat/hooks/useAppSettings.d.ts +0 -3
  75. package/src/components/Chat/hooks/__tests__/useAppSettings.test.tsx +0 -34
  76. package/src/components/Chat/hooks/useAppSettings.ts +0 -39
@@ -65,6 +65,7 @@ const styles = StyleSheet.create({
65
65
  },
66
66
  giphyHeaderTitle: {
67
67
  fontSize: 14,
68
+ marginLeft: 8,
68
69
  },
69
70
  giphyMask: {
70
71
  bottom: 8,
@@ -84,7 +85,8 @@ const styles = StyleSheet.create({
84
85
  width: '60%',
85
86
  },
86
87
  selectionContainer: {
87
- borderBottomLeftRadius: 8,
88
+ borderBottomRightRadius: 0,
89
+ borderRadius: 16,
88
90
  borderWidth: 1,
89
91
  overflow: 'hidden',
90
92
  width: 272,
@@ -1,5 +1,8 @@
1
1
  import React from 'react';
2
2
 
3
+ import { Linking } from 'react-native';
4
+
5
+ import { act, renderHook } from '@testing-library/react-hooks';
3
6
  import { fireEvent, render, waitFor } from '@testing-library/react-native';
4
7
  import { v4 as uuidv4 } from 'uuid';
5
8
 
@@ -15,6 +18,7 @@ import {
15
18
  import { generateMessage } from '../../../mock-builders/generator/message';
16
19
  import { Attachment } from '../Attachment';
17
20
  import { AttachmentActions } from '../AttachmentActions';
21
+ import { useGoToURL } from '../hooks/useGoToURL';
18
22
 
19
23
  const getAttachmentComponent = (props) => {
20
24
  const message = generateMessage();
@@ -120,4 +124,39 @@ describe('Attachment', () => {
120
124
  expect(getByTestId('card-attachment')).toBeTruthy();
121
125
  });
122
126
  });
127
+
128
+ it('should open the URL in the browser', async () => {
129
+ jest.spyOn(Linking, 'canOpenURL').mockImplementation(jest.fn().mockResolvedValue(true));
130
+
131
+ jest.spyOn(Linking, 'openURL').mockImplementation(jest.fn().mockResolvedValue(false));
132
+
133
+ const { result, waitFor } = renderHook(() => useGoToURL('www.google.com'));
134
+
135
+ const [error, openURL] = result.current;
136
+
137
+ await act(openURL);
138
+
139
+ await waitFor(() => {
140
+ expect(Linking.canOpenURL).toHaveBeenCalled();
141
+ expect(error).not.toBeTruthy();
142
+ expect(Linking.openURL).toHaveBeenCalled();
143
+ });
144
+ });
145
+
146
+ it('should open the URL in the browser when no url', async () => {
147
+ jest.spyOn(Linking, 'canOpenURL').mockImplementation(jest.fn().mockResolvedValue(false));
148
+
149
+ jest.spyOn(Linking, 'openURL').mockImplementation(jest.fn().mockResolvedValue(true));
150
+
151
+ const { result, waitForNextUpdate } = await renderHook(() => useGoToURL());
152
+ const [error, openURL] = result.current;
153
+
154
+ act(openURL);
155
+
156
+ await waitForNextUpdate(() => {
157
+ expect(Linking.canOpenURL).toHaveBeenCalled();
158
+ expect(error).toBeTruthy();
159
+ expect(Linking.openURL).not.toHaveBeenCalled();
160
+ });
161
+ });
123
162
  });
@@ -0,0 +1,27 @@
1
+ import { useState } from 'react';
2
+ import { Linking } from 'react-native';
3
+
4
+ export type UseGoToURLType = (url?: string) => [boolean, () => Promise<void>];
5
+
6
+ export const useGoToURL: UseGoToURLType = (url?: string) => {
7
+ const [error, setError] = useState<boolean>(false);
8
+
9
+ let finalUrl = url as string;
10
+ const pattern = new RegExp(/^\S+:\/\//);
11
+
12
+ if (!pattern.test(finalUrl)) {
13
+ finalUrl = 'http://' + url;
14
+ }
15
+
16
+ const openURL = () =>
17
+ Linking.canOpenURL(finalUrl).then((supported) => {
18
+ if (supported) {
19
+ Linking.openURL(finalUrl);
20
+ } else {
21
+ setError(true);
22
+ console.log(`Don't know how to open URI: ${finalUrl}`);
23
+ }
24
+ });
25
+
26
+ return [error, openURL];
27
+ };
@@ -34,7 +34,7 @@ const styles = StyleSheet.create({
34
34
  });
35
35
 
36
36
  const screenHeight = vh(100);
37
- const fullScreenHeight = Dimensions.get('screen').height;
37
+ const fullScreenHeight = Dimensions.get('window').height;
38
38
 
39
39
  type AttachmentImageProps = {
40
40
  ImageOverlaySelectedComponent: React.ComponentType;
@@ -326,26 +326,36 @@ export const AttachmentPicker = React.forwardRef(
326
326
  : statusBarHeight
327
327
  : 0;
328
328
 
329
- /**
330
- * Snap points changing cause a rerender of the position,
331
- * this is an issue if you are calling close on the bottom sheet.
332
- */
333
- const snapPoints = useMemo(
334
- () => [
335
- attachmentPickerBottomSheetHeight ??
336
- 308 + (fullScreenHeight - screenHeight + androidBottomBarHeightAdjustment) - handleHeight,
337
- fullScreenHeight - topInset - handleHeight,
338
- ],
329
+ const initialSnapPoint = useMemo(
330
+ () =>
331
+ attachmentPickerBottomSheetHeight ?? Platform.OS === 'android'
332
+ ? 308 +
333
+ (fullScreenHeight - screenHeight + androidBottomBarHeightAdjustment) -
334
+ handleHeight
335
+ : 308 + (fullScreenHeight - screenHeight + androidBottomBarHeightAdjustment),
339
336
  [
340
- androidBottomBarHeightAdjustment,
341
337
  attachmentPickerBottomSheetHeight,
338
+ androidBottomBarHeightAdjustment,
342
339
  fullScreenHeight,
343
340
  handleHeight,
344
341
  screenHeight,
345
- topInset,
346
342
  ],
347
343
  );
348
344
 
345
+ const finalSnapPoint = useMemo(
346
+ () =>
347
+ Platform.OS === 'android'
348
+ ? fullScreenHeight - topInset - handleHeight
349
+ : fullScreenHeight - topInset,
350
+ [fullScreenHeight, handleHeight, topInset],
351
+ );
352
+
353
+ /**
354
+ * Snap points changing cause a rerender of the position,
355
+ * this is an issue if you are calling close on the bottom sheet.
356
+ */
357
+ const snapPoints = [initialSnapPoint, finalSnapPoint];
358
+
349
359
  return (
350
360
  <>
351
361
  <BottomSheet
@@ -55,7 +55,6 @@ describe('useChannelUpdated', () => {
55
55
  render(
56
56
  <ChatContext.Provider
57
57
  value={{
58
- appSettings: null,
59
58
  client: mockClient,
60
59
  connectionRecovering: false,
61
60
  isOnline: true,
@@ -5,7 +5,6 @@ import Dayjs from 'dayjs';
5
5
 
6
6
  import type { Channel } from 'stream-chat';
7
7
 
8
- import { useAppSettings } from './hooks/useAppSettings';
9
8
  import { useCreateChatContext } from './hooks/useCreateChatContext';
10
9
  import { useIsOnline } from './hooks/useIsOnline';
11
10
  import { useMutedUsers } from './hooks/useMutedUsers';
@@ -162,10 +161,7 @@ const ChatWithContext = <
162
161
 
163
162
  const setActiveChannel = (newChannel?: Channel<StreamChatGenerics>) => setChannel(newChannel);
164
163
 
165
- const appSettings = useAppSettings(client, isOnline);
166
-
167
164
  const chatContext = useCreateChatContext({
168
- appSettings,
169
165
  channel,
170
166
  client,
171
167
  connectionRecovering,
@@ -6,7 +6,6 @@ import type { DefaultStreamChatGenerics } from '../../../types/types';
6
6
  export const useCreateChatContext = <
7
7
  StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
8
8
  >({
9
- appSettings,
10
9
  channel,
11
10
  client,
12
11
  connectionRecovering,
@@ -22,7 +21,6 @@ export const useCreateChatContext = <
22
21
 
23
22
  const chatContext: ChatContextValue<StreamChatGenerics> = useMemo(
24
23
  () => ({
25
- appSettings,
26
24
  channel,
27
25
  client,
28
26
  connectionRecovering,
@@ -147,10 +147,16 @@ export const renderText = <
147
147
  },
148
148
  };
149
149
 
150
- const onLink = (url: string) =>
151
- onLinkParams
150
+ const onLink = (url: string) => {
151
+ const pattern = new RegExp(/^\S+:\/\//);
152
+ if (!pattern.test(url)) {
153
+ url = 'http://' + url;
154
+ }
155
+
156
+ return onLinkParams
152
157
  ? onLinkParams(url)
153
158
  : Linking.canOpenURL(url).then((canOpenUrl) => canOpenUrl && Linking.openURL(url));
159
+ };
154
160
 
155
161
  const link: ReactNodeOutput = (node, output, { ...state }) => {
156
162
  const onPress = (event: GestureResponderEvent) => {
@@ -1059,8 +1059,8 @@ Array [
1059
1059
  onChange={[Function]}
1060
1060
  snapPoints={
1061
1061
  Array [
1062
- 288,
1063
- 1314,
1062
+ 308,
1063
+ 1334,
1064
1064
  ]
1065
1065
  }
1066
1066
  >
@@ -2316,8 +2316,8 @@ Array [
2316
2316
  onChange={[Function]}
2317
2317
  snapPoints={
2318
2318
  Array [
2319
- 288,
2320
- 1314,
2319
+ 308,
2320
+ 1334,
2321
2321
  ]
2322
2322
  }
2323
2323
  >
@@ -3261,8 +3261,8 @@ Array [
3261
3261
  onChange={[Function]}
3262
3262
  snapPoints={
3263
3263
  Array [
3264
- 288,
3265
- 1314,
3264
+ 308,
3265
+ 1334,
3266
3266
  ]
3267
3267
  }
3268
3268
  >
@@ -4368,8 +4368,8 @@ Array [
4368
4368
  onChange={[Function]}
4369
4369
  snapPoints={
4370
4370
  Array [
4371
- 288,
4372
- 1314,
4371
+ 308,
4372
+ 1334,
4373
4373
  ]
4374
4374
  }
4375
4375
  >
@@ -703,8 +703,8 @@ Array [
703
703
  onChange={[Function]}
704
704
  snapPoints={
705
705
  Array [
706
- 288,
707
- 1314,
706
+ 308,
707
+ 1334,
708
708
  ]
709
709
  }
710
710
  >
@@ -63,6 +63,7 @@ export const ScrollToBottomButton: React.FC<ScrollToBottomButtonProps> = (props)
63
63
  colors: { accent_blue, black, white },
64
64
  messageList: {
65
65
  scrollToBottomButton: {
66
+ chevronColor,
66
67
  container,
67
68
  touchable,
68
69
  unreadCountNotificationContainer,
@@ -83,7 +84,7 @@ export const ScrollToBottomButton: React.FC<ScrollToBottomButtonProps> = (props)
83
84
  >
84
85
  <View style={[styles.wrapper, wrapper]}>
85
86
  <View style={[styles.container, { backgroundColor: white, shadowColor: black }, container]}>
86
- <Down />
87
+ <Down pathFill={chevronColor ? chevronColor : black} />
87
88
  </View>
88
89
  {!!unreadCount && (
89
90
  <View
@@ -68,6 +68,7 @@ exports[`ScrollToBottomButton should render the message notification and match s
68
68
  meetOrSlice={0}
69
69
  minX={0}
70
70
  minY={0}
71
+ pathFill="#000000"
71
72
  style={
72
73
  Array [
73
74
  Object {
@@ -1,6 +1,6 @@
1
1
  import React, { PropsWithChildren, useContext } from 'react';
2
2
 
3
- import type { AppSettingsAPIResponse, Channel, Mute, StreamChat } from 'stream-chat';
3
+ import type { Channel, Mute, StreamChat } from 'stream-chat';
4
4
 
5
5
  import type { DefaultStreamChatGenerics, UnknownType } from '../../types/types';
6
6
  import { getDisplayName } from '../utils/getDisplayName';
@@ -8,10 +8,6 @@ import { getDisplayName } from '../utils/getDisplayName';
8
8
  export type ChatContextValue<
9
9
  StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
10
10
  > = {
11
- /**
12
- * Object of application settings returned from Stream.
13
- * */
14
- appSettings: AppSettingsAPIResponse<StreamChatGenerics> | null;
15
11
  /**
16
12
  * The StreamChat client object
17
13
  *
@@ -334,6 +334,7 @@ export type Theme = {
334
334
  unreadCountNotificationContainer: ViewStyle;
335
335
  unreadCountNotificationText: TextStyle;
336
336
  wrapper: ViewStyle;
337
+ chevronColor?: Color;
337
338
  };
338
339
  typingIndicatorContainer: ViewStyle;
339
340
  };
package/src/version.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "4.3.1-beta.2"
2
+ "version": "4.4.0-beta.2"
3
3
  }
@@ -1,80 +0,0 @@
1
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useAppSettings = void 0;
7
-
8
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
-
10
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
-
12
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
13
-
14
- var _react = require("react");
15
-
16
- var useAppSettings = function useAppSettings(client, isOnline) {
17
- var _useState = (0, _react.useState)(null),
18
- _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
19
- appSettings = _useState2[0],
20
- setAppSettings = _useState2[1];
21
-
22
- var isMounted = (0, _react.useRef)(true);
23
- (0, _react.useEffect)(function () {
24
- function getAppSettings() {
25
- return _getAppSettings.apply(this, arguments);
26
- }
27
-
28
- function _getAppSettings() {
29
- _getAppSettings = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee() {
30
- var _appSettings;
31
-
32
- return _regenerator["default"].wrap(function _callee$(_context) {
33
- while (1) {
34
- switch (_context.prev = _context.next) {
35
- case 0:
36
- _context.prev = 0;
37
- _context.next = 3;
38
- return client.getAppSettings();
39
-
40
- case 3:
41
- _appSettings = _context.sent;
42
-
43
- if (isMounted.current) {
44
- setAppSettings(_appSettings);
45
- }
46
-
47
- _context.next = 10;
48
- break;
49
-
50
- case 7:
51
- _context.prev = 7;
52
- _context.t0 = _context["catch"](0);
53
-
54
- if (_context.t0 instanceof Error) {
55
- console.error("An error occurred while getting app settings: " + _context.t0);
56
- }
57
-
58
- case 10:
59
- case "end":
60
- return _context.stop();
61
- }
62
- }
63
- }, _callee, null, [[0, 7]]);
64
- }));
65
- return _getAppSettings.apply(this, arguments);
66
- }
67
-
68
- if (isOnline) {
69
- getAppSettings();
70
- }
71
-
72
- return function () {
73
- isMounted.current = false;
74
- };
75
- }, [client, isOnline]);
76
- return appSettings;
77
- };
78
-
79
- exports.useAppSettings = useAppSettings;
80
- //# sourceMappingURL=useAppSettings.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["useAppSettings.ts"],"names":["useAppSettings","client","isOnline","appSettings","setAppSettings","isMounted","getAppSettings","current","Error","console","error"],"mappings":";;;;;;;;;;;;;AAAA;;AAKO,IAAMA,cAAc,GAAG,SAAjBA,cAAiB,CAG5BC,MAH4B,EAI5BC,QAJ4B,EAKM;AAClC,kBAAsC,qBAAwC,IAAxC,CAAtC;AAAA;AAAA,MAAOC,WAAP;AAAA,MAAoBC,cAApB;;AACA,MAAMC,SAAS,GAAG,mBAAO,IAAP,CAAlB;AAEA,wBAAU,YAAM;AAAA,aACCC,cADD;AAAA;AAAA;;AAAA;AAAA,wFACd;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAE8BL,MAAM,CAACK,cAAP,EAF9B;;AAAA;AAEUH,gBAAAA,YAFV;;AAGI,oBAAIE,SAAS,CAACE,OAAd,EAAuB;AACrBH,kBAAAA,cAAc,CAACD,YAAD,CAAd;AACD;;AALL;AAAA;;AAAA;AAAA;AAAA;;AAOI,oBAAI,uBAAiBK,KAArB,EAA4B;AAC1BC,kBAAAA,OAAO,CAACC,KAAR;AACD;;AATL;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,OADc;AAAA;AAAA;;AAcd,QAAIR,QAAJ,EAAc;AACZI,MAAAA,cAAc;AACf;;AAED,WAAO,YAAM;AACXD,MAAAA,SAAS,CAACE,OAAV,GAAoB,KAApB;AACD,KAFD;AAGD,GArBD,EAqBG,CAACN,MAAD,EAASC,QAAT,CArBH;AAuBA,SAAOC,WAAP;AACD,CAjCM","sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { AppSettingsAPIResponse, StreamChat } from 'stream-chat';\nimport type { DefaultStreamChatGenerics } from 'stream-chat-react-native';\n\nexport const useAppSettings = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n client: StreamChat<StreamChatGenerics>,\n isOnline: boolean,\n): AppSettingsAPIResponse | null => {\n const [appSettings, setAppSettings] = useState<AppSettingsAPIResponse | null>(null);\n const isMounted = useRef(true);\n\n useEffect(() => {\n async function getAppSettings() {\n try {\n const appSettings = await client.getAppSettings();\n if (isMounted.current) {\n setAppSettings(appSettings);\n }\n } catch (error: unknown) {\n if (error instanceof Error) {\n console.error(`An error occurred while getting app settings: ${error}`);\n }\n }\n }\n\n if (isOnline) {\n getAppSettings();\n }\n\n return () => {\n isMounted.current = false;\n };\n }, [client, isOnline]);\n\n return appSettings;\n};\n"]}
@@ -1,80 +0,0 @@
1
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useAppSettings = void 0;
7
-
8
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
-
10
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
-
12
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
13
-
14
- var _react = require("react");
15
-
16
- var useAppSettings = function useAppSettings(client, isOnline) {
17
- var _useState = (0, _react.useState)(null),
18
- _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
19
- appSettings = _useState2[0],
20
- setAppSettings = _useState2[1];
21
-
22
- var isMounted = (0, _react.useRef)(true);
23
- (0, _react.useEffect)(function () {
24
- function getAppSettings() {
25
- return _getAppSettings.apply(this, arguments);
26
- }
27
-
28
- function _getAppSettings() {
29
- _getAppSettings = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee() {
30
- var _appSettings;
31
-
32
- return _regenerator["default"].wrap(function _callee$(_context) {
33
- while (1) {
34
- switch (_context.prev = _context.next) {
35
- case 0:
36
- _context.prev = 0;
37
- _context.next = 3;
38
- return client.getAppSettings();
39
-
40
- case 3:
41
- _appSettings = _context.sent;
42
-
43
- if (isMounted.current) {
44
- setAppSettings(_appSettings);
45
- }
46
-
47
- _context.next = 10;
48
- break;
49
-
50
- case 7:
51
- _context.prev = 7;
52
- _context.t0 = _context["catch"](0);
53
-
54
- if (_context.t0 instanceof Error) {
55
- console.error("An error occurred while getting app settings: " + _context.t0);
56
- }
57
-
58
- case 10:
59
- case "end":
60
- return _context.stop();
61
- }
62
- }
63
- }, _callee, null, [[0, 7]]);
64
- }));
65
- return _getAppSettings.apply(this, arguments);
66
- }
67
-
68
- if (isOnline) {
69
- getAppSettings();
70
- }
71
-
72
- return function () {
73
- isMounted.current = false;
74
- };
75
- }, [client, isOnline]);
76
- return appSettings;
77
- };
78
-
79
- exports.useAppSettings = useAppSettings;
80
- //# sourceMappingURL=useAppSettings.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["useAppSettings.ts"],"names":["useAppSettings","client","isOnline","appSettings","setAppSettings","isMounted","getAppSettings","current","Error","console","error"],"mappings":";;;;;;;;;;;;;AAAA;;AAKO,IAAMA,cAAc,GAAG,SAAjBA,cAAiB,CAG5BC,MAH4B,EAI5BC,QAJ4B,EAKM;AAClC,kBAAsC,qBAAwC,IAAxC,CAAtC;AAAA;AAAA,MAAOC,WAAP;AAAA,MAAoBC,cAApB;;AACA,MAAMC,SAAS,GAAG,mBAAO,IAAP,CAAlB;AAEA,wBAAU,YAAM;AAAA,aACCC,cADD;AAAA;AAAA;;AAAA;AAAA,wFACd;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAE8BL,MAAM,CAACK,cAAP,EAF9B;;AAAA;AAEUH,gBAAAA,YAFV;;AAGI,oBAAIE,SAAS,CAACE,OAAd,EAAuB;AACrBH,kBAAAA,cAAc,CAACD,YAAD,CAAd;AACD;;AALL;AAAA;;AAAA;AAAA;AAAA;;AAOI,oBAAI,uBAAiBK,KAArB,EAA4B;AAC1BC,kBAAAA,OAAO,CAACC,KAAR;AACD;;AATL;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,OADc;AAAA;AAAA;;AAcd,QAAIR,QAAJ,EAAc;AACZI,MAAAA,cAAc;AACf;;AAED,WAAO,YAAM;AACXD,MAAAA,SAAS,CAACE,OAAV,GAAoB,KAApB;AACD,KAFD;AAGD,GArBD,EAqBG,CAACN,MAAD,EAASC,QAAT,CArBH;AAuBA,SAAOC,WAAP;AACD,CAjCM","sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { AppSettingsAPIResponse, StreamChat } from 'stream-chat';\nimport type { DefaultStreamChatGenerics } from 'stream-chat-react-native';\n\nexport const useAppSettings = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n client: StreamChat<StreamChatGenerics>,\n isOnline: boolean,\n): AppSettingsAPIResponse | null => {\n const [appSettings, setAppSettings] = useState<AppSettingsAPIResponse | null>(null);\n const isMounted = useRef(true);\n\n useEffect(() => {\n async function getAppSettings() {\n try {\n const appSettings = await client.getAppSettings();\n if (isMounted.current) {\n setAppSettings(appSettings);\n }\n } catch (error: unknown) {\n if (error instanceof Error) {\n console.error(`An error occurred while getting app settings: ${error}`);\n }\n }\n }\n\n if (isOnline) {\n getAppSettings();\n }\n\n return () => {\n isMounted.current = false;\n };\n }, [client, isOnline]);\n\n return appSettings;\n};\n"]}
@@ -1,3 +0,0 @@
1
- import type { AppSettingsAPIResponse, StreamChat } from 'stream-chat';
2
- import type { DefaultStreamChatGenerics } from 'stream-chat-react-native';
3
- export declare const useAppSettings: <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>(client: StreamChat<StreamChatGenerics>, isOnline: boolean) => AppSettingsAPIResponse | null;
@@ -1,34 +0,0 @@
1
- import React from 'react';
2
- import { Text } from 'react-native';
3
-
4
- import { render, waitFor } from '@testing-library/react-native';
5
-
6
- import type { StreamChat } from 'stream-chat';
7
-
8
- import { useAppSettings } from '../useAppSettings';
9
-
10
- describe('useAppSettings', () => {
11
- it('will return a settings object if the backend call is successful', async () => {
12
- const TestComponent = () => {
13
- const isOnline = true;
14
- const appSettings = useAppSettings(
15
- {
16
- getAppSettings: jest.fn().mockReturnValue(
17
- Promise.resolve({
18
- auto_translation_enabled: true,
19
- }),
20
- ),
21
- } as unknown as StreamChat,
22
- isOnline,
23
- );
24
-
25
- return <Text>{JSON.stringify(appSettings)}</Text>;
26
- };
27
-
28
- const { getByText } = render(<TestComponent />);
29
-
30
- await waitFor(() => {
31
- expect(getByText(JSON.stringify({ auto_translation_enabled: true }))).toBeTruthy();
32
- });
33
- });
34
- });
@@ -1,39 +0,0 @@
1
- import { useEffect, useRef, useState } from 'react';
2
-
3
- import type { AppSettingsAPIResponse, StreamChat } from 'stream-chat';
4
- import type { DefaultStreamChatGenerics } from 'stream-chat-react-native';
5
-
6
- export const useAppSettings = <
7
- StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
8
- >(
9
- client: StreamChat<StreamChatGenerics>,
10
- isOnline: boolean,
11
- ): AppSettingsAPIResponse | null => {
12
- const [appSettings, setAppSettings] = useState<AppSettingsAPIResponse | null>(null);
13
- const isMounted = useRef(true);
14
-
15
- useEffect(() => {
16
- async function getAppSettings() {
17
- try {
18
- const appSettings = await client.getAppSettings();
19
- if (isMounted.current) {
20
- setAppSettings(appSettings);
21
- }
22
- } catch (error: unknown) {
23
- if (error instanceof Error) {
24
- console.error(`An error occurred while getting app settings: ${error}`);
25
- }
26
- }
27
- }
28
-
29
- if (isOnline) {
30
- getAppSettings();
31
- }
32
-
33
- return () => {
34
- isMounted.current = false;
35
- };
36
- }, [client, isOnline]);
37
-
38
- return appSettings;
39
- };