@linktr.ee/messaging-react 1.22.2 → 1.22.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linktr.ee/messaging-react",
3
- "version": "1.22.2",
3
+ "version": "1.22.3",
4
4
  "description": "React messaging components built on messaging-core for web applications",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -0,0 +1,23 @@
1
+ import React from 'react'
2
+ import type { Channel, LocalMessage } from 'stream-chat'
3
+
4
+ type ChannelListContextValue = {
5
+ selectedChannel?: Channel | null
6
+ onChannelSelect: (channel: Channel) => void
7
+ debug: boolean
8
+ renderMessagePreview?: (
9
+ message: LocalMessage | undefined,
10
+ defaultPreview?: string
11
+ ) => React.ReactNode
12
+ }
13
+
14
+ const ChannelListContext = React.createContext<ChannelListContextValue>({
15
+ selectedChannel: undefined,
16
+ onChannelSelect: () => {},
17
+ debug: false,
18
+ renderMessagePreview: undefined,
19
+ })
20
+
21
+ export const ChannelListProvider = ChannelListContext.Provider
22
+
23
+ export const useChannelListContext = () => React.useContext(ChannelListContext)
@@ -1,34 +1,21 @@
1
1
  import classNames from 'classnames'
2
2
  import React from 'react'
3
- import { Channel, LocalMessage } from 'stream-chat'
4
3
  import { ChannelPreviewUIComponentProps } from 'stream-chat-react'
5
4
 
6
5
  import { formatRelativeTime } from '../../utils/formatRelativeTime'
7
6
  import { Avatar } from '../Avatar'
8
7
  import { isChatbotMessage } from '../CustomMessage/MessageTag'
9
8
 
10
- type CustomChannelPreviewProps = ChannelPreviewUIComponentProps & {
11
- selectedChannel?: Channel | null
12
- onChannelSelect: (channel: Channel) => void
13
- debug?: boolean
14
- renderMessagePreview?: (
15
- message: LocalMessage | undefined,
16
- defaultPreview?: string
17
- ) => React.ReactNode
18
- }
9
+ import { useChannelListContext } from './ChannelListContext'
19
10
 
20
11
  /**
21
12
  * Custom channel preview that handles selection
22
13
  */
23
- const CustomChannelPreview = React.memo<CustomChannelPreviewProps>(
24
- ({
25
- channel,
26
- selectedChannel,
27
- onChannelSelect,
28
- debug = false,
29
- unread,
30
- renderMessagePreview,
31
- }) => {
14
+ const CustomChannelPreview = React.memo<ChannelPreviewUIComponentProps>(
15
+ ({ channel, unread }) => {
16
+ const { selectedChannel, onChannelSelect, debug, renderMessagePreview } =
17
+ useChannelListContext()
18
+
32
19
  const isSelected = selectedChannel?.id === channel?.id
33
20
 
34
21
  const handleClick = () => {
@@ -1,11 +1,11 @@
1
1
  import classNames from 'classnames'
2
2
  import React from 'react'
3
- import type { ChannelPreviewUIComponentProps } from 'stream-chat-react'
4
3
  import { ChannelList as StreamChannelList } from 'stream-chat-react'
5
4
 
6
5
  import { useMessagingContext } from '../../providers/MessagingProvider'
7
6
  import type { ChannelListProps } from '../../types'
8
7
 
8
+ import { ChannelListProvider } from './ChannelListContext'
9
9
  import CustomChannelPreview from './CustomChannelPreview'
10
10
 
11
11
  /**
@@ -35,19 +35,15 @@ export const ChannelList = React.memo<ChannelListProps>(
35
35
  })
36
36
  }
37
37
 
38
- // Memoize Preview component to prevent re-renders
39
- const PreviewComponent = React.useMemo(() => {
40
- const Preview = (props: ChannelPreviewUIComponentProps) => (
41
- <CustomChannelPreview
42
- {...props}
43
- selectedChannel={selectedChannel}
44
- onChannelSelect={onChannelSelect}
45
- debug={debug}
46
- renderMessagePreview={renderMessagePreview}
47
- />
48
- )
49
- return Preview
50
- }, [selectedChannel, onChannelSelect, debug, renderMessagePreview])
38
+ const contextValue = React.useMemo(
39
+ () => ({
40
+ selectedChannel,
41
+ onChannelSelect,
42
+ debug,
43
+ renderMessagePreview,
44
+ }),
45
+ [selectedChannel, onChannelSelect, debug, renderMessagePreview]
46
+ )
51
47
 
52
48
  return (
53
49
  <div
@@ -58,14 +54,16 @@ export const ChannelList = React.memo<ChannelListProps>(
58
54
  >
59
55
  {/* Channel List */}
60
56
  <div className="flex-1 overflow-hidden min-w-0">
61
- <StreamChannelList
62
- key={JSON.stringify(filters)}
63
- filters={filters}
64
- sort={{ last_message_at: -1 }}
65
- options={{ limit: 30 }}
66
- Preview={PreviewComponent}
67
- EmptyStateIndicator={customEmptyStateIndicator}
68
- />
57
+ <ChannelListProvider value={contextValue}>
58
+ <StreamChannelList
59
+ key={JSON.stringify(filters)}
60
+ filters={filters}
61
+ sort={{ last_message_at: -1 }}
62
+ options={{ limit: 30 }}
63
+ Preview={CustomChannelPreview}
64
+ EmptyStateIndicator={customEmptyStateIndicator}
65
+ />
66
+ </ChannelListProvider>
69
67
  </div>
70
68
  </div>
71
69
  )