From e1ede96d17d944a6f1d6c94877e2fa704fe0285b Mon Sep 17 00:00:00 2001 From: Oliver Lazoroski Date: Tue, 1 Dec 2026 16:18:37 +0100 Subject: [PATCH 1/2] fix(deps): bump @stream-io/state-store to 1.3.0 --- examples/SampleApp/package.json | 2 +- package/package.json | 2 +- yarn.lock | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/SampleApp/package.json b/examples/SampleApp/package.json index c48a1f3327..32771c59e0 100644 --- a/examples/SampleApp/package.json +++ b/examples/SampleApp/package.json @@ -44,7 +44,7 @@ "@react-navigation/native": "^7.5.0", "@react-navigation/native-stack": "^7.20.0", "@shopify/flash-list": "^2.3.3", - "@stream-io/state-store": "^1.2.0", + "@stream-io/state-store": "^1.3.0", "dayjs": "^1.11.23", "emoji-mart": "^5.6.0", "lodash.mergewith": "^4.6.2", diff --git a/package/package.json b/package/package.json index 5317fd7ec1..61cc941c21 100644 --- a/package/package.json +++ b/package/package.json @@ -74,7 +74,7 @@ "@gorhom/bottom-sheet": "^5.2.14", "@legendapp/list": "^3.7.1", "@stream-io/i18n": "^1.1.0", - "@stream-io/state-store": "^1.2.0", + "@stream-io/state-store": "^1.3.0", "@ungap/structured-clone": "^1.3.0", "dayjs": "^1.11.23", "emoji-regex": "^10.4.0", diff --git a/yarn.lock b/yarn.lock index 2760258c9f..334c76f8a6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6757,9 +6757,9 @@ __metadata: languageName: node linkType: hard -"@stream-io/state-store@npm:^1.2.0": - version: 1.2.0 - resolution: "@stream-io/state-store@npm:1.2.0" +"@stream-io/state-store@npm:^1.2.0, @stream-io/state-store@npm:^1.3.0": + version: 1.3.0 + resolution: "@stream-io/state-store@npm:1.3.0" peerDependencies: react: ^17 || ^18 || ^19 use-sync-external-store: ^1.5.0 @@ -6768,7 +6768,7 @@ __metadata: optional: true use-sync-external-store: optional: true - checksum: 10c0/27179805cb9a042416c741e1759c3324eefae0b27612c50f5fa0e0e13675d71bbe0a324978fcb5fdceaa4df5a99d11c6746eae319761216861b338e8cb7f1928 + checksum: 10c0/92cfd7e3f5008dc84cb0bf7b8cb75a1501ef6fe32c17671f40f2f5ba5a2f874da3ecd806cde277c74f0cdf1443ae7f3e649184319511d803a56efe6acb6f6eb8 languageName: node linkType: hard @@ -19631,7 +19631,7 @@ __metadata: "@react-navigation/native-stack": "npm:^7.20.0" "@rnx-kit/metro-config": "npm:^2.2.6" "@shopify/flash-list": "npm:^2.3.3" - "@stream-io/state-store": "npm:^1.2.0" + "@stream-io/state-store": "npm:^1.3.0" "@stream-io/typescript-config": "workspace:^" "@types/lodash.mergewith": "npm:^4.6.9" "@types/react": "npm:^19.3.0" @@ -20464,7 +20464,7 @@ __metadata: "@shopify/flash-list": "npm:^2.3.3" "@shopify/react-native-skia": "npm:^2.13.0" "@stream-io/i18n": "npm:^1.1.0" - "@stream-io/state-store": "npm:^1.2.0" + "@stream-io/state-store": "npm:^1.3.0" "@stream-io/typescript-config": "workspace:^" "@testing-library/jest-native": "npm:^5.4.3" "@testing-library/react-native": "npm:13.2.0" From 54c2e0eec462669c18e2f6f073888c204f8e9f3a Mon Sep 17 00:00:00 2001 From: Oliver Lazoroski Date: Wed, 2 Dec 2026 10:17:54 +0100 Subject: [PATCH 2/2] fix(hooks): use the state-store React binding for useStateStore Bump @stream-io/state-store to 1.3.1, which notifies selector subscribers when a selection shrinks, and replace the SDK's own useStateStore with the one from @stream-io/state-store/react-bindings. The old hook compared only the cached selection's keys, so a selection that grew (an added key, or an array growing with the same prefix) kept returning the stale value. useStateStore stays exported from the SDK as a re-export of the binding. --- examples/SampleApp/package.json | 2 +- package/package.json | 2 +- .../AITypingIndicatorView/hooks/useAIState.ts | 3 +- .../Accessibility/OverlayA11yShield.tsx | 3 +- .../Attachment/Audio/AudioAttachment.tsx | 2 +- .../AttachmentPickerItem.tsx | 2 +- .../components/AttachmentPickerContent.tsx | 2 +- .../AutoCompleteInput/AutoCompleteInput.tsx | 2 +- .../AutoCompleteSuggestionList.tsx | 2 +- package/src/components/Channel/Channel.tsx | 3 +- .../src/components/Channel/ChannelShell.tsx | 2 +- .../hooks/useCreateOwnCapabilitiesContext.ts | 2 +- .../Channel/hooks/useSupersededChannelSwap.ts | 3 +- .../ChannelEditDetailsFormContent.tsx | 3 +- .../components/ChannelEditImageSheet.tsx | 3 +- .../components/ChannelEditName.tsx | 3 +- .../members/ChannelAddMembersFormContent.tsx | 2 +- .../components/members/ChannelMemberList.tsx | 2 +- .../navigation-section/FileAttachmentList.tsx | 2 +- .../navigation-section/MediaList.tsx | 2 +- .../navigation-section/PinnedMessageList.tsx | 2 +- .../hooks/useChannelMembersState.ts | 3 +- .../hooks/useChannelOnlineMemberCount.ts | 3 +- .../ChannelList/hooks/useMutedUsers.ts | 2 +- .../ChannelList/hooks/usePaginatedChannels.ts | 2 +- .../ChannelMessagePreviewDeliveryStatus.tsx | 2 +- .../hooks/useChannelPreviewData.ts | 3 +- .../hooks/useChannelPreviewDraftMessage.ts | 3 +- .../hooks/useChannelPreviewPollLabel.ts | 2 +- .../ChannelPreview/hooks/useIsChannelMuted.ts | 3 +- package/src/components/Chat/Chat.tsx | 2 +- .../Chat/hooks/useNetworkConnectionState.ts | 2 +- .../Chat/hooks/useWSConnectionState.ts | 2 +- .../components/ImageGallery/ImageGallery.tsx | 3 +- .../components/AnimatedGalleryImage.tsx | 3 +- .../components/AnimatedGalleryVideo.tsx | 4 +- .../components/ImageGalleryA11yProbe.tsx | 3 +- .../components/ImageGalleryFooter.tsx | 3 +- .../components/ImageGalleryHeader.tsx | 3 +- .../components/ImageGalleryVideoControl.tsx | 3 +- .../ImageGallery/components/ImageGrid.tsx | 3 +- .../Headers/MessageReminderHeader.tsx | 2 +- .../Message/MessageItemView/MessageFooter.tsx | 2 +- .../Message/MessageItemView/MessageHeader.tsx | 2 +- .../Message/MessageItemView/MessageStatus.tsx | 2 +- .../MessageItemView/MessageWrapper.tsx | 2 +- .../hooks/useIsMessageDeliveredToOthers.ts | 2 +- .../Message/hooks/useIsMessageReadByOthers.ts | 2 +- .../Message/hooks/useMessageDeliveryData.ts | 2 +- .../Message/hooks/useMessageReadData.ts | 2 +- .../Message/hooks/useUserMuteActive.ts | 2 +- .../components/MessageInput/CommandChip.tsx | 3 +- .../MessageInput/MessageComposer.tsx | 2 +- .../MessageComposerLeadingView.tsx | 3 +- .../MessageInput/MessageInputHeaderView.tsx | 3 +- .../MessageInput/MessageInputTrailingView.tsx | 3 +- .../ShowThreadMessageInChannelButton.tsx | 2 +- .../AudioRecorder/AudioRecorder.tsx | 2 +- .../AudioRecorder/AudioRecordingButton.tsx | 3 +- .../AudioRecordingInProgress.tsx | 2 +- .../AudioRecorder/AudioRecordingPreview.tsx | 2 +- .../components/OutputButtons/index.tsx | 2 +- .../hooks/useCooldownRemaining.tsx | 2 +- .../MessageInput/hooks/useIsCooldownActive.ts | 2 +- .../MessageInput/hooks/useLinkPreviews.ts | 2 +- .../MessageList/MessageFlashList.tsx | 3 +- .../components/MessageList/MessageList.tsx | 2 +- .../MessageList/TypingIndicatorContainer.tsx | 2 +- .../UnreadMessagesNotification.tsx | 2 +- .../dateSeparatorSystemMessages.test.tsx | 2 +- .../MessageList/hooks/useMessageList.ts | 3 +- .../MessageList/hooks/useMessageListFocus.ts | 3 +- .../hooks/useMessageListPagination.ts | 3 +- .../MessageList/hooks/useOwnUnreadCount.ts | 2 +- .../MessageList/hooks/useTypingUsers.ts | 2 +- .../Notifications/hooks/useNotifications.ts | 2 +- .../hooks/useSystemNotifications.ts | 2 +- .../src/components/Poll/CreatePollContent.tsx | 2 +- .../Poll/components/CreatePollOptions.tsx | 2 +- .../Poll/components/MultipleVotesSettings.tsx | 2 +- .../Poll/contexts/PollUIStateContext.tsx | 3 +- .../Poll/hooks/usePollStateStore.ts | 2 +- package/src/components/Reply/Reply.tsx | 2 +- package/src/components/Thread/Thread.tsx | 2 +- .../components/ThreadFooterComponent.tsx | 2 +- .../src/components/ThreadList/ThreadList.tsx | 2 +- .../components/ThreadList/ThreadListItem.tsx | 2 +- .../ThreadList/ThreadListUnreadBanner.tsx | 2 +- .../ThreadMessagePreviewDeliveryStatus.tsx | 2 +- package/src/components/ui/GiphyChip.tsx | 2 +- .../audioPlayerContext/AudioPlayerContext.tsx | 3 +- .../MessageComposerContext.tsx | 2 +- .../hooks/useActiveCommand.ts | 3 +- .../hooks/useAttachmentManagerState.ts | 3 +- .../hooks/useHasAttachments.ts | 3 +- .../hooks/useIsCommandDisabled.ts | 3 +- .../useMessageComposerHasSendableData.ts | 3 +- .../hooks/usePendingUploadsEnabled.ts | 3 +- .../hooks/__tests__/useStateStore.test.tsx | 109 ++++++++++++++++++ .../hooks/actions/useChannelActionItems.tsx | 2 +- .../actions/useChannelMemberActionItems.tsx | 2 +- package/src/hooks/index.ts | 2 +- .../useMessageDeliveryStatus.ts | 2 +- .../messagePreview/useMessagePreviewText.tsx | 2 +- package/src/hooks/useAttachmentPickerState.ts | 2 +- package/src/hooks/useChannelImage.ts | 3 +- package/src/hooks/useChannelMemberCount.ts | 3 +- .../src/hooks/useChannelMembershipState.ts | 3 +- package/src/hooks/useChannelName.ts | 3 +- .../src/hooks/useChannelOwnCapabilities.ts | 3 +- package/src/hooks/useClientNotifications.ts | 3 +- .../hooks/useDisplayedChannelMemberCount.ts | 3 +- .../src/hooks/useInAppNotificationsState.ts | 2 +- package/src/hooks/useIsTargetedMessage.ts | 3 +- package/src/hooks/useMessageReminder.ts | 3 +- .../src/hooks/usePendingAttachmentUpload.ts | 3 +- package/src/hooks/usePrunableMessageList.ts | 2 +- package/src/hooks/useQueryReminders.ts | 3 +- package/src/hooks/useStateStore.ts | 64 ---------- package/src/hooks/useStreami18n.ts | 2 +- .../state-store/edit-channel-details-store.ts | 2 +- .../src/state-store/message-overlay-store.ts | 3 +- package/src/state-store/selection-store.ts | 2 +- yarn.lock | 12 +- 124 files changed, 262 insertions(+), 215 deletions(-) create mode 100644 package/src/hooks/__tests__/useStateStore.test.tsx delete mode 100644 package/src/hooks/useStateStore.ts diff --git a/examples/SampleApp/package.json b/examples/SampleApp/package.json index 32771c59e0..d46ed0a572 100644 --- a/examples/SampleApp/package.json +++ b/examples/SampleApp/package.json @@ -44,7 +44,7 @@ "@react-navigation/native": "^7.5.0", "@react-navigation/native-stack": "^7.20.0", "@shopify/flash-list": "^2.3.3", - "@stream-io/state-store": "^1.3.0", + "@stream-io/state-store": "^1.3.1", "dayjs": "^1.11.23", "emoji-mart": "^5.6.0", "lodash.mergewith": "^4.6.2", diff --git a/package/package.json b/package/package.json index 61cc941c21..e3067b669c 100644 --- a/package/package.json +++ b/package/package.json @@ -74,7 +74,7 @@ "@gorhom/bottom-sheet": "^5.2.14", "@legendapp/list": "^3.7.1", "@stream-io/i18n": "^1.1.0", - "@stream-io/state-store": "^1.3.0", + "@stream-io/state-store": "^1.3.1", "@ungap/structured-clone": "^1.3.0", "dayjs": "^1.11.23", "emoji-regex": "^10.4.0", diff --git a/package/src/components/AITypingIndicatorView/hooks/useAIState.ts b/package/src/components/AITypingIndicatorView/hooks/useAIState.ts index 99406cb2bc..86ce980429 100644 --- a/package/src/components/AITypingIndicatorView/hooks/useAIState.ts +++ b/package/src/components/AITypingIndicatorView/hooks/useAIState.ts @@ -1,7 +1,6 @@ +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { AIState, AIStates, Channel } from 'stream-chat'; -import { useStateStore } from '../../../hooks/useStateStore'; - // Re-exports `AIStates` from `stream-chat` so it can be imported from this module. export { AIStates }; diff --git a/package/src/components/Accessibility/OverlayA11yShield.tsx b/package/src/components/Accessibility/OverlayA11yShield.tsx index 0fae556fba..103d8c10ff 100644 --- a/package/src/components/Accessibility/OverlayA11yShield.tsx +++ b/package/src/components/Accessibility/OverlayA11yShield.tsx @@ -1,10 +1,11 @@ import React, { PropsWithChildren } from 'react'; import { Platform, StyleSheet, View } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; + import { useAccessibilityServiceEnabled } from '../../a11y'; import { useAccessibilityContext } from '../../contexts/accessibilityContext/AccessibilityContext'; import { useOverlayContext } from '../../contexts/overlayContext/OverlayContext'; -import { useStateStore } from '../../hooks'; import { overlayStore } from '../../state-store/message-overlay-store'; const messageOverlayActiveSelector = (state: { id: string | undefined }) => ({ diff --git a/package/src/components/Attachment/Audio/AudioAttachment.tsx b/package/src/components/Attachment/Audio/AudioAttachment.tsx index 36cdef90b3..2232b3f4bc 100644 --- a/package/src/components/Attachment/Audio/AudioAttachment.tsx +++ b/package/src/components/Attachment/Audio/AudioAttachment.tsx @@ -1,6 +1,7 @@ import React, { RefObject, useEffect, useMemo } from 'react'; import { I18nManager, StyleProp, StyleSheet, Text, TextStyle, View, ViewStyle } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import dayjs from 'dayjs'; import duration from 'dayjs/plugin/duration'; @@ -17,7 +18,6 @@ import { PlayPauseButton } from './PlayPauseButton'; import { useChannelContext, useChatConfigContext, useTheme } from '../../../contexts'; import { useStableCallback } from '../../../hooks'; -import { useStateStore } from '../../../hooks'; import { useAudioPlayer } from '../../../hooks/useAudioPlayer'; import { NativeHandlers, diff --git a/package/src/components/AttachmentPicker/components/AttachmentMediaPicker/AttachmentPickerItem.tsx b/package/src/components/AttachmentPicker/components/AttachmentMediaPicker/AttachmentPickerItem.tsx index bd1a1a0f14..faa760bd99 100644 --- a/package/src/components/AttachmentPicker/components/AttachmentMediaPicker/AttachmentPickerItem.tsx +++ b/package/src/components/AttachmentPicker/components/AttachmentMediaPicker/AttachmentPickerItem.tsx @@ -2,6 +2,7 @@ import React, { useCallback } from 'react'; import { Alert, Image, StyleSheet, Text, View } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { AttachmentManagerState, FileReference, @@ -19,7 +20,6 @@ import { useMessageComposer } from '../../../../contexts/messageInputContext/hoo import { useMessageInputContext } from '../../../../contexts/messageInputContext/MessageInputContext'; import { useTheme } from '../../../../contexts/themeContext/ThemeContext'; import { useTranslationContext } from '../../../../contexts/translationContext/TranslationContext'; -import { useStateStore } from '../../../../hooks/useStateStore'; import { useWindowContentWidth } from '../../../../hooks/useWindowContentWidth'; import { NativeHandlers } from '../../../../native'; import { primitives } from '../../../../theme'; diff --git a/package/src/components/AttachmentPicker/components/AttachmentPickerContent.tsx b/package/src/components/AttachmentPicker/components/AttachmentPickerContent.tsx index 4af9095c37..cea42cc6d0 100644 --- a/package/src/components/AttachmentPicker/components/AttachmentPickerContent.tsx +++ b/package/src/components/AttachmentPicker/components/AttachmentPickerContent.tsx @@ -3,6 +3,7 @@ import { Linking, Platform, Pressable, StyleSheet, Text } from 'react-native'; import { FlatList } from 'react-native-gesture-handler'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { CommandSearchSource, CommandSuggestion, notifyCommandDisabled } from 'stream-chat'; import { AttachmentMediaPicker } from './AttachmentMediaPicker/AttachmentMediaPicker'; @@ -22,7 +23,6 @@ import { import { useComponentsContext } from '../../../contexts/componentsContext/ComponentsContext'; import { useTheme } from '../../../contexts/themeContext/ThemeContext'; import { useAttachmentPickerState, useStableCallback } from '../../../hooks'; -import { useStateStore } from '../../../hooks/useStateStore'; import { primitives } from '../../../theme'; import { CommandSuggestionItem } from '../../AutoCompleteInput/AutoCompleteSuggestionItem'; diff --git a/package/src/components/AutoCompleteInput/AutoCompleteInput.tsx b/package/src/components/AutoCompleteInput/AutoCompleteInput.tsx index 21cb099457..19b29e822c 100644 --- a/package/src/components/AutoCompleteInput/AutoCompleteInput.tsx +++ b/package/src/components/AutoCompleteInput/AutoCompleteInput.tsx @@ -10,6 +10,7 @@ import { import Animated, { LinearTransition } from 'react-native-reanimated'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { MessageComposerConfig, TextComposerState } from 'stream-chat'; import { @@ -26,7 +27,6 @@ import { } from '../../contexts/translationContext/TranslationContext'; import { useStableCallback } from '../../hooks'; -import { useStateStore } from '../../hooks/useStateStore'; import type { TextInputRef } from '../../types/react-native-compat'; import { useCooldownRemaining } from '../MessageInput/hooks/useCooldownRemaining'; diff --git a/package/src/components/AutoCompleteInput/AutoCompleteSuggestionList.tsx b/package/src/components/AutoCompleteInput/AutoCompleteSuggestionList.tsx index fbf58c32aa..dad3a054aa 100644 --- a/package/src/components/AutoCompleteInput/AutoCompleteSuggestionList.tsx +++ b/package/src/components/AutoCompleteInput/AutoCompleteSuggestionList.tsx @@ -5,6 +5,7 @@ import { FlatList } from 'react-native-gesture-handler'; import Animated, { LinearTransition, ZoomIn, ZoomOut } from 'react-native-reanimated'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { SearchSourceState, TextComposerState, TextComposerSuggestion } from 'stream-chat'; import { useA11yLabel } from '../../a11y/hooks/useA11yLabel'; @@ -13,7 +14,6 @@ import { useComponentsContext } from '../../contexts/componentsContext/Component import { useMessageComposer } from '../../contexts/messageInputContext/hooks/useMessageComposer'; import { useTheme } from '../../contexts/themeContext/ThemeContext'; import { useStableCallback } from '../../hooks'; -import { useStateStore } from '../../hooks/useStateStore'; import { primitives } from '../../theme'; import { ClippingFadeBottom } from '../UIComponents/ClippingFadeBottom'; diff --git a/package/src/components/Channel/Channel.tsx b/package/src/components/Channel/Channel.tsx index 75c3573e6e..6de4c52592 100644 --- a/package/src/components/Channel/Channel.tsx +++ b/package/src/components/Channel/Channel.tsx @@ -1,6 +1,8 @@ import React, { PropsWithChildren, useMemo } from 'react'; import { StyleSheet, Text } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; + import { ChannelConfigProps, ChannelShell } from './ChannelShell'; import { useChannelLifecycle } from './hooks/useChannelLifecycle'; @@ -14,7 +16,6 @@ import { TranslationContextValue, useTranslationContext, } from '../../contexts/translationContext/TranslationContext'; -import { useStateStore } from '../../hooks/useStateStore'; import { primitives } from '../../theme'; import { getChannelNotificationHostId } from '../Notifications/notificationTarget'; diff --git a/package/src/components/Channel/ChannelShell.tsx b/package/src/components/Channel/ChannelShell.tsx index 81962b36e6..c11d4391b4 100644 --- a/package/src/components/Channel/ChannelShell.tsx +++ b/package/src/components/Channel/ChannelShell.tsx @@ -1,6 +1,7 @@ import React, { PropsWithChildren, useCallback, useMemo, useState } from 'react'; import { View } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { Channel, ChannelConfig, @@ -43,7 +44,6 @@ import { import { useStableCallback } from '../../hooks'; import { useAppStateListener } from '../../hooks/useAppStateListener'; import { useAttachmentPickerBottomSheet } from '../../hooks/useAttachmentPickerBottomSheet'; -import { useStateStore } from '../../hooks/useStateStore'; import { isDocumentPickerAvailable, isImageMediaLibraryAvailable, diff --git a/package/src/components/Channel/hooks/useCreateOwnCapabilitiesContext.ts b/package/src/components/Channel/hooks/useCreateOwnCapabilitiesContext.ts index 766c696b2e..5456c08b45 100644 --- a/package/src/components/Channel/hooks/useCreateOwnCapabilitiesContext.ts +++ b/package/src/components/Channel/hooks/useCreateOwnCapabilitiesContext.ts @@ -1,5 +1,6 @@ import { useMemo } from 'react'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { Channel, OwnCapabilitiesState } from 'stream-chat'; import { @@ -7,7 +8,6 @@ import { OwnCapabilitiesContextValue, OwnCapability, } from '../../../contexts/ownCapabilitiesContext/OwnCapabilitiesContext'; -import { useStateStore } from '../../../hooks/useStateStore'; // TODO: Move own_capabilities as part of channel state rather than having to do // stuff like this. diff --git a/package/src/components/Channel/hooks/useSupersededChannelSwap.ts b/package/src/components/Channel/hooks/useSupersededChannelSwap.ts index bf9b1c7443..bfe761a494 100644 --- a/package/src/components/Channel/hooks/useSupersededChannelSwap.ts +++ b/package/src/components/Channel/hooks/useSupersededChannelSwap.ts @@ -1,7 +1,6 @@ +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { Channel, ChannelStateData, EditingAuditState } from 'stream-chat'; -import { useStateStore } from '../../../hooks/useStateStore'; - const supersededBySelector = ({ supersededBy }: ChannelStateData) => ({ supersededBy }); const activeSelector = ({ active }: ChannelStateData) => ({ active }); const editingAuditStateSelector = (state: EditingAuditState) => state; diff --git a/package/src/components/ChannelDetails/components/ChannelEditDetailsFormContent.tsx b/package/src/components/ChannelDetails/components/ChannelEditDetailsFormContent.tsx index e0a0fab75b..9b4c7d358a 100644 --- a/package/src/components/ChannelDetails/components/ChannelEditDetailsFormContent.tsx +++ b/package/src/components/ChannelDetails/components/ChannelEditDetailsFormContent.tsx @@ -1,12 +1,13 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { StyleSheet, View } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; + import { useChannelDetailsContext } from '../../../contexts/channelDetailsContext/channelDetailsContext'; import { useChannelEditDetailsContext } from '../../../contexts/channelEditDetailsContext/ChannelEditDetailsContext'; import { useComponentsContext } from '../../../contexts/componentsContext/ComponentsContext'; import { useTheme } from '../../../contexts/themeContext/ThemeContext'; import { useTranslationContext } from '../../../contexts/translationContext/TranslationContext'; -import { useStateStore } from '../../../hooks/useStateStore'; import type { EditChannelDetailsState } from '../../../state-store/edit-channel-details-store'; import { primitives } from '../../../theme'; import { ChannelAvatar } from '../../ui/Avatar/ChannelAvatar'; diff --git a/package/src/components/ChannelDetails/components/ChannelEditImageSheet.tsx b/package/src/components/ChannelDetails/components/ChannelEditImageSheet.tsx index 7618e5680b..3e26477b84 100644 --- a/package/src/components/ChannelDetails/components/ChannelEditImageSheet.tsx +++ b/package/src/components/ChannelDetails/components/ChannelEditImageSheet.tsx @@ -9,12 +9,13 @@ import { ViewStyle, } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; + import { useBottomSheetContext } from '../../../contexts'; import { useChannelEditDetailsContext } from '../../../contexts/channelEditDetailsContext/ChannelEditDetailsContext'; import { useComponentsContext } from '../../../contexts/componentsContext/ComponentsContext'; import { useTheme } from '../../../contexts/themeContext/ThemeContext'; import { useTranslationContext } from '../../../contexts/translationContext/TranslationContext'; -import { useStateStore } from '../../../hooks/useStateStore'; import type { IconProps } from '../../../icons/utils/base'; import type { EditChannelDetailsState, diff --git a/package/src/components/ChannelDetails/components/ChannelEditName.tsx b/package/src/components/ChannelDetails/components/ChannelEditName.tsx index adc34c11b4..97a971271d 100644 --- a/package/src/components/ChannelDetails/components/ChannelEditName.tsx +++ b/package/src/components/ChannelDetails/components/ChannelEditName.tsx @@ -1,9 +1,10 @@ import React, { useCallback } from 'react'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; + import { useChannelEditDetailsContext } from '../../../contexts/channelEditDetailsContext/ChannelEditDetailsContext'; import { useTheme } from '../../../contexts/themeContext/ThemeContext'; import { useTranslationContext } from '../../../contexts/translationContext/TranslationContext'; -import { useStateStore } from '../../../hooks/useStateStore'; import type { EditChannelDetailsState } from '../../../state-store/edit-channel-details-store'; import { Input } from '../../ui/Input/Input'; diff --git a/package/src/components/ChannelDetails/components/members/ChannelAddMembersFormContent.tsx b/package/src/components/ChannelDetails/components/members/ChannelAddMembersFormContent.tsx index ae2be72daa..dcecb5112c 100644 --- a/package/src/components/ChannelDetails/components/members/ChannelAddMembersFormContent.tsx +++ b/package/src/components/ChannelDetails/components/members/ChannelAddMembersFormContent.tsx @@ -1,6 +1,7 @@ import React, { useCallback, useEffect, useMemo, useRef } from 'react'; import { ActivityIndicator, FlatList, type FlatListProps, StyleSheet, View } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { SearchSourceState, UserResponse } from 'stream-chat'; import { AddMemberSearchResultItem } from './AddMemberSearchResultItem'; @@ -11,7 +12,6 @@ import { useChannelDetailsContext } from '../../../../contexts/channelDetailsCon import { useTheme } from '../../../../contexts/themeContext/ThemeContext'; import { useTranslationContext } from '../../../../contexts/translationContext/TranslationContext'; import { getNotificationErrorOptions } from '../../../../hooks/actions/useChannelActions'; -import { useStateStore } from '../../../../hooks/useStateStore'; import { primitives } from '../../../../theme'; import { useNotificationApi } from '../../../Notifications/hooks/useNotificationApi'; import { EmptySearchResult } from '../../../UIComponents/EmptySearchResult'; diff --git a/package/src/components/ChannelDetails/components/members/ChannelMemberList.tsx b/package/src/components/ChannelDetails/components/members/ChannelMemberList.tsx index 607c77ce58..a3b3723d6b 100644 --- a/package/src/components/ChannelDetails/components/members/ChannelMemberList.tsx +++ b/package/src/components/ChannelDetails/components/members/ChannelMemberList.tsx @@ -1,6 +1,7 @@ import React, { useCallback, useEffect, useState } from 'react'; import { ActivityIndicator, FlatList, type FlatListProps, StyleSheet, View } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { ChannelMemberResponse, ChannelMemberSearchSource, @@ -19,7 +20,6 @@ import { useTheme } from '../../../../contexts/themeContext/ThemeContext'; import { useTranslationContext } from '../../../../contexts/translationContext/TranslationContext'; import { getNotificationErrorOptions } from '../../../../hooks/actions/useChannelActions'; import { useChannelMemberCount } from '../../../../hooks/useChannelMemberCount'; -import { useStateStore } from '../../../../hooks/useStateStore'; import { primitives } from '../../../../theme'; import { useNotificationApi } from '../../../Notifications/hooks/useNotificationApi'; import { NotificationList } from '../../../Notifications/NotificationList'; diff --git a/package/src/components/ChannelDetails/components/navigation-section/FileAttachmentList.tsx b/package/src/components/ChannelDetails/components/navigation-section/FileAttachmentList.tsx index 5f8c608dd8..0b52751b81 100644 --- a/package/src/components/ChannelDetails/components/navigation-section/FileAttachmentList.tsx +++ b/package/src/components/ChannelDetails/components/navigation-section/FileAttachmentList.tsx @@ -7,6 +7,7 @@ import { View, } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { MessageResponse, MessageSearchSource, SearchSourceState } from 'stream-chat'; import { FileAttachmentListLoadingSkeleton } from './FileAttachmentListLoadingSkeleton'; @@ -21,7 +22,6 @@ import { useComponentsContext } from '../../../../contexts/componentsContext/Com import { useTheme } from '../../../../contexts/themeContext/ThemeContext'; import { useTranslationContext } from '../../../../contexts/translationContext/TranslationContext'; import { getNotificationErrorOptions } from '../../../../hooks/actions/useChannelActions'; -import { useStateStore } from '../../../../hooks/useStateStore'; import { primitives } from '../../../../theme'; import { useNotificationApi } from '../../../Notifications/hooks/useNotificationApi'; import { NotificationList } from '../../../Notifications/NotificationList'; diff --git a/package/src/components/ChannelDetails/components/navigation-section/MediaList.tsx b/package/src/components/ChannelDetails/components/navigation-section/MediaList.tsx index 70b944f229..188ac7f4e3 100644 --- a/package/src/components/ChannelDetails/components/navigation-section/MediaList.tsx +++ b/package/src/components/ChannelDetails/components/navigation-section/MediaList.tsx @@ -1,6 +1,7 @@ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { ActivityIndicator, FlatList, type FlatListProps, StyleSheet, View } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { formatMessage, type MessageResponse, @@ -22,7 +23,6 @@ import { useOverlayContext } from '../../../../contexts/overlayContext/OverlayCo import { useTheme } from '../../../../contexts/themeContext/ThemeContext'; import { useTranslationContext } from '../../../../contexts/translationContext/TranslationContext'; import { getNotificationErrorOptions } from '../../../../hooks/actions/useChannelActions'; -import { useStateStore } from '../../../../hooks/useStateStore'; import { useWindowContentWidth } from '../../../../hooks/useWindowContentWidth'; import { isVideoPlayerAvailable } from '../../../../native'; import { primitives } from '../../../../theme'; diff --git a/package/src/components/ChannelDetails/components/navigation-section/PinnedMessageList.tsx b/package/src/components/ChannelDetails/components/navigation-section/PinnedMessageList.tsx index 180fd8b896..11a11e6e78 100644 --- a/package/src/components/ChannelDetails/components/navigation-section/PinnedMessageList.tsx +++ b/package/src/components/ChannelDetails/components/navigation-section/PinnedMessageList.tsx @@ -1,6 +1,7 @@ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { ActivityIndicator, FlatList, type FlatListProps, StyleSheet, View } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { MessageResponse, MessageSearchSource, SearchSourceState } from 'stream-chat'; import { PinnedMessageListLoadingSkeleton } from './PinnedMessageListLoadingSkeleton'; @@ -14,7 +15,6 @@ import { useComponentsContext } from '../../../../contexts/componentsContext/Com import { useTheme } from '../../../../contexts/themeContext/ThemeContext'; import { useTranslationContext } from '../../../../contexts/translationContext/TranslationContext'; import { getNotificationErrorOptions } from '../../../../hooks/actions/useChannelActions'; -import { useStateStore } from '../../../../hooks/useStateStore'; import { primitives } from '../../../../theme'; import { useNotificationApi } from '../../../Notifications/hooks/useNotificationApi'; import { NotificationList } from '../../../Notifications/NotificationList'; diff --git a/package/src/components/ChannelList/hooks/useChannelMembersState.ts b/package/src/components/ChannelList/hooks/useChannelMembersState.ts index 2d9945cd23..6cc0a4bd1f 100644 --- a/package/src/components/ChannelList/hooks/useChannelMembersState.ts +++ b/package/src/components/ChannelList/hooks/useChannelMembersState.ts @@ -1,9 +1,8 @@ import { useMemo } from 'react'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { Channel, ChannelMemberResponse } from 'stream-chat'; -import { useStateStore } from '../../../hooks/useStateStore'; - type MembersState = { members: Record }; /** Picks the member fields a caller reads. Define it at module scope to keep it stable. */ diff --git a/package/src/components/ChannelList/hooks/useChannelOnlineMemberCount.ts b/package/src/components/ChannelList/hooks/useChannelOnlineMemberCount.ts index 6bbbce7fc1..0726f5b744 100644 --- a/package/src/components/ChannelList/hooks/useChannelOnlineMemberCount.ts +++ b/package/src/components/ChannelList/hooks/useChannelOnlineMemberCount.ts @@ -1,7 +1,6 @@ +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { Channel } from 'stream-chat'; -import { useStateStore } from '../../../hooks/useStateStore'; - const selector = (state: { watcherCount: number }) => ({ watcherCount: state.watcherCount }); /** diff --git a/package/src/components/ChannelList/hooks/useMutedUsers.ts b/package/src/components/ChannelList/hooks/useMutedUsers.ts index 20ecfa4ffb..8e28c0695a 100644 --- a/package/src/components/ChannelList/hooks/useMutedUsers.ts +++ b/package/src/components/ChannelList/hooks/useMutedUsers.ts @@ -1,7 +1,7 @@ +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { UserMuteResponse } from 'stream-chat'; import { useChatContext } from '../../../contexts'; -import { useStateStore } from '../../../hooks/useStateStore'; const selector = (state: { mutedUsers: UserMuteResponse[] }) => ({ mutedUsers: state.mutedUsers }); diff --git a/package/src/components/ChannelList/hooks/usePaginatedChannels.ts b/package/src/components/ChannelList/hooks/usePaginatedChannels.ts index dad4468788..d947b9e8ca 100644 --- a/package/src/components/ChannelList/hooks/usePaginatedChannels.ts +++ b/package/src/components/ChannelList/hooks/usePaginatedChannels.ts @@ -1,9 +1,9 @@ import { useEffect, useRef, useState } from 'react'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { ChannelPaginator, ChannelPaginatorState } from 'stream-chat'; import { useChatContext } from '../../../contexts/chatContext/ChatContext'; -import { useStateStore } from '../../../hooks'; import { useStableCallback } from '../../../hooks/useStableCallback'; import { useClientUserId } from '../../Chat/hooks/useClientUserId'; diff --git a/package/src/components/ChannelPreview/ChannelMessagePreviewDeliveryStatus.tsx b/package/src/components/ChannelPreview/ChannelMessagePreviewDeliveryStatus.tsx index 430d6a2c5f..159636fa09 100644 --- a/package/src/components/ChannelPreview/ChannelMessagePreviewDeliveryStatus.tsx +++ b/package/src/components/ChannelPreview/ChannelMessagePreviewDeliveryStatus.tsx @@ -1,6 +1,7 @@ import React, { useMemo } from 'react'; import { StyleSheet, Text, View } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { ChannelConfig, LocalMessage, MessageResponse } from 'stream-chat'; import { ChannelPreviewProps } from './ChannelPreview'; @@ -11,7 +12,6 @@ import { useComponentsContext } from '../../contexts/componentsContext/Component import { useTheme } from '../../contexts/themeContext/ThemeContext'; import { useTranslationContext } from '../../contexts/translationContext/TranslationContext'; import { MessageDeliveryStatus, useMessageDeliveryStatus } from '../../hooks'; -import { useStateStore } from '../../hooks/useStateStore'; import { primitives } from '../../theme'; import { MessageStatusTypes } from '../../utils/utils'; import { CompositeAccessibilityProbe } from '../Accessibility/CompositeAccessibilityProbe'; diff --git a/package/src/components/ChannelPreview/hooks/useChannelPreviewData.ts b/package/src/components/ChannelPreview/hooks/useChannelPreviewData.ts index 5322479303..df5c0283a1 100644 --- a/package/src/components/ChannelPreview/hooks/useChannelPreviewData.ts +++ b/package/src/components/ChannelPreview/hooks/useChannelPreviewData.ts @@ -1,5 +1,6 @@ import { useCallback, useEffect } from 'react'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { Channel, LocalMessage, @@ -11,8 +12,6 @@ import type { StreamChat, } from 'stream-chat'; -import { useStateStore } from '../../../hooks'; - export type LastMessageType = LocalMessage | MessageResponse; // The latest message comes from the paginator's `aggregateState`, which stays current when a new diff --git a/package/src/components/ChannelPreview/hooks/useChannelPreviewDraftMessage.ts b/package/src/components/ChannelPreview/hooks/useChannelPreviewDraftMessage.ts index 3f12319a25..0dd9de529d 100644 --- a/package/src/components/ChannelPreview/hooks/useChannelPreviewDraftMessage.ts +++ b/package/src/components/ChannelPreview/hooks/useChannelPreviewDraftMessage.ts @@ -1,9 +1,8 @@ import { useMemo } from 'react'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { AttachmentManagerState, Channel, DraftMessage, TextComposerState } from 'stream-chat'; -import { useStateStore } from '../../../hooks/useStateStore'; - const textComposerStateSelector = (state: TextComposerState) => ({ text: state.text, }); diff --git a/package/src/components/ChannelPreview/hooks/useChannelPreviewPollLabel.ts b/package/src/components/ChannelPreview/hooks/useChannelPreviewPollLabel.ts index a52a64d7a6..de2e96c339 100644 --- a/package/src/components/ChannelPreview/hooks/useChannelPreviewPollLabel.ts +++ b/package/src/components/ChannelPreview/hooks/useChannelPreviewPollLabel.ts @@ -1,10 +1,10 @@ import { useMemo } from 'react'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { PollState } from 'stream-chat'; import { useChatContext } from '../../../contexts/chatContext/ChatContext'; import { useTranslationContext } from '../../../contexts/translationContext/TranslationContext'; -import { useStateStore } from '../../../hooks/useStateStore'; import { getTranslatedText } from '../../../utils/i18n/getTranslatedText'; export type UseChannelPreviewPollLabelProps = { diff --git a/package/src/components/ChannelPreview/hooks/useIsChannelMuted.ts b/package/src/components/ChannelPreview/hooks/useIsChannelMuted.ts index 1a584e9413..7eb9792c5a 100644 --- a/package/src/components/ChannelPreview/hooks/useIsChannelMuted.ts +++ b/package/src/components/ChannelPreview/hooks/useIsChannelMuted.ts @@ -1,7 +1,6 @@ +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { Channel, ChannelMuteStatus } from 'stream-chat'; -import { useStateStore } from '../../../hooks/useStateStore'; - const defaultMuteStatus = { createdAt: null, expiresAt: null, diff --git a/package/src/components/Chat/Chat.tsx b/package/src/components/Chat/Chat.tsx index 547ea99cbc..7b3ce6acef 100644 --- a/package/src/components/Chat/Chat.tsx +++ b/package/src/components/Chat/Chat.tsx @@ -1,6 +1,7 @@ import React, { PropsWithChildren, useEffect, useMemo, useState } from 'react'; import { Platform } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { OfflineDBState } from 'stream-chat'; import { useAppSettingsGetter } from './hooks/useAppSettingsGetter'; @@ -17,7 +18,6 @@ import { DEFAULT_USER_LANGUAGE, TranslationProvider, } from '../../contexts/translationContext/TranslationContext'; -import { useStateStore } from '../../hooks'; import { useStreami18n } from '../../hooks/useStreami18n'; import init from '../../init'; diff --git a/package/src/components/Chat/hooks/useNetworkConnectionState.ts b/package/src/components/Chat/hooks/useNetworkConnectionState.ts index b59c0f8f73..243e5c5b69 100644 --- a/package/src/components/Chat/hooks/useNetworkConnectionState.ts +++ b/package/src/components/Chat/hooks/useNetworkConnectionState.ts @@ -1,7 +1,7 @@ +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { NetworkConnectionState } from 'stream-chat'; import { useChatContext } from '../../../contexts/chatContext/ChatContext'; -import { useStateStore } from '../../../hooks/useStateStore'; const identity = (state: NetworkConnectionState) => state; diff --git a/package/src/components/Chat/hooks/useWSConnectionState.ts b/package/src/components/Chat/hooks/useWSConnectionState.ts index bdf14222e4..607e8ac968 100644 --- a/package/src/components/Chat/hooks/useWSConnectionState.ts +++ b/package/src/components/Chat/hooks/useWSConnectionState.ts @@ -1,9 +1,9 @@ import { useEffect, useState } from 'react'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { NetworkConnectionState, WSConnectionConfig, WSConnectionState } from 'stream-chat'; import { useChatContext } from '../../../contexts/chatContext/ChatContext'; -import { useStateStore } from '../../../hooks/useStateStore'; const identity = (state: WSConnectionState) => state; const healthSelector = (state: WSConnectionState) => ({ diff --git a/package/src/components/ImageGallery/ImageGallery.tsx b/package/src/components/ImageGallery/ImageGallery.tsx index 6d5ac22802..2d60f45257 100644 --- a/package/src/components/ImageGallery/ImageGallery.tsx +++ b/package/src/components/ImageGallery/ImageGallery.tsx @@ -12,6 +12,8 @@ import Animated, { withTiming, } from 'react-native-reanimated'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; + import { AnimatedGalleryImage } from './components/AnimatedGalleryImage'; import { AnimatedGalleryVideo } from './components/AnimatedGalleryVideo'; import { ImageGalleryA11yProbe } from './components/ImageGalleryA11yProbe'; @@ -35,7 +37,6 @@ import { useOverlayContext, } from '../../contexts/overlayContext/OverlayContext'; import { useTheme } from '../../contexts/themeContext/ThemeContext'; -import { useStateStore } from '../../hooks'; import { useViewport } from '../../hooks/useViewport'; import { IconProps } from '../../icons/utils/base'; import { ImageGalleryState } from '../../state-store/image-gallery-state-store'; diff --git a/package/src/components/ImageGallery/components/AnimatedGalleryImage.tsx b/package/src/components/ImageGallery/components/AnimatedGalleryImage.tsx index 50c323235f..24c34bc50e 100644 --- a/package/src/components/ImageGallery/components/AnimatedGalleryImage.tsx +++ b/package/src/components/ImageGallery/components/AnimatedGalleryImage.tsx @@ -3,9 +3,10 @@ import { StyleSheet, View } from 'react-native'; import type { ImageStyle, StyleProp } from 'react-native'; import Animated, { SharedValue } from 'react-native-reanimated'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; + import { useChatConfigContext } from '../../../contexts/chatConfigContext/ChatConfigContext'; import { useImageGalleryContext } from '../../../contexts/imageGalleryContext/ImageGalleryContext'; -import { useStateStore } from '../../../hooks'; import { useIsSvg } from '../../../hooks/useIsSvg'; import { ImageGalleryAsset, diff --git a/package/src/components/ImageGallery/components/AnimatedGalleryVideo.tsx b/package/src/components/ImageGallery/components/AnimatedGalleryVideo.tsx index 48c9eea580..f68b23db75 100644 --- a/package/src/components/ImageGallery/components/AnimatedGalleryVideo.tsx +++ b/package/src/components/ImageGallery/components/AnimatedGalleryVideo.tsx @@ -3,9 +3,11 @@ import { StyleSheet, View, ViewStyle } from 'react-native'; import type { StyleProp } from 'react-native'; import Animated, { SharedValue } from 'react-native-reanimated'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; + import { useChatConfigContext } from '../../../contexts/chatConfigContext/ChatConfigContext'; import { useImageGalleryContext } from '../../../contexts/imageGalleryContext/ImageGalleryContext'; -import { useStableCallback, useStateStore } from '../../../hooks'; +import { useStableCallback } from '../../../hooks'; import { isVideoPlayerAvailable, diff --git a/package/src/components/ImageGallery/components/ImageGalleryA11yProbe.tsx b/package/src/components/ImageGallery/components/ImageGalleryA11yProbe.tsx index 63d7bb78e1..e8bdf94387 100644 --- a/package/src/components/ImageGallery/components/ImageGalleryA11yProbe.tsx +++ b/package/src/components/ImageGallery/components/ImageGalleryA11yProbe.tsx @@ -2,9 +2,10 @@ import React, { useCallback, useMemo } from 'react'; import { StyleSheet, ViewStyle } from 'react-native'; import Animated, { AnimatedStyle } from 'react-native-reanimated'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; + import { useA11yLabel } from '../../../a11y/hooks/useA11yLabel'; import { useImageGalleryContext } from '../../../contexts/imageGalleryContext/ImageGalleryContext'; -import { useStateStore } from '../../../hooks'; import { ImageGalleryState } from '../../../state-store/image-gallery-state-store'; const a11ySelector = (state: ImageGalleryState) => ({ diff --git a/package/src/components/ImageGallery/components/ImageGalleryFooter.tsx b/package/src/components/ImageGallery/components/ImageGalleryFooter.tsx index 923f54f845..362c9a6c9a 100644 --- a/package/src/components/ImageGallery/components/ImageGalleryFooter.tsx +++ b/package/src/components/ImageGallery/components/ImageGalleryFooter.tsx @@ -2,13 +2,14 @@ import React, { useMemo, useRef, useState } from 'react'; import { ActivityIndicator, StyleSheet, Text, View, ViewStyle } from 'react-native'; import Animated, { Extrapolation, interpolate, useAnimatedStyle } from 'react-native-reanimated'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; + import type { ImageGalleryFooterProps, ImageGalleryVideoControlProps } from './types'; import { useComponentsContext } from '../../../contexts/componentsContext/ComponentsContext'; import { useImageGalleryContext } from '../../../contexts/imageGalleryContext/ImageGalleryContextBase'; import { useTheme } from '../../../contexts/themeContext/ThemeContext'; import { useTranslationContext } from '../../../contexts/translationContext/TranslationContext'; -import { useStateStore } from '../../../hooks/useStateStore'; import { isFileSystemAvailable, isShareImageAvailable, NativeHandlers } from '../../../native'; import { ImageGalleryState } from '../../../state-store/image-gallery-state-store'; diff --git a/package/src/components/ImageGallery/components/ImageGalleryHeader.tsx b/package/src/components/ImageGallery/components/ImageGalleryHeader.tsx index ac183cd8e7..b5faabed6d 100644 --- a/package/src/components/ImageGallery/components/ImageGalleryHeader.tsx +++ b/package/src/components/ImageGallery/components/ImageGalleryHeader.tsx @@ -5,6 +5,8 @@ import { StyleSheet, Text, View, ViewStyle } from 'react-native'; import Animated, { Extrapolation, interpolate, useAnimatedStyle } from 'react-native-reanimated'; import { SafeAreaInsetsContext } from 'react-native-safe-area-context'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; + import type { ImageGalleryHeaderProps } from './types'; import { useComponentsContext } from '../../../contexts/componentsContext/ComponentsContext'; @@ -12,7 +14,6 @@ import { useImageGalleryContext } from '../../../contexts/imageGalleryContext/Im import { useOverlayContext } from '../../../contexts/overlayContext/OverlayContext'; import { useTheme } from '../../../contexts/themeContext/ThemeContext'; import { useTranslationContext } from '../../../contexts/translationContext/TranslationContext'; -import { useStateStore } from '../../../hooks/useStateStore'; import { getDateString } from '../../../i18n/utils'; import { ImageGalleryState } from '../../../state-store/image-gallery-state-store'; diff --git a/package/src/components/ImageGallery/components/ImageGalleryVideoControl.tsx b/package/src/components/ImageGallery/components/ImageGalleryVideoControl.tsx index 22a7fc6add..8e97f2da0e 100644 --- a/package/src/components/ImageGallery/components/ImageGalleryVideoControl.tsx +++ b/package/src/components/ImageGallery/components/ImageGalleryVideoControl.tsx @@ -1,13 +1,14 @@ import React, { useCallback, useMemo, useRef } from 'react'; import { StyleSheet, Text, View } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; + import type { ImageGalleryVideoControlProps } from './types'; import { useComponentsContext } from '../../../contexts/componentsContext/ComponentsContext'; import { useTheme } from '../../../contexts/themeContext/ThemeContext'; import { useStableCallback } from '../../../hooks/useStableCallback'; -import { useStateStore } from '../../../hooks/useStateStore'; import { IconProps } from '../../../icons/utils/base'; import { VideoPlayerState } from '../../../state-store/video-player'; import { primitives } from '../../../theme'; diff --git a/package/src/components/ImageGallery/components/ImageGrid.tsx b/package/src/components/ImageGallery/components/ImageGrid.tsx index ee34e6828d..a6956fbc04 100644 --- a/package/src/components/ImageGallery/components/ImageGrid.tsx +++ b/package/src/components/ImageGallery/components/ImageGrid.tsx @@ -1,11 +1,12 @@ import React, { useMemo } from 'react'; import { Image, Pressable, StyleSheet, View } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; + import type { ImageGalleryGridProps } from './types'; import { useImageGalleryContext } from '../../../contexts/imageGalleryContext/ImageGalleryContextBase'; import { useTheme } from '../../../contexts/themeContext/ThemeContext'; -import { useStateStore } from '../../../hooks/useStateStore'; import { useWindowContentWidth } from '../../../hooks/useWindowContentWidth'; import type { ImageGalleryAsset, diff --git a/package/src/components/Message/MessageItemView/Headers/MessageReminderHeader.tsx b/package/src/components/Message/MessageItemView/Headers/MessageReminderHeader.tsx index 39f9da695a..525a1fa27d 100644 --- a/package/src/components/Message/MessageItemView/Headers/MessageReminderHeader.tsx +++ b/package/src/components/Message/MessageItemView/Headers/MessageReminderHeader.tsx @@ -2,6 +2,7 @@ import React, { useMemo } from 'react'; import { StyleSheet, Text, View } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { ReminderState } from 'stream-chat'; import { useComponentsContext } from '../../../../contexts/componentsContext/ComponentsContext'; @@ -9,7 +10,6 @@ import { useMessageContext } from '../../../../contexts/messageContext/MessageCo import { useTheme } from '../../../../contexts/themeContext/ThemeContext'; import { useTranslationContext } from '../../../../contexts/translationContext/TranslationContext'; import { useMessageReminder } from '../../../../hooks/useMessageReminder'; -import { useStateStore } from '../../../../hooks/useStateStore'; import { primitives } from '../../../../theme'; import { useShouldUseOverlayStyles } from '../../hooks/useShouldUseOverlayStyles'; diff --git a/package/src/components/Message/MessageItemView/MessageFooter.tsx b/package/src/components/Message/MessageItemView/MessageFooter.tsx index d49dcb2450..bdcac58e4e 100644 --- a/package/src/components/Message/MessageItemView/MessageFooter.tsx +++ b/package/src/components/Message/MessageItemView/MessageFooter.tsx @@ -1,6 +1,7 @@ import React, { useMemo } from 'react'; import { StyleSheet, Text, View } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { Attachment, LocalMessage } from 'stream-chat'; import { useChannelContext } from '../../../contexts/channelContext/ChannelContext'; @@ -15,7 +16,6 @@ import { import { useTheme } from '../../../contexts/themeContext/ThemeContext'; import { useTranslationContext } from '../../../contexts/translationContext/TranslationContext'; -import { useStateStore } from '../../../hooks/useStateStore'; import { primitives } from '../../../theme'; import { getPlayedCount, isEditedMessage, MessageStatusTypes } from '../../../utils/utils'; import { useShouldUseOverlayStyles } from '../hooks/useShouldUseOverlayStyles'; diff --git a/package/src/components/Message/MessageItemView/MessageHeader.tsx b/package/src/components/Message/MessageItemView/MessageHeader.tsx index 4b9478831d..fc499fb590 100644 --- a/package/src/components/Message/MessageItemView/MessageHeader.tsx +++ b/package/src/components/Message/MessageItemView/MessageHeader.tsx @@ -2,6 +2,7 @@ import React, { useMemo } from 'react'; import { View, ViewStyle } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { Reminder, ReminderState } from 'stream-chat'; import { useComponentsContext } from '../../../contexts/componentsContext/ComponentsContext'; @@ -10,7 +11,6 @@ import { useMessageContext, } from '../../../contexts/messageContext/MessageContext'; import { useMessageReminder } from '../../../hooks/useMessageReminder'; -import { useStateStore } from '../../../hooks/useStateStore'; type MessageHeaderPropsWithContext = Pick & { reminder?: Reminder; diff --git a/package/src/components/Message/MessageItemView/MessageStatus.tsx b/package/src/components/Message/MessageItemView/MessageStatus.tsx index 617fe02bed..6cbae9a92c 100644 --- a/package/src/components/Message/MessageItemView/MessageStatus.tsx +++ b/package/src/components/Message/MessageItemView/MessageStatus.tsx @@ -1,6 +1,7 @@ import React, { useMemo } from 'react'; import { StyleSheet, View } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { ChannelConfig } from 'stream-chat'; import { useA11yLabel } from '../../../a11y/hooks/useA11yLabel'; @@ -11,7 +12,6 @@ import { useMessageContext, } from '../../../contexts/messageContext/MessageContext'; import { useTheme } from '../../../contexts/themeContext/ThemeContext'; -import { useStateStore } from '../../../hooks/useStateStore'; import { primitives } from '../../../theme'; import { MessageStatusTypes } from '../../../utils/utils'; import { HiddenA11yText } from '../../Accessibility/HiddenA11yText'; diff --git a/package/src/components/Message/MessageItemView/MessageWrapper.tsx b/package/src/components/Message/MessageItemView/MessageWrapper.tsx index f5585d280b..48a45757a3 100644 --- a/package/src/components/Message/MessageItemView/MessageWrapper.tsx +++ b/package/src/components/Message/MessageItemView/MessageWrapper.tsx @@ -2,6 +2,7 @@ import React, { useCallback, useMemo } from 'react'; import { StyleSheet, View } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { LocalMessage, UnreadSnapshotState } from 'stream-chat'; import { useMessageDateSeparator } from '../../../components/MessageList/hooks/useMessageDateSeparator'; @@ -15,7 +16,6 @@ import { ThemeProvider, useTheme } from '../../../contexts/themeContext/ThemeCon import { useIsTargetedMessage } from '../../../hooks/useIsTargetedMessage'; import { useMessagePaginator } from '../../../hooks/useMessagePaginator'; -import { useStateStore } from '../../../hooks/useStateStore'; import { primitives } from '../../../theme'; export type MessageWrapperProps = { diff --git a/package/src/components/Message/hooks/useIsMessageDeliveredToOthers.ts b/package/src/components/Message/hooks/useIsMessageDeliveredToOthers.ts index a6f8a6f40d..32dd8a22de 100644 --- a/package/src/components/Message/hooks/useIsMessageDeliveredToOthers.ts +++ b/package/src/components/Message/hooks/useIsMessageDeliveredToOthers.ts @@ -1,9 +1,9 @@ import { useCallback } from 'react'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { LocalMessage, MessageReceiptsSnapshot } from 'stream-chat'; import { useChannelContext } from '../../../contexts/channelContext/ChannelContext'; -import { useStateStore } from '../../../hooks/useStateStore'; /** * Whether the message has been delivered to at least one other member, read from the channel's diff --git a/package/src/components/Message/hooks/useIsMessageReadByOthers.ts b/package/src/components/Message/hooks/useIsMessageReadByOthers.ts index b63e8b56c9..646db36cd7 100644 --- a/package/src/components/Message/hooks/useIsMessageReadByOthers.ts +++ b/package/src/components/Message/hooks/useIsMessageReadByOthers.ts @@ -1,9 +1,9 @@ import { useCallback } from 'react'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { LocalMessage, MessageReceiptsSnapshot } from 'stream-chat'; import { useChannelContext } from '../../../contexts/channelContext/ChannelContext'; -import { useStateStore } from '../../../hooks/useStateStore'; /** * Whether at least one other member has read the message, read from the channel's diff --git a/package/src/components/Message/hooks/useMessageDeliveryData.ts b/package/src/components/Message/hooks/useMessageDeliveryData.ts index 882599fd27..3ec0c27d88 100644 --- a/package/src/components/Message/hooks/useMessageDeliveryData.ts +++ b/package/src/components/Message/hooks/useMessageDeliveryData.ts @@ -1,9 +1,9 @@ import { useCallback } from 'react'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { LocalMessage, UserResponse } from 'stream-chat'; import { useChannelContext } from '../../../contexts/channelContext/ChannelContext'; -import { useStateStore } from '../../../hooks/useStateStore'; const EMPTY_DELIVERED: UserResponse[] = []; diff --git a/package/src/components/Message/hooks/useMessageReadData.ts b/package/src/components/Message/hooks/useMessageReadData.ts index 311a99a1b2..2d3c075e79 100644 --- a/package/src/components/Message/hooks/useMessageReadData.ts +++ b/package/src/components/Message/hooks/useMessageReadData.ts @@ -1,9 +1,9 @@ import { useCallback } from 'react'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { LocalMessage, UserResponse } from 'stream-chat'; import { useChannelContext } from '../../../contexts/channelContext/ChannelContext'; -import { useStateStore } from '../../../hooks/useStateStore'; const EMPTY_READERS: UserResponse[] = []; diff --git a/package/src/components/Message/hooks/useUserMuteActive.ts b/package/src/components/Message/hooks/useUserMuteActive.ts index 8cd2f7f240..4876e743fb 100644 --- a/package/src/components/Message/hooks/useUserMuteActive.ts +++ b/package/src/components/Message/hooks/useUserMuteActive.ts @@ -1,9 +1,9 @@ import { useCallback } from 'react'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { UserMuteResponse, UserResponse } from 'stream-chat'; import { useChatContext } from '../../../contexts'; -import { useStateStore } from '../../../hooks/useStateStore'; /** * Whether `currentUserId` has muted `userId`, according to the given mute list. diff --git a/package/src/components/MessageInput/CommandChip.tsx b/package/src/components/MessageInput/CommandChip.tsx index 332e5fff33..5b064f3f0c 100644 --- a/package/src/components/MessageInput/CommandChip.tsx +++ b/package/src/components/MessageInput/CommandChip.tsx @@ -3,10 +3,11 @@ import { StyleSheet } from 'react-native'; import Animated, { LinearTransition, ZoomIn, ZoomOut } from 'react-native-reanimated'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; + import { textComposerStateSelector } from './utils/messageComposerSelectors'; import { useMessageComposer } from '../../contexts/messageInputContext/hooks/useMessageComposer'; -import { useStateStore } from '../../hooks/useStateStore'; import { primitives } from '../../theme'; import { GiphyChip } from '../ui/GiphyChip'; diff --git a/package/src/components/MessageInput/MessageComposer.tsx b/package/src/components/MessageInput/MessageComposer.tsx index 2bb0ad7eac..29a646410a 100644 --- a/package/src/components/MessageInput/MessageComposer.tsx +++ b/package/src/components/MessageInput/MessageComposer.tsx @@ -10,6 +10,7 @@ import Animated, { import { useSafeAreaInsets } from 'react-native-safe-area-context'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { type ChannelDataState, type ChannelWatchState, @@ -47,7 +48,6 @@ import { import { useAttachmentPickerState } from '../../hooks/useAttachmentPickerState'; import { useKeyboardVisibility } from '../../hooks/useKeyboardVisibility'; -import { useStateStore } from '../../hooks/useStateStore'; import { AudioRecorderManagerState } from '../../state-store/audio-recorder-manager'; import { MessageInputHeightState } from '../../state-store/message-input-height-store'; import { primitives } from '../../theme'; diff --git a/package/src/components/MessageInput/MessageComposerLeadingView.tsx b/package/src/components/MessageInput/MessageComposerLeadingView.tsx index 8b2a89c899..f12e6c5938 100644 --- a/package/src/components/MessageInput/MessageComposerLeadingView.tsx +++ b/package/src/components/MessageInput/MessageComposerLeadingView.tsx @@ -3,12 +3,13 @@ import { StyleSheet } from 'react-native'; import Animated from 'react-native-reanimated'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; + import { InputButtons } from './components/InputButtons'; import { idleRecordingStateSelector } from './utils/audioRecorderSelectors'; import { useMessageInputContext } from '../../contexts/messageInputContext/MessageInputContext'; import { useTheme } from '../../contexts/themeContext/ThemeContext'; -import { useStateStore } from '../../hooks/useStateStore'; import { transitions } from '../../utils/animations/transitions'; export const MessageComposerLeadingView = () => { diff --git a/package/src/components/MessageInput/MessageInputHeaderView.tsx b/package/src/components/MessageInput/MessageInputHeaderView.tsx index c24d1c6fad..208f4942ec 100644 --- a/package/src/components/MessageInput/MessageInputHeaderView.tsx +++ b/package/src/components/MessageInput/MessageInputHeaderView.tsx @@ -3,6 +3,8 @@ import { StyleSheet } from 'react-native'; import Animated from 'react-native-reanimated'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; + import { LinkPreviewList } from './components/LinkPreviewList'; import { useHasLinkPreviews } from './hooks/useLinkPreviews'; @@ -15,7 +17,6 @@ import { useHasAttachments } from '../../contexts/messageInputContext/hooks/useH import { useMessageComposer } from '../../contexts/messageInputContext/hooks/useMessageComposer'; import { useMessageInputContext } from '../../contexts/messageInputContext/MessageInputContext'; import { useTheme } from '../../contexts/themeContext/ThemeContext'; -import { useStateStore } from '../../hooks/useStateStore'; import { primitives } from '../../theme'; import { transitions } from '../../utils/animations/transitions'; diff --git a/package/src/components/MessageInput/MessageInputTrailingView.tsx b/package/src/components/MessageInput/MessageInputTrailingView.tsx index a88b9393e4..e4bc780187 100644 --- a/package/src/components/MessageInput/MessageInputTrailingView.tsx +++ b/package/src/components/MessageInput/MessageInputTrailingView.tsx @@ -3,13 +3,14 @@ import { StyleSheet } from 'react-native'; import Animated from 'react-native-reanimated'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; + import { OutputButtons } from './components/OutputButtons'; import { audioRecorderSelector } from './utils/audioRecorderSelectors'; import { useMessageInputContext } from '../../contexts/messageInputContext/MessageInputContext'; import { useTheme } from '../../contexts/themeContext/ThemeContext'; -import { useStateStore } from '../../hooks/useStateStore'; import { primitives } from '../../theme'; import { transitions } from '../../utils/animations/transitions'; diff --git a/package/src/components/MessageInput/ShowThreadMessageInChannelButton.tsx b/package/src/components/MessageInput/ShowThreadMessageInChannelButton.tsx index ace836f58a..6344bfd3ba 100644 --- a/package/src/components/MessageInput/ShowThreadMessageInChannelButton.tsx +++ b/package/src/components/MessageInput/ShowThreadMessageInChannelButton.tsx @@ -3,6 +3,7 @@ import { Pressable, StyleSheet, Text, View } from 'react-native'; import Animated, { LinearTransition } from 'react-native-reanimated'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { MessageComposerState } from 'stream-chat'; import { useComponentsContext } from '../../contexts/componentsContext/ComponentsContext'; @@ -13,7 +14,6 @@ import { TranslationContextValue, useTranslationContext, } from '../../contexts/translationContext/TranslationContext'; -import { useStateStore } from '../../hooks/useStateStore'; import { primitives } from '../../theme'; const stateSelector = (state: MessageComposerState) => ({ diff --git a/package/src/components/MessageInput/components/AudioRecorder/AudioRecorder.tsx b/package/src/components/MessageInput/components/AudioRecorder/AudioRecorder.tsx index 98c359847c..f55000b163 100644 --- a/package/src/components/MessageInput/components/AudioRecorder/AudioRecorder.tsx +++ b/package/src/components/MessageInput/components/AudioRecorder/AudioRecorder.tsx @@ -3,6 +3,7 @@ import { StyleProp, StyleSheet, Text, View, ViewStyle } from 'react-native'; import Animated, { type AnimatedStyle } from 'react-native-reanimated'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import dayjs from 'dayjs'; import { Button } from '../../../../components/ui'; @@ -13,7 +14,6 @@ import { } from '../../../../contexts/messageInputContext/MessageInputContext'; import { useTheme } from '../../../../contexts/themeContext/ThemeContext'; import { useTranslationContext } from '../../../../contexts/translationContext/TranslationContext'; -import { useStateStore } from '../../../../hooks/useStateStore'; import { IconProps } from '../../../../icons/utils/base'; import { NativeHandlers } from '../../../../native'; diff --git a/package/src/components/MessageInput/components/AudioRecorder/AudioRecordingButton.tsx b/package/src/components/MessageInput/components/AudioRecorder/AudioRecordingButton.tsx index e4fda1fe0f..205d0c264e 100644 --- a/package/src/components/MessageInput/components/AudioRecorder/AudioRecordingButton.tsx +++ b/package/src/components/MessageInput/components/AudioRecorder/AudioRecordingButton.tsx @@ -10,6 +10,8 @@ import Animated, { withSpring, } from 'react-native-reanimated'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; + import { useA11yLabel } from '../../../../a11y/hooks/useA11yLabel'; import { useActiveAudioPlayer } from '../../../../contexts/audioPlayerContext/AudioPlayerContext'; import { useComponentsContext } from '../../../../contexts/componentsContext/ComponentsContext'; @@ -20,7 +22,6 @@ import { import { useTheme } from '../../../../contexts/themeContext/ThemeContext'; import { useTranslationContext } from '../../../../contexts/translationContext/TranslationContext'; import { useStableCallback } from '../../../../hooks'; -import { useStateStore } from '../../../../hooks/useStateStore'; import { NativeHandlers } from '../../../../native'; import { AudioRecorderManagerState } from '../../../../state-store/audio-recorder-manager'; import { primitives } from '../../../../theme'; diff --git a/package/src/components/MessageInput/components/AudioRecorder/AudioRecordingInProgress.tsx b/package/src/components/MessageInput/components/AudioRecorder/AudioRecordingInProgress.tsx index 961a312aa9..2151df9075 100644 --- a/package/src/components/MessageInput/components/AudioRecorder/AudioRecordingInProgress.tsx +++ b/package/src/components/MessageInput/components/AudioRecorder/AudioRecordingInProgress.tsx @@ -1,6 +1,7 @@ import React, { useMemo } from 'react'; import { StyleSheet, Text, View } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import dayjs from 'dayjs'; import { useComponentsContext } from '../../../../contexts/componentsContext/ComponentsContext'; @@ -9,7 +10,6 @@ import { useMessageInputContext, } from '../../../../contexts/messageInputContext/MessageInputContext'; import { useTheme } from '../../../../contexts/themeContext/ThemeContext'; -import { useStateStore } from '../../../../hooks/useStateStore'; import { AudioRecorderManagerState } from '../../../../state-store/audio-recorder-manager'; import { primitives } from '../../../../theme'; diff --git a/package/src/components/MessageInput/components/AudioRecorder/AudioRecordingPreview.tsx b/package/src/components/MessageInput/components/AudioRecorder/AudioRecordingPreview.tsx index 137ec3c41a..37c39c917c 100644 --- a/package/src/components/MessageInput/components/AudioRecorder/AudioRecordingPreview.tsx +++ b/package/src/components/MessageInput/components/AudioRecorder/AudioRecordingPreview.tsx @@ -1,6 +1,7 @@ import React, { useEffect, useMemo } from 'react'; import { Pressable, StyleSheet, View } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import dayjs from 'dayjs'; import { useComponentsContext } from '../../../../contexts/componentsContext/ComponentsContext'; @@ -8,7 +9,6 @@ import { useMessageInputContext } from '../../../../contexts/messageInputContext import { useTheme } from '../../../../contexts/themeContext/ThemeContext'; import { useStableCallback } from '../../../../hooks'; import { useAudioPlayer } from '../../../../hooks/useAudioPlayer'; -import { useStateStore } from '../../../../hooks/useStateStore'; import { AudioPlayerState } from '../../../../state-store/audio-player'; import { AudioRecorderManagerState } from '../../../../state-store/audio-recorder-manager'; diff --git a/package/src/components/MessageInput/components/OutputButtons/index.tsx b/package/src/components/MessageInput/components/OutputButtons/index.tsx index 18ca6b4bbe..240d88f11b 100644 --- a/package/src/components/MessageInput/components/OutputButtons/index.tsx +++ b/package/src/components/MessageInput/components/OutputButtons/index.tsx @@ -2,6 +2,7 @@ import React, { useCallback } from 'react'; import Animated from 'react-native-reanimated'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { TextComposerState } from 'stream-chat'; import { EditButton } from './EditButton'; @@ -19,7 +20,6 @@ import { MessageInputContextValue, useMessageInputContext, } from '../../../../contexts/messageInputContext/MessageInputContext'; -import { useStateStore } from '../../../../hooks/useStateStore'; import { transitions } from '../../../../utils/animations/transitions'; import { AIStates, useAIState } from '../../../AITypingIndicatorView'; import { useSettledWSConnectionHealth } from '../../../Chat/hooks/useWSConnectionState'; diff --git a/package/src/components/MessageInput/hooks/useCooldownRemaining.tsx b/package/src/components/MessageInput/hooks/useCooldownRemaining.tsx index a4f6e04928..8cb235b0b7 100644 --- a/package/src/components/MessageInput/hooks/useCooldownRemaining.tsx +++ b/package/src/components/MessageInput/hooks/useCooldownRemaining.tsx @@ -1,7 +1,7 @@ +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { type CooldownTimerState } from 'stream-chat'; import { useChannelContext } from '../../../contexts/channelContext/ChannelContext'; -import { useStateStore } from '../../../hooks/useStateStore'; const cooldownTimerStateSelector = (state: CooldownTimerState) => ({ cooldownRemaining: state.cooldownRemaining, diff --git a/package/src/components/MessageInput/hooks/useIsCooldownActive.ts b/package/src/components/MessageInput/hooks/useIsCooldownActive.ts index 6c6494b8fc..76736e4d38 100644 --- a/package/src/components/MessageInput/hooks/useIsCooldownActive.ts +++ b/package/src/components/MessageInput/hooks/useIsCooldownActive.ts @@ -1,7 +1,7 @@ +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { CooldownTimerState } from 'stream-chat'; import { useChannelContext } from '../../../contexts/channelContext/ChannelContext'; -import { useStateStore } from '../../../hooks/useStateStore'; const cooldownTimerStateSelector = (state: CooldownTimerState) => ({ isCooldownActive: !!state.cooldownRemaining, diff --git a/package/src/components/MessageInput/hooks/useLinkPreviews.ts b/package/src/components/MessageInput/hooks/useLinkPreviews.ts index 4f4e7beb83..2c9b95392c 100644 --- a/package/src/components/MessageInput/hooks/useLinkPreviews.ts +++ b/package/src/components/MessageInput/hooks/useLinkPreviews.ts @@ -1,7 +1,7 @@ +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { LinkPreviewsManager, LinkPreviewsManagerState } from 'stream-chat'; import { useMessageComposer } from '../../../contexts'; -import { useStateStore } from '../../../hooks'; const linkPreviewsManagerStateSelector = (state: LinkPreviewsManagerState) => ({ linkPreviews: Array.from(state.previews.values()).filter((preview) => diff --git a/package/src/components/MessageList/MessageFlashList.tsx b/package/src/components/MessageList/MessageFlashList.tsx index d8587a0256..89c0a4235b 100644 --- a/package/src/components/MessageList/MessageFlashList.tsx +++ b/package/src/components/MessageList/MessageFlashList.tsx @@ -4,6 +4,7 @@ import { LayoutChangeEvent, ScrollViewProps, StyleSheet, View, useColorScheme } import Animated from 'react-native-reanimated'; import type { FlashListProps, FlashListRef } from '@shopify/flash-list'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { LocalMessage, Thread } from 'stream-chat'; import { getAttachmentPreviewUrl } from 'stream-chat'; @@ -53,7 +54,7 @@ import { import { mergeThemes, useTheme } from '../../contexts/themeContext/ThemeContext'; import { ThreadContextValue, useThreadContext } from '../../contexts/threadContext/ThreadContext'; -import { useStableCallback, useStateStore } from '../../hooks'; +import { useStableCallback } from '../../hooks'; import { isVideoPlayerAvailable } from '../../native'; import { bumpOverlayLayoutRevision, useHasActiveId } from '../../state-store'; import { MessageInputHeightState } from '../../state-store/message-input-height-store'; diff --git a/package/src/components/MessageList/MessageList.tsx b/package/src/components/MessageList/MessageList.tsx index eb7df10831..c649f6d9f0 100644 --- a/package/src/components/MessageList/MessageList.tsx +++ b/package/src/components/MessageList/MessageList.tsx @@ -12,6 +12,7 @@ import { import Animated from 'react-native-reanimated'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import debounce from 'lodash/debounce'; import type { LocalMessage, Thread } from 'stream-chat'; @@ -69,7 +70,6 @@ import { mergeThemes, useTheme } from '../../contexts/themeContext/ThemeContext' import { ThreadContextValue, useThreadContext } from '../../contexts/threadContext/ThreadContext'; import { useStableCallback } from '../../hooks'; -import { useStateStore } from '../../hooks/useStateStore'; import { bumpOverlayLayoutRevision, useHasActiveId } from '../../state-store'; import { MessageInputHeightState } from '../../state-store/message-input-height-store'; import { primitives } from '../../theme'; diff --git a/package/src/components/MessageList/TypingIndicatorContainer.tsx b/package/src/components/MessageList/TypingIndicatorContainer.tsx index 680562d9ba..da4e257c96 100644 --- a/package/src/components/MessageList/TypingIndicatorContainer.tsx +++ b/package/src/components/MessageList/TypingIndicatorContainer.tsx @@ -1,6 +1,7 @@ import React, { PropsWithChildren } from 'react'; import { StyleSheet, View } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { TypingUsersState } from 'stream-chat'; import { filterTypingUsers } from './utils/filterTypingUsers'; @@ -9,7 +10,6 @@ import { useChannelContext } from '../../contexts/channelContext/ChannelContext' import { ChatContextValue, useChatContext } from '../../contexts/chatContext/ChatContext'; import { useTheme } from '../../contexts/themeContext/ThemeContext'; import { useThreadContext } from '../../contexts/threadContext/ThreadContext'; -import { useStateStore } from '../../hooks/useStateStore'; import { primitives } from '../../theme'; const styles = StyleSheet.create({ diff --git a/package/src/components/MessageList/UnreadMessagesNotification.tsx b/package/src/components/MessageList/UnreadMessagesNotification.tsx index dcd538c5af..0cd4e26bd6 100644 --- a/package/src/components/MessageList/UnreadMessagesNotification.tsx +++ b/package/src/components/MessageList/UnreadMessagesNotification.tsx @@ -1,6 +1,7 @@ import React, { useMemo } from 'react'; import { StyleSheet, View } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { UnreadSnapshotState } from 'stream-chat'; import { DEFAULT_HIGHLIGHT_DURATION } from './hooks/useMessageListFocus'; @@ -9,7 +10,6 @@ import { useChannelContext } from '../../contexts/channelContext/ChannelContext' import { useComponentsContext } from '../../contexts/componentsContext/ComponentsContext'; import { useTheme } from '../../contexts/themeContext/ThemeContext'; import { useTranslationContext } from '../../contexts/translationContext/TranslationContext'; -import { useStateStore } from '../../hooks/useStateStore'; import { primitives } from '../../theme'; import { MarkReadFunctionOptions } from '../Channel/Channel'; import { useNotificationApi } from '../Notifications'; diff --git a/package/src/components/MessageList/__tests__/dateSeparatorSystemMessages.test.tsx b/package/src/components/MessageList/__tests__/dateSeparatorSystemMessages.test.tsx index 2909888532..d2062b6d69 100644 --- a/package/src/components/MessageList/__tests__/dateSeparatorSystemMessages.test.tsx +++ b/package/src/components/MessageList/__tests__/dateSeparatorSystemMessages.test.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { View } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { cleanup, render, waitFor } from '@testing-library/react-native'; import type { Channel as ChannelType, LocalMessage, TimestampNS } from 'stream-chat'; @@ -9,7 +10,6 @@ import { nsToMs } from 'stream-chat'; import { useChannelContext } from '../../../contexts/channelContext/ChannelContext'; import { WithComponents } from '../../../contexts/componentsContext/ComponentsContext'; import { OverlayProvider } from '../../../contexts/overlayContext/OverlayProvider'; -import { useStateStore } from '../../../hooks/useStateStore'; import { getOrCreateChannelApi } from '../../../mock-builders/api/getOrCreateChannel'; import { useMockedApis } from '../../../mock-builders/api/useMockedApis'; import { generateChannelResponse } from '../../../mock-builders/generator/channel'; diff --git a/package/src/components/MessageList/hooks/useMessageList.ts b/package/src/components/MessageList/hooks/useMessageList.ts index a6c45079c4..b3f0f097c2 100644 --- a/package/src/components/MessageList/hooks/useMessageList.ts +++ b/package/src/components/MessageList/hooks/useMessageList.ts @@ -1,8 +1,9 @@ import { useMemo } from 'react'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { LocalMessage, MessagePaginator } from 'stream-chat'; -import { useRAFCoalescedValue, useStateStore } from '../../../hooks'; +import { useRAFCoalescedValue } from '../../../hooks'; import { usePrunableMessageList } from '../../../hooks/usePrunableMessageList'; export type UseMessageListParams = { diff --git a/package/src/components/MessageList/hooks/useMessageListFocus.ts b/package/src/components/MessageList/hooks/useMessageListFocus.ts index f62941b6df..81ace044ec 100644 --- a/package/src/components/MessageList/hooks/useMessageListFocus.ts +++ b/package/src/components/MessageList/hooks/useMessageListFocus.ts @@ -1,11 +1,12 @@ import { useEffect } from 'react'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { MessagePaginator } from 'stream-chat'; import type { GoToMessage } from '../../../contexts/messageListItemContext/MessageListItemContext'; import { useMessagesContext } from '../../../contexts/messagesContext/MessagesContext'; import { useThreadContext } from '../../../contexts/threadContext/ThreadContext'; -import { useStableCallback, useStateStore } from '../../../hooks'; +import { useStableCallback } from '../../../hooks'; import { useOpenThreadAtMessage } from '../../Message/hooks/useOpenThreadAtMessage'; /** How long, in milliseconds, a message the list jumped to stays highlighted. */ diff --git a/package/src/components/MessageList/hooks/useMessageListPagination.ts b/package/src/components/MessageList/hooks/useMessageListPagination.ts index 4a58d504d1..20da94a614 100644 --- a/package/src/components/MessageList/hooks/useMessageListPagination.ts +++ b/package/src/components/MessageList/hooks/useMessageListPagination.ts @@ -1,8 +1,9 @@ import { useRef, useState } from 'react'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { MessagePaginator } from 'stream-chat'; -import { useStableCallback, useStateStore } from '../../../hooks'; +import { useStableCallback } from '../../../hooks'; const loadingSelector = (state: { isLoading: boolean; items?: unknown[] }) => ({ hasMessages: (state.items?.length ?? 0) > 0, diff --git a/package/src/components/MessageList/hooks/useOwnUnreadCount.ts b/package/src/components/MessageList/hooks/useOwnUnreadCount.ts index 36c6c39719..31fbe3b3b7 100644 --- a/package/src/components/MessageList/hooks/useOwnUnreadCount.ts +++ b/package/src/components/MessageList/hooks/useOwnUnreadCount.ts @@ -1,9 +1,9 @@ import { useMemo } from 'react'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { Channel, ReadState } from 'stream-chat'; import { useChatContext } from '../../../contexts/chatContext/ChatContext'; -import { useStateStore } from '../../../hooks/useStateStore'; /** * The current user's unread message count in `channel`, kept current as reads arrive. `undefined` diff --git a/package/src/components/MessageList/hooks/useTypingUsers.ts b/package/src/components/MessageList/hooks/useTypingUsers.ts index 3dc8e2e45f..0fab676636 100644 --- a/package/src/components/MessageList/hooks/useTypingUsers.ts +++ b/package/src/components/MessageList/hooks/useTypingUsers.ts @@ -1,9 +1,9 @@ import { useMemo } from 'react'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { Channel, TypingUsersState } from 'stream-chat'; import { useChannelContext, useChatContext, useThreadContext } from '../../../contexts'; -import { useStateStore } from '../../../hooks'; import { filterTypingUsers } from '../utils/filterTypingUsers'; const selector = (state: TypingUsersState) => ({ typing: state.typing }); diff --git a/package/src/components/Notifications/hooks/useNotifications.ts b/package/src/components/Notifications/hooks/useNotifications.ts index cee7f83d16..bfbd153738 100644 --- a/package/src/components/Notifications/hooks/useNotifications.ts +++ b/package/src/components/Notifications/hooks/useNotifications.ts @@ -1,9 +1,9 @@ import { useCallback } from 'react'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { Notification, NotificationManagerState } from 'stream-chat'; import { useChatContext } from '../../../contexts/chatContext/ChatContext'; -import { useStateStore } from '../../../hooks/useStateStore'; import { isNotificationForTarget, type NotificationTarget } from '../notificationTarget'; export type UseNotificationsFilter = (notification: Notification) => boolean; diff --git a/package/src/components/Notifications/hooks/useSystemNotifications.ts b/package/src/components/Notifications/hooks/useSystemNotifications.ts index 9224cf70df..7672c6fd6d 100644 --- a/package/src/components/Notifications/hooks/useSystemNotifications.ts +++ b/package/src/components/Notifications/hooks/useSystemNotifications.ts @@ -1,11 +1,11 @@ import { useCallback } from 'react'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { Notification, NotificationManagerState } from 'stream-chat'; import { hasSystemNotificationTag } from './useNotificationApi'; import { useChatContext } from '../../../contexts/chatContext/ChatContext'; -import { useStateStore } from '../../../hooks/useStateStore'; export type UseSystemNotificationsFilter = (notification: Notification) => boolean; diff --git a/package/src/components/Poll/CreatePollContent.tsx b/package/src/components/Poll/CreatePollContent.tsx index 53060e49ce..b0312d35d2 100644 --- a/package/src/components/Poll/CreatePollContent.tsx +++ b/package/src/components/Poll/CreatePollContent.tsx @@ -5,6 +5,7 @@ import { ScrollView } from 'react-native-gesture-handler'; import Animated, { LinearTransition, useSharedValue } from 'react-native-reanimated'; import { StateStore } from '@stream-io/state-store'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { PollComposerState } from 'stream-chat'; import { CreatePollOptions, CurrentOptionPositionsCache } from './components'; @@ -23,7 +24,6 @@ import { } from '../../contexts'; import { useComponentsContext } from '../../contexts/componentsContext/ComponentsContext'; import { useMessageComposer } from '../../contexts/messageInputContext/hooks/useMessageComposer'; -import { useStateStore } from '../../hooks/useStateStore'; import { primitives } from '../../theme'; import { useRtlMirrorSwitchStyle } from '../../utils/rtlMirrorSwitchStyle'; diff --git a/package/src/components/Poll/components/CreatePollOptions.tsx b/package/src/components/Poll/components/CreatePollOptions.tsx index 62536d1ee9..13ebc170fa 100644 --- a/package/src/components/Poll/components/CreatePollOptions.tsx +++ b/package/src/components/Poll/components/CreatePollOptions.tsx @@ -24,13 +24,13 @@ import Animated, { withSpring, } from 'react-native-reanimated'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { POLL_COMPOSER_VALIDATION_CODE, PollComposerOption, PollComposerState } from 'stream-chat'; import type { PollComposerValidationCode, PollComposerValidationError } from 'stream-chat'; import { useCreatePollContentContext, useTheme, useTranslationContext } from '../../../contexts'; import { useComponentsContext } from '../../../contexts/componentsContext/ComponentsContext'; import { useMessageComposer } from '../../../contexts/messageInputContext/hooks/useMessageComposer'; -import { useStateStore } from '../../../hooks/useStateStore'; import { primitives } from '../../../theme'; import type { ViewRef } from '../../../types/react-native-compat'; diff --git a/package/src/components/Poll/components/MultipleVotesSettings.tsx b/package/src/components/Poll/components/MultipleVotesSettings.tsx index d86851dcfc..db43d4a0e7 100644 --- a/package/src/components/Poll/components/MultipleVotesSettings.tsx +++ b/package/src/components/Poll/components/MultipleVotesSettings.tsx @@ -3,13 +3,13 @@ import { Platform, StyleSheet, Switch, Text, TextInput, View } from 'react-nativ import Animated, { LinearTransition, StretchInY, StretchOutY } from 'react-native-reanimated'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { PollComposerState } from 'stream-chat'; import { useCreatePollContentContext, useTheme, useTranslationContext } from '../../../contexts'; import { useComponentsContext } from '../../../contexts/componentsContext/ComponentsContext'; import { useMessageComposer } from '../../../contexts/messageInputContext/hooks/useMessageComposer'; import { useStableCallback } from '../../../hooks'; -import { useStateStore } from '../../../hooks/useStateStore'; import { primitives } from '../../../theme'; import type { TextInputRef } from '../../../types/react-native-compat'; import { useRtlMirrorSwitchStyle } from '../../../utils/rtlMirrorSwitchStyle'; diff --git a/package/src/components/Poll/contexts/PollUIStateContext.tsx b/package/src/components/Poll/contexts/PollUIStateContext.tsx index 831d937b25..89aed19d41 100644 --- a/package/src/components/Poll/contexts/PollUIStateContext.tsx +++ b/package/src/components/Poll/contexts/PollUIStateContext.tsx @@ -2,9 +2,10 @@ import React, { PropsWithChildren, useContext, useState } from 'react'; import { StateStore } from '@stream-io/state-store'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; + import { DEFAULT_BASE_CONTEXT_VALUE } from '../../../contexts/utils/defaultBaseContextValue'; import { isTestEnvironment } from '../../../contexts/utils/isTestEnvironment'; -import { useStateStore } from '../../../hooks/useStateStore'; export type PollUIState = { addCommentOpen: boolean; diff --git a/package/src/components/Poll/hooks/usePollStateStore.ts b/package/src/components/Poll/hooks/usePollStateStore.ts index bbfc6e7e9e..520546a23d 100644 --- a/package/src/components/Poll/hooks/usePollStateStore.ts +++ b/package/src/components/Poll/hooks/usePollStateStore.ts @@ -1,7 +1,7 @@ +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { PollState } from 'stream-chat'; import { usePollContext } from '../../../contexts'; -import { useStateStore } from '../../../hooks'; export const usePollStateStore = < T extends Readonly | Readonly>, diff --git a/package/src/components/Reply/Reply.tsx b/package/src/components/Reply/Reply.tsx index f56b12184b..bfa18cb416 100644 --- a/package/src/components/Reply/Reply.tsx +++ b/package/src/components/Reply/Reply.tsx @@ -11,6 +11,7 @@ import { ViewStyle, } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { getAttachmentPreviewUrl, isFileAttachment, @@ -32,7 +33,6 @@ import { import { useMessageComposer } from '../../contexts/messageInputContext/hooks/useMessageComposer'; import { useTheme } from '../../contexts/themeContext/ThemeContext'; import { useTranslationContext } from '../../contexts/translationContext/TranslationContext'; -import { useStateStore } from '../../hooks'; import { primitives } from '../../theme'; import { FileTypes } from '../../types/types'; import { checkQuotedMessageEquality } from '../../utils/utils'; diff --git a/package/src/components/Thread/Thread.tsx b/package/src/components/Thread/Thread.tsx index 2cfc099ae4..03e9a1b4d8 100644 --- a/package/src/components/Thread/Thread.tsx +++ b/package/src/components/Thread/Thread.tsx @@ -1,11 +1,11 @@ import React, { PropsWithChildren, useEffect } from 'react'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { LocalMessage, Thread as ThreadInstance } from 'stream-chat'; import { useComponentsContext } from '../../contexts/componentsContext/ComponentsContext'; import { ThreadContextValue, ThreadProvider } from '../../contexts/threadContext/ThreadContext'; import { useStableCallback } from '../../hooks'; -import { useStateStore } from '../../hooks/useStateStore'; import { ChannelConfigProps, ChannelShell } from '../Channel/ChannelShell'; import { useCreateThreadContext } from '../Channel/hooks/useCreateThreadContext'; import { getThreadNotificationHostId } from '../Notifications/notificationTarget'; diff --git a/package/src/components/Thread/components/ThreadFooterComponent.tsx b/package/src/components/Thread/components/ThreadFooterComponent.tsx index 712107fbbc..3b794dfdd8 100644 --- a/package/src/components/Thread/components/ThreadFooterComponent.tsx +++ b/package/src/components/Thread/components/ThreadFooterComponent.tsx @@ -1,6 +1,7 @@ import React, { useMemo } from 'react'; import { ActivityIndicator, StyleSheet, Text, View } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { ThreadState } from 'stream-chat'; import { useComponentsContext } from '../../../contexts/componentsContext/ComponentsContext'; @@ -10,7 +11,6 @@ import { useThreadContext, } from '../../../contexts/threadContext/ThreadContext'; import { useTranslationContext } from '../../../contexts/translationContext/TranslationContext'; -import { useStateStore } from '../../../hooks'; import { primitives } from '../../../theme'; type ThreadFooterComponentPropsWithContext = Pick & { diff --git a/package/src/components/ThreadList/ThreadList.tsx b/package/src/components/ThreadList/ThreadList.tsx index 0c56af7315..b25fc5ced5 100644 --- a/package/src/components/ThreadList/ThreadList.tsx +++ b/package/src/components/ThreadList/ThreadList.tsx @@ -1,6 +1,7 @@ import React, { useCallback, useEffect } from 'react'; import { FlatList, StyleSheet, View } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { PaginatorState, Thread } from 'stream-chat'; import { ThreadListItem } from './ThreadListItem'; @@ -13,7 +14,6 @@ import { ThreadsProvider, useThreadsContext, } from '../../contexts/threadsContext/ThreadsContext'; -import { useStateStore } from '../../hooks'; import { useLazyRef } from '../../hooks/useLazyRef'; import { generateRandomId } from '../../utils/utils'; diff --git a/package/src/components/ThreadList/ThreadListItem.tsx b/package/src/components/ThreadList/ThreadListItem.tsx index 49f0434e69..4638b18ebe 100644 --- a/package/src/components/ThreadList/ThreadListItem.tsx +++ b/package/src/components/ThreadList/ThreadListItem.tsx @@ -1,6 +1,7 @@ import React, { useCallback, useEffect, useMemo } from 'react'; import { Pressable, StyleSheet, Text, View } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { AttachmentManagerState, convertTimestampToDate, @@ -19,7 +20,6 @@ import { useThreadListItemContext, } from '../../contexts/threadsContext/ThreadListItemContext'; import { useThreadsContext } from '../../contexts/threadsContext/ThreadsContext'; -import { useStateStore } from '../../hooks'; import { getDateString } from '../../i18n/utils'; import { primitives } from '../../theme'; import { useChannelPreviewDisplayPresence } from '../ChannelPreview/hooks'; diff --git a/package/src/components/ThreadList/ThreadListUnreadBanner.tsx b/package/src/components/ThreadList/ThreadListUnreadBanner.tsx index ae5e8fbdae..288de9f3ab 100644 --- a/package/src/components/ThreadList/ThreadListUnreadBanner.tsx +++ b/package/src/components/ThreadList/ThreadListUnreadBanner.tsx @@ -1,11 +1,11 @@ import React, { useCallback, useMemo, useState } from 'react'; import { Pressable, StyleSheet, Text, View } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { ThreadManagerState } from 'stream-chat'; import { useChatContext, useTheme, useTranslationContext } from '../../contexts'; import { useComponentsContext } from '../../contexts/componentsContext/ComponentsContext'; -import { useStateStore } from '../../hooks'; import { primitives } from '../../theme'; const selector = (nextValue: ThreadManagerState) => diff --git a/package/src/components/ThreadList/ThreadMessagePreviewDeliveryStatus.tsx b/package/src/components/ThreadList/ThreadMessagePreviewDeliveryStatus.tsx index 749a579258..c35a753f6c 100644 --- a/package/src/components/ThreadList/ThreadMessagePreviewDeliveryStatus.tsx +++ b/package/src/components/ThreadList/ThreadMessagePreviewDeliveryStatus.tsx @@ -1,6 +1,7 @@ import React, { useMemo } from 'react'; import { StyleSheet, Text, View } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { Channel, ChannelConfig, LocalMessage } from 'stream-chat'; import { useChatContext } from '../../contexts/chatContext/ChatContext'; @@ -8,7 +9,6 @@ import { useComponentsContext } from '../../contexts/componentsContext/Component import { useTheme } from '../../contexts/themeContext/ThemeContext'; import { useTranslationContext } from '../../contexts/translationContext/TranslationContext'; import { MessageDeliveryStatus, useMessageDeliveryStatus } from '../../hooks'; -import { useStateStore } from '../../hooks/useStateStore'; import { primitives } from '../../theme'; import { MessageStatusTypes } from '../../utils/utils'; diff --git a/package/src/components/ui/GiphyChip.tsx b/package/src/components/ui/GiphyChip.tsx index 3f410a5173..06d1457598 100644 --- a/package/src/components/ui/GiphyChip.tsx +++ b/package/src/components/ui/GiphyChip.tsx @@ -1,12 +1,12 @@ import React, { useMemo } from 'react'; import { StyleSheet, View, Text, Pressable } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { TextComposerState } from 'stream-chat'; import { useComponentsContext } from '../../contexts/componentsContext/ComponentsContext'; import { useMessageComposer } from '../../contexts/messageInputContext/hooks/useMessageComposer'; import { useTheme } from '../../contexts/themeContext/ThemeContext'; -import { useStateStore } from '../../hooks/useStateStore'; import { primitives } from '../../theme'; const textComposerStateSelector = (state: TextComposerState) => ({ diff --git a/package/src/contexts/audioPlayerContext/AudioPlayerContext.tsx b/package/src/contexts/audioPlayerContext/AudioPlayerContext.tsx index af30ad7839..0273d2049b 100644 --- a/package/src/contexts/audioPlayerContext/AudioPlayerContext.tsx +++ b/package/src/contexts/audioPlayerContext/AudioPlayerContext.tsx @@ -1,6 +1,7 @@ import React, { createContext, PropsWithChildren, useContext, useEffect, useMemo } from 'react'; -import { useStateStore } from '../../hooks/useStateStore'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; + import { AudioPlayerPool, AudioPlayerPoolState } from '../../state-store/audio-player-pool'; import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue'; diff --git a/package/src/contexts/messageComposerContext/MessageComposerContext.tsx b/package/src/contexts/messageComposerContext/MessageComposerContext.tsx index 6ba9777d50..5848d46a8e 100644 --- a/package/src/contexts/messageComposerContext/MessageComposerContext.tsx +++ b/package/src/contexts/messageComposerContext/MessageComposerContext.tsx @@ -1,5 +1,6 @@ import React, { useContext, useEffect, useMemo, useState } from 'react'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { LocalMessage, MessageComposer, MessageComposerState } from 'stream-chat'; import { @@ -9,7 +10,6 @@ import { import { ChannelProps } from '../../components'; import { useStableCallback } from '../../hooks/useStableCallback'; -import { useStateStore } from '../../hooks/useStateStore'; import { useChatContext } from '../chatContext/ChatContext'; import { ThreadContextValue } from '../threadContext/ThreadContext'; import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue'; diff --git a/package/src/contexts/messageInputContext/hooks/useActiveCommand.ts b/package/src/contexts/messageInputContext/hooks/useActiveCommand.ts index bdcbbcacce..adad7bb965 100644 --- a/package/src/contexts/messageInputContext/hooks/useActiveCommand.ts +++ b/package/src/contexts/messageInputContext/hooks/useActiveCommand.ts @@ -1,9 +1,8 @@ +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { TextComposerState } from 'stream-chat'; import { useMessageComposer } from './useMessageComposer'; -import { useStateStore } from '../../../hooks/useStateStore'; - const activeCommandSelector = (state: TextComposerState) => ({ command: state.command, }); diff --git a/package/src/contexts/messageInputContext/hooks/useAttachmentManagerState.ts b/package/src/contexts/messageInputContext/hooks/useAttachmentManagerState.ts index dfb3185fe7..ce50f24d67 100644 --- a/package/src/contexts/messageInputContext/hooks/useAttachmentManagerState.ts +++ b/package/src/contexts/messageInputContext/hooks/useAttachmentManagerState.ts @@ -1,9 +1,8 @@ +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { AttachmentManagerState } from 'stream-chat'; import { useMessageComposer } from './useMessageComposer'; -import { useStateStore } from '../../../hooks/useStateStore'; - const stateSelector = (state: AttachmentManagerState) => ({ attachments: state.attachments, }); diff --git a/package/src/contexts/messageInputContext/hooks/useHasAttachments.ts b/package/src/contexts/messageInputContext/hooks/useHasAttachments.ts index 33e6d9c91b..3af3b57364 100644 --- a/package/src/contexts/messageInputContext/hooks/useHasAttachments.ts +++ b/package/src/contexts/messageInputContext/hooks/useHasAttachments.ts @@ -1,9 +1,8 @@ +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { AttachmentManagerState } from 'stream-chat'; import { useMessageComposer } from './useMessageComposer'; -import { useStateStore } from '../../../hooks/useStateStore'; - const stateSelector = (state: AttachmentManagerState) => ({ hasAttachments: state.attachments.length > 0, }); diff --git a/package/src/contexts/messageInputContext/hooks/useIsCommandDisabled.ts b/package/src/contexts/messageInputContext/hooks/useIsCommandDisabled.ts index 4cc02ee951..b4f6f49590 100644 --- a/package/src/contexts/messageInputContext/hooks/useIsCommandDisabled.ts +++ b/package/src/contexts/messageInputContext/hooks/useIsCommandDisabled.ts @@ -1,11 +1,10 @@ import { useMemo } from 'react'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { CommandSuggestion, MessageComposerState } from 'stream-chat'; import { useMessageComposer } from './useMessageComposer'; -import { useStateStore } from '../../../hooks/useStateStore'; - const hasQuotedMessageSelector = (state: MessageComposerState) => ({ hasQuotedMessage: !!state.quotedMessage, }); diff --git a/package/src/contexts/messageInputContext/hooks/useMessageComposerHasSendableData.ts b/package/src/contexts/messageInputContext/hooks/useMessageComposerHasSendableData.ts index fca2ac33c8..48874e6765 100644 --- a/package/src/contexts/messageInputContext/hooks/useMessageComposerHasSendableData.ts +++ b/package/src/contexts/messageInputContext/hooks/useMessageComposerHasSendableData.ts @@ -1,10 +1,9 @@ +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { EditingAuditState } from 'stream-chat'; import { useMessageComposer } from './useMessageComposer'; import { pendingUploadsEnabledSelector } from './usePendingUploadsEnabled'; -import { useStateStore } from '../../../hooks/useStateStore'; - const editingAuditStateStateSelector = (state: EditingAuditState) => state; export const useMessageComposerHasSendableData = () => { diff --git a/package/src/contexts/messageInputContext/hooks/usePendingUploadsEnabled.ts b/package/src/contexts/messageInputContext/hooks/usePendingUploadsEnabled.ts index 95de069ce3..a0a4ce6494 100644 --- a/package/src/contexts/messageInputContext/hooks/usePendingUploadsEnabled.ts +++ b/package/src/contexts/messageInputContext/hooks/usePendingUploadsEnabled.ts @@ -1,9 +1,8 @@ +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { MessageComposerConfig } from 'stream-chat'; import { useMessageComposer } from './useMessageComposer'; -import { useStateStore } from '../../../hooks/useStateStore'; - export const pendingUploadsEnabledSelector = (config: MessageComposerConfig) => ({ pendingUploadsEnabled: config.attachments.pendingUploadsEnabled, }); diff --git a/package/src/hooks/__tests__/useStateStore.test.tsx b/package/src/hooks/__tests__/useStateStore.test.tsx new file mode 100644 index 0000000000..50fd5f0cf6 --- /dev/null +++ b/package/src/hooks/__tests__/useStateStore.test.tsx @@ -0,0 +1,109 @@ +import { StateStore } from '@stream-io/state-store'; +import { useStateStore as useBindingStateStore } from '@stream-io/state-store/react-bindings'; +import { act, renderHook } from '@testing-library/react-native'; + +import { useStateStore } from '..'; + +type State = { + count: number; + items: string[]; + label?: string; + unrelated: number; +}; + +const initialState: State = { count: 0, items: ['a'], unrelated: 0 }; + +const countSelector = (state: State) => ({ count: state.count }); +const itemsSelector = (state: State) => state.items; +// Includes `label` only when it is set, so the selection gains or loses a key. +const optionalKeySelector = (state: State) => + state.label === undefined ? { count: state.count } : { count: state.count, label: state.label }; + +describe('useStateStore', () => { + it('is the hook from the state-store React bindings', () => { + expect(useStateStore).toBe(useBindingStateStore); + }); + + it('returns the current selection and follows store changes', () => { + const store = new StateStore(initialState); + const { result } = renderHook(() => useStateStore(store, countSelector)); + + expect(result.current).toEqual({ count: 0 }); + + act(() => store.partialNext({ count: 1 })); + + expect(result.current).toEqual({ count: 1 }); + }); + + it('keeps the selection reference while the selected values are unchanged', () => { + const store = new StateStore(initialState); + const { rerender, result } = renderHook(() => useStateStore(store, countSelector)); + const first = result.current; + + act(() => store.partialNext({ unrelated: 1 })); + rerender({}); + + expect(result.current).toBe(first); + }); + + it('returns a new selection when it gains a key', () => { + const store = new StateStore(initialState); + const { result } = renderHook(() => useStateStore(store, optionalKeySelector)); + + expect(result.current).toEqual({ count: 0 }); + + act(() => store.partialNext({ label: 'new' })); + + expect(result.current).toEqual({ count: 0, label: 'new' }); + }); + + it('returns a new selection when it loses a key', () => { + const store = new StateStore({ ...initialState, label: 'old' }); + const { result } = renderHook(() => useStateStore(store, optionalKeySelector)); + + expect(result.current).toEqual({ count: 0, label: 'old' }); + + act(() => store.partialNext({ label: undefined })); + + expect(result.current).toEqual({ count: 0 }); + }); + + it('returns a new array selection when the array grows with the same prefix', () => { + const store = new StateStore(initialState); + const { result } = renderHook(() => useStateStore(store, itemsSelector)); + + expect(result.current).toEqual(['a']); + + act(() => store.partialNext({ items: ['a', 'b'] })); + + expect(result.current).toEqual(['a', 'b']); + }); + + it('returns a new array selection when the array shrinks', () => { + const store = new StateStore({ ...initialState, items: ['a', 'b'] }); + const { result } = renderHook(() => useStateStore(store, itemsSelector)); + + expect(result.current).toEqual(['a', 'b']); + + act(() => store.partialNext({ items: ['a'] })); + + expect(result.current).toEqual(['a']); + }); + + it('keeps the array reference when a new array holds the same items', () => { + const store = new StateStore(initialState); + const { rerender, result } = renderHook(() => useStateStore(store, itemsSelector)); + const first = result.current; + + act(() => store.partialNext({ items: ['a'] })); + rerender({}); + + expect(result.current).toBe(first); + }); + + it('returns undefined without a store', () => { + const { result } = renderHook(() => useStateStore(undefined, countSelector)); + + expect(result.current).toBeUndefined(); + }); +}); diff --git a/package/src/hooks/actions/useChannelActionItems.tsx b/package/src/hooks/actions/useChannelActionItems.tsx index 8708bf34f1..80412c5873 100644 --- a/package/src/hooks/actions/useChannelActionItems.tsx +++ b/package/src/hooks/actions/useChannelActionItems.tsx @@ -1,6 +1,7 @@ import React, { useMemo } from 'react'; import { Alert } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { BlockedUsersState, Channel } from 'stream-chat'; import type { ActionItem } from './types'; @@ -20,7 +21,6 @@ import type { TranslationContextValue } from '../../contexts/translationContext/ import { IconProps } from '../../icons'; import { useChannelMembershipState } from '../useChannelMembershipState'; import { useIsDirectChat } from '../useIsDirectChat'; -import { useStateStore } from '../useStateStore'; // Required lazily: a static import of defaultComponents.ts would form a cycle // (defaultComponents -> ChannelDetails*/ChannelPreview* -> this file) and corrupt init order. diff --git a/package/src/hooks/actions/useChannelMemberActionItems.tsx b/package/src/hooks/actions/useChannelMemberActionItems.tsx index 16b9ae81e8..86b125d96f 100644 --- a/package/src/hooks/actions/useChannelMemberActionItems.tsx +++ b/package/src/hooks/actions/useChannelMemberActionItems.tsx @@ -1,6 +1,7 @@ import React, { useMemo } from 'react'; import { Alert } from 'react-native'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { BlockedUsersState, Channel, ChannelMemberResponse } from 'stream-chat'; import type { ActionItem } from './types'; @@ -14,7 +15,6 @@ import type { IconsMap } from '../../contexts/componentsContext/defaultComponent import type { TranslationContextValue } from '../../contexts/translationContext/TranslationContext'; import { IconProps } from '../../icons'; import { useChannelOwnCapabilities } from '../useChannelOwnCapabilities'; -import { useStateStore } from '../useStateStore'; // Required lazily: a static import of defaultComponents.ts would form a cycle // (defaultComponents -> ChannelDetails*/ChannelPreview* -> this file) and corrupt init order. diff --git a/package/src/hooks/index.ts b/package/src/hooks/index.ts index 375a0d4bf8..9d674504dd 100644 --- a/package/src/hooks/index.ts +++ b/package/src/hooks/index.ts @@ -18,7 +18,7 @@ export * from './useTranslatedMessage'; export * from './useViewport'; export * from './useScreenDimensions'; export * from './useScreenOrientation'; -export * from './useStateStore'; +export { useStateStore } from '@stream-io/state-store/react-bindings'; export * from './useChannel'; export * from './useMessagePaginator'; export * from './usePendingAttachmentUpload'; diff --git a/package/src/hooks/messagePreview/useMessageDeliveryStatus.ts b/package/src/hooks/messagePreview/useMessageDeliveryStatus.ts index 99a3bf4438..75269b91c9 100644 --- a/package/src/hooks/messagePreview/useMessageDeliveryStatus.ts +++ b/package/src/hooks/messagePreview/useMessageDeliveryStatus.ts @@ -1,5 +1,6 @@ import { useCallback, useMemo } from 'react'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { Channel, LocalMessage, @@ -9,7 +10,6 @@ import { } from 'stream-chat'; import { useChatContext } from '../../contexts/chatContext/ChatContext'; -import { useStateStore } from '../useStateStore'; export enum MessageDeliveryStatus { NOT_SENT_BY_CURRENT_USER = 'not_sent_by_current_user', diff --git a/package/src/hooks/messagePreview/useMessagePreviewText.tsx b/package/src/hooks/messagePreview/useMessagePreviewText.tsx index 15bf425b22..dd30bb7df8 100644 --- a/package/src/hooks/messagePreview/useMessagePreviewText.tsx +++ b/package/src/hooks/messagePreview/useMessagePreviewText.tsx @@ -1,3 +1,4 @@ +import { useStateStore } from '@stream-io/state-store/react-bindings'; import dayjs from 'dayjs'; import { DraftMessage, @@ -13,7 +14,6 @@ import { useGroupedAttachments } from './useGroupedAttachments'; import { useChatContext } from '../../contexts/chatContext/ChatContext'; import { useTranslationContext } from '../../contexts/translationContext/TranslationContext'; -import { useStateStore } from '../../hooks/useStateStore'; import { getTranslatedText } from '../../utils/i18n/getTranslatedText'; const selector = (nextValue: PollState) => ({ diff --git a/package/src/hooks/useAttachmentPickerState.ts b/package/src/hooks/useAttachmentPickerState.ts index 14591f856c..bf11d665cc 100644 --- a/package/src/hooks/useAttachmentPickerState.ts +++ b/package/src/hooks/useAttachmentPickerState.ts @@ -1,4 +1,4 @@ -import { useStateStore } from './useStateStore'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { useAttachmentPickerContext } from '../contexts/attachmentPickerContext/AttachmentPickerContext'; import { AttachmentPickerState } from '../state-store/attachment-picker-store'; diff --git a/package/src/hooks/useChannelImage.ts b/package/src/hooks/useChannelImage.ts index 203d6d8b1b..68f5195e80 100644 --- a/package/src/hooks/useChannelImage.ts +++ b/package/src/hooks/useChannelImage.ts @@ -1,7 +1,6 @@ +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { Channel } from 'stream-chat'; -import { useStateStore } from './useStateStore'; - const selector = (state: { data: Channel['data'] }) => ({ image: state.data?.custom?.image, }); diff --git a/package/src/hooks/useChannelMemberCount.ts b/package/src/hooks/useChannelMemberCount.ts index 86241c0963..3670d8213c 100644 --- a/package/src/hooks/useChannelMemberCount.ts +++ b/package/src/hooks/useChannelMemberCount.ts @@ -1,7 +1,6 @@ +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { Channel } from 'stream-chat'; -import { useStateStore } from './useStateStore'; - const selector = (state: { memberCount: number }) => ({ memberCount: state.memberCount, }); diff --git a/package/src/hooks/useChannelMembershipState.ts b/package/src/hooks/useChannelMembershipState.ts index b4083fb7f5..06c0111d40 100644 --- a/package/src/hooks/useChannelMembershipState.ts +++ b/package/src/hooks/useChannelMembershipState.ts @@ -1,7 +1,6 @@ +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { Channel, ChannelMemberResponse } from 'stream-chat'; -import { useStateStore } from './useStateStore'; - const selector = (state: { membership: ChannelMemberResponse }) => ({ membership: state.membership, }); diff --git a/package/src/hooks/useChannelName.ts b/package/src/hooks/useChannelName.ts index 1e1440ef26..761fe5d6db 100644 --- a/package/src/hooks/useChannelName.ts +++ b/package/src/hooks/useChannelName.ts @@ -1,7 +1,6 @@ +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { Channel } from 'stream-chat'; -import { useStateStore } from './useStateStore'; - const selector = (state: { data: Channel['data'] }) => ({ name: state.data?.custom?.name, }); diff --git a/package/src/hooks/useChannelOwnCapabilities.ts b/package/src/hooks/useChannelOwnCapabilities.ts index 16cd1b6a5e..ec1481c38f 100644 --- a/package/src/hooks/useChannelOwnCapabilities.ts +++ b/package/src/hooks/useChannelOwnCapabilities.ts @@ -1,7 +1,6 @@ +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { Channel } from 'stream-chat'; -import { useStateStore } from './useStateStore'; - const selector = (state: { ownCapabilities: string[] }) => ({ ownCapabilities: state.ownCapabilities, }); diff --git a/package/src/hooks/useClientNotifications.ts b/package/src/hooks/useClientNotifications.ts index 50dd98030c..d29194fe46 100644 --- a/package/src/hooks/useClientNotifications.ts +++ b/package/src/hooks/useClientNotifications.ts @@ -1,7 +1,6 @@ +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { NotificationManagerState } from 'stream-chat'; -import { useStateStore } from './useStateStore'; - import { useChatContext } from '../contexts/chatContext/ChatContext'; const selector = (state: NotificationManagerState) => ({ diff --git a/package/src/hooks/useDisplayedChannelMemberCount.ts b/package/src/hooks/useDisplayedChannelMemberCount.ts index 5875a37dab..d7b51ce971 100644 --- a/package/src/hooks/useDisplayedChannelMemberCount.ts +++ b/package/src/hooks/useDisplayedChannelMemberCount.ts @@ -1,7 +1,6 @@ +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { Channel } from 'stream-chat'; -import { useStateStore } from './useStateStore'; - const selector = (state: { activeMemberCount?: number; memberCount: number }) => ({ activeMemberCount: state.activeMemberCount, memberCount: state.memberCount, diff --git a/package/src/hooks/useInAppNotificationsState.ts b/package/src/hooks/useInAppNotificationsState.ts index e4c8b0f636..e1d8b0a825 100644 --- a/package/src/hooks/useInAppNotificationsState.ts +++ b/package/src/hooks/useInAppNotificationsState.ts @@ -1,7 +1,7 @@ +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { Notification } from 'stream-chat'; import { useStableCallback } from './useStableCallback'; -import { useStateStore } from './useStateStore'; import type { InAppNotificationsState } from '../state-store/in-app-notifications-store'; import { diff --git a/package/src/hooks/useIsTargetedMessage.ts b/package/src/hooks/useIsTargetedMessage.ts index 58066e596b..799474a8cb 100644 --- a/package/src/hooks/useIsTargetedMessage.ts +++ b/package/src/hooks/useIsTargetedMessage.ts @@ -1,7 +1,8 @@ import { useCallback } from 'react'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; + import { useMessagePaginator } from './useMessagePaginator'; -import { useStateStore } from './useStateStore'; type MessageFocusSignalState = { signal: { messageId?: string } | null }; diff --git a/package/src/hooks/useMessageReminder.ts b/package/src/hooks/useMessageReminder.ts index 00d4372c26..5f2c7749d8 100644 --- a/package/src/hooks/useMessageReminder.ts +++ b/package/src/hooks/useMessageReminder.ts @@ -1,9 +1,8 @@ import { useCallback } from 'react'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { ReminderManagerState } from 'stream-chat'; -import { useStateStore } from './useStateStore'; - import { useChatContext } from '../contexts/chatContext/ChatContext'; export const useMessageReminder = (messageId: string) => { diff --git a/package/src/hooks/usePendingAttachmentUpload.ts b/package/src/hooks/usePendingAttachmentUpload.ts index fa6bbed030..18b49aa4ac 100644 --- a/package/src/hooks/usePendingAttachmentUpload.ts +++ b/package/src/hooks/usePendingAttachmentUpload.ts @@ -1,9 +1,8 @@ import { useCallback, useEffect, useRef, useState } from 'react'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { UploadManagerState } from 'stream-chat'; -import { useStateStore } from './useStateStore'; - import { useChatContext } from '../contexts/chatContext/ChatContext'; export type PendingAttachmentUpload = { diff --git a/package/src/hooks/usePrunableMessageList.ts b/package/src/hooks/usePrunableMessageList.ts index ef5ae99a61..583c69de57 100644 --- a/package/src/hooks/usePrunableMessageList.ts +++ b/package/src/hooks/usePrunableMessageList.ts @@ -1,9 +1,9 @@ import { useEffect, useRef } from 'react'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { MessagePaginator } from 'stream-chat'; import { useStableCallback } from './useStableCallback'; -import { useStateStore } from './useStateStore'; import type { ViewToken } from '../types/react-native-compat'; diff --git a/package/src/hooks/useQueryReminders.ts b/package/src/hooks/useQueryReminders.ts index 5864f77ca9..31548adbb7 100644 --- a/package/src/hooks/useQueryReminders.ts +++ b/package/src/hooks/useQueryReminders.ts @@ -1,11 +1,10 @@ import { useCallback, useEffect, useRef, useState } from 'react'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { EventPayload, PaginatorState, ReminderFilters, ReminderResponseData } from 'stream-chat'; import { nowNs } from 'stream-chat'; -import { useStateStore } from './useStateStore'; - import { useChatContext } from '../contexts/chatContext/ChatContext'; const selector = (nextValue: PaginatorState) => diff --git a/package/src/hooks/useStateStore.ts b/package/src/hooks/useStateStore.ts deleted file mode 100644 index 320ae6e688..0000000000 --- a/package/src/hooks/useStateStore.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { useCallback, useMemo } from 'react'; - -import type { StateStore } from '@stream-io/state-store'; -import { useSyncExternalStore } from 'use-sync-external-store/shim'; - -const noop = () => {}; - -export function useStateStore< - T extends Record, - O extends Readonly | Readonly>, ->(store: StateStore, selector: (v: T) => O): O; -export function useStateStore< - T extends Record, - O extends Readonly | Readonly>, ->(store: StateStore | undefined, selector: (v: T) => O): O | undefined; -export function useStateStore< - T extends Record, - O extends Readonly | Readonly>, ->(store: StateStore | undefined, selector: (v: T) => O) { - const wrappedSubscription = useCallback( - (onStoreChange: () => void) => { - const unsubscribe = store?.subscribeWithSelector(selector, onStoreChange); - return unsubscribe ?? noop; - }, - [store, selector], - ); - - const wrappedSnapshot = useMemo(() => { - let cachedTuple: [T, O]; - - return () => { - const currentValue = store?.getLatestValue(); - - if (!currentValue) return undefined; - - // store value hasn't changed, no need to compare individual values - if (cachedTuple && cachedTuple[0] === currentValue) { - return cachedTuple[1]; - } - - const newlySelected = selector(currentValue); - - // store value changed but selected values wouldn't have to, double-check selected - if (cachedTuple) { - let selectededAreEqualToCached = true; - - for (const key in cachedTuple[1]) { - if (cachedTuple[1][key] === newlySelected[key]) continue; - selectededAreEqualToCached = false; - break; - } - - if (selectededAreEqualToCached) return cachedTuple[1]; - } - - cachedTuple = [currentValue, newlySelected]; - return cachedTuple[1]; - }; - }, [store, selector]); - - const state = useSyncExternalStore(wrappedSubscription, wrappedSnapshot); - - return state; -} diff --git a/package/src/hooks/useStreami18n.ts b/package/src/hooks/useStreami18n.ts index 00422897db..9caf4b48b5 100644 --- a/package/src/hooks/useStreami18n.ts +++ b/package/src/hooks/useStreami18n.ts @@ -2,7 +2,7 @@ import { useEffect, useMemo } from 'react'; import type { Streami18nState } from '@stream-io/i18n'; -import { useStateStore } from './useStateStore'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import type { TranslatorFunctions } from '../contexts/translationContext/types'; import type { BundledTranslationKey } from '../i18n/keys'; diff --git a/package/src/state-store/edit-channel-details-store.ts b/package/src/state-store/edit-channel-details-store.ts index 473143cc3c..f742020fe8 100644 --- a/package/src/state-store/edit-channel-details-store.ts +++ b/package/src/state-store/edit-channel-details-store.ts @@ -1,7 +1,7 @@ import { StateStore } from '@stream-io/state-store'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { Channel } from 'stream-chat'; -import { useStateStore } from '../hooks/useStateStore'; import type { File } from '../types/types'; export type EditChannelImagePendingAction = 'camera' | 'library' | 'reset'; diff --git a/package/src/state-store/message-overlay-store.ts b/package/src/state-store/message-overlay-store.ts index f3bdcb7fe7..953e295f80 100644 --- a/package/src/state-store/message-overlay-store.ts +++ b/package/src/state-store/message-overlay-store.ts @@ -3,10 +3,9 @@ import { useCallback, useEffect, useRef } from 'react'; import { makeMutable, type SharedValue } from 'react-native-reanimated'; import { StateStore } from '@stream-io/state-store'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; import { useSyncExternalStore } from 'use-sync-external-store/shim'; -import { useStateStore } from '../hooks'; - type OverlayState = { closingPortalHostBlacklist: string[]; id: string | undefined; diff --git a/package/src/state-store/selection-store.ts b/package/src/state-store/selection-store.ts index c1c4a7e432..df45bb15cc 100644 --- a/package/src/state-store/selection-store.ts +++ b/package/src/state-store/selection-store.ts @@ -2,7 +2,7 @@ import { useCallback } from 'react'; import { StateStore } from '@stream-io/state-store'; -import { useStateStore } from '../hooks/useStateStore'; +import { useStateStore } from '@stream-io/state-store/react-bindings'; export type SelectionState = { /** IDs of the currently selected items. */ diff --git a/yarn.lock b/yarn.lock index 334c76f8a6..e3965734e6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6757,9 +6757,9 @@ __metadata: languageName: node linkType: hard -"@stream-io/state-store@npm:^1.2.0, @stream-io/state-store@npm:^1.3.0": - version: 1.3.0 - resolution: "@stream-io/state-store@npm:1.3.0" +"@stream-io/state-store@npm:^1.2.0, @stream-io/state-store@npm:^1.3.1": + version: 1.3.1 + resolution: "@stream-io/state-store@npm:1.3.1" peerDependencies: react: ^17 || ^18 || ^19 use-sync-external-store: ^1.5.0 @@ -6768,7 +6768,7 @@ __metadata: optional: true use-sync-external-store: optional: true - checksum: 10c0/92cfd7e3f5008dc84cb0bf7b8cb75a1501ef6fe32c17671f40f2f5ba5a2f874da3ecd806cde277c74f0cdf1443ae7f3e649184319511d803a56efe6acb6f6eb8 + checksum: 10c0/20d58fb89e1bca05ecd4a7d74bcdf01290053d3ddafb4ce4716279bbf68272f393e25ece4e7152adfe031ad582d3e8bce080901b6b66694663212dd8c55cf46f languageName: node linkType: hard @@ -19631,7 +19631,7 @@ __metadata: "@react-navigation/native-stack": "npm:^7.20.0" "@rnx-kit/metro-config": "npm:^2.2.6" "@shopify/flash-list": "npm:^2.3.3" - "@stream-io/state-store": "npm:^1.3.0" + "@stream-io/state-store": "npm:^1.3.1" "@stream-io/typescript-config": "workspace:^" "@types/lodash.mergewith": "npm:^4.6.9" "@types/react": "npm:^19.3.0" @@ -20464,7 +20464,7 @@ __metadata: "@shopify/flash-list": "npm:^2.3.3" "@shopify/react-native-skia": "npm:^2.13.0" "@stream-io/i18n": "npm:^1.1.0" - "@stream-io/state-store": "npm:^1.3.0" + "@stream-io/state-store": "npm:^1.3.1" "@stream-io/typescript-config": "workspace:^" "@testing-library/jest-native": "npm:^5.4.3" "@testing-library/react-native": "npm:13.2.0"