Skip to content

Commit 44c4cba

Browse files
committed
chore: add event handler overrides
1 parent 3b3d4e6 commit 44c4cba

File tree

1 file changed

+48
-20
lines changed

1 file changed

+48
-20
lines changed

package/src/components/ChannelList/ChannelList.tsx

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export type ChannelListProps<
100100
* @overrideType Function
101101
* */
102102
onAddedToChannel?: (
103-
setChannels: React.Dispatch<React.SetStateAction<Channel<StreamChatGenerics>[] | null>>,
103+
setChannels: React.Dispatch<React.SetStateAction<Channel<StreamChatGenerics>[]>>,
104104
event: Event<StreamChatGenerics>,
105105
) => void;
106106
/**
@@ -112,7 +112,7 @@ export type ChannelListProps<
112112
* @overrideType Function
113113
* */
114114
onChannelDeleted?: (
115-
setChannels: React.Dispatch<React.SetStateAction<Channel<StreamChatGenerics>[] | null>>,
115+
setChannels: React.Dispatch<React.SetStateAction<Channel<StreamChatGenerics>[]>>,
116116
event: Event<StreamChatGenerics>,
117117
) => void;
118118
/**
@@ -124,7 +124,7 @@ export type ChannelListProps<
124124
* @overrideType Function
125125
* */
126126
onChannelHidden?: (
127-
setChannels: React.Dispatch<React.SetStateAction<Channel<StreamChatGenerics>[] | null>>,
127+
setChannels: React.Dispatch<React.SetStateAction<Channel<StreamChatGenerics>[]>>,
128128
event: Event<StreamChatGenerics>,
129129
) => void;
130130
/**
@@ -136,7 +136,7 @@ export type ChannelListProps<
136136
* @overrideType Function
137137
* */
138138
onChannelTruncated?: (
139-
setChannels: React.Dispatch<React.SetStateAction<Channel<StreamChatGenerics>[] | null>>,
139+
setChannels: React.Dispatch<React.SetStateAction<Channel<StreamChatGenerics>[]>>,
140140
event: Event<StreamChatGenerics>,
141141
) => void;
142142
/**
@@ -148,7 +148,7 @@ export type ChannelListProps<
148148
* @overrideType Function
149149
* */
150150
onChannelUpdated?: (
151-
setChannels: React.Dispatch<React.SetStateAction<Channel<StreamChatGenerics>[] | null>>,
151+
setChannels: React.Dispatch<React.SetStateAction<Channel<StreamChatGenerics>[]>>,
152152
event: Event<StreamChatGenerics>,
153153
) => void;
154154
/**
@@ -160,7 +160,7 @@ export type ChannelListProps<
160160
* @overrideType Function
161161
* */
162162
onChannelVisible?: (
163-
setChannels: React.Dispatch<React.SetStateAction<Channel<StreamChatGenerics>[] | null>>,
163+
setChannels: React.Dispatch<React.SetStateAction<Channel<StreamChatGenerics>[]>>,
164164
event: Event<StreamChatGenerics>,
165165
) => void;
166166
/**
@@ -175,7 +175,7 @@ export type ChannelListProps<
175175
* */
176176
onNewMessage?: (
177177
lockChannelOrder: boolean,
178-
setChannels: React.Dispatch<React.SetStateAction<Channel<StreamChatGenerics>[] | null>>,
178+
setChannels: React.Dispatch<React.SetStateAction<Channel<StreamChatGenerics>[]>>,
179179
event: Event<StreamChatGenerics>,
180180
) => void;
181181
/**
@@ -188,7 +188,7 @@ export type ChannelListProps<
188188
* @overrideType Function
189189
* */
190190
onNewMessageNotification?: (
191-
setChannels: React.Dispatch<React.SetStateAction<Channel<StreamChatGenerics>[] | null>>,
191+
setChannels: React.Dispatch<React.SetStateAction<Channel<StreamChatGenerics>[]>>,
192192
event: Event<StreamChatGenerics>,
193193
) => void;
194194
/**
@@ -200,7 +200,7 @@ export type ChannelListProps<
200200
* @overrideType Function
201201
* */
202202
onRemovedFromChannel?: (
203-
setChannels: React.Dispatch<React.SetStateAction<Channel<StreamChatGenerics>[] | null>>,
203+
setChannels: React.Dispatch<React.SetStateAction<Channel<StreamChatGenerics>[]>>,
204204
event: Event<StreamChatGenerics>,
205205
) => void;
206206
/**
@@ -248,15 +248,15 @@ export const ChannelList = <
248248
lockChannelOrder = false,
249249
maxUnreadCount = 255,
250250
numberOfSkeletons = 6,
251-
// onAddedToChannel,
252-
// onChannelDeleted,
253-
// onChannelHidden,
254-
// onChannelTruncated,
255-
// onChannelUpdated,
256-
// onChannelVisible,
257-
// onNewMessage,
258-
// onNewMessageNotification,
259-
// onRemovedFromChannel,
251+
onAddedToChannel,
252+
onChannelDeleted,
253+
onChannelHidden,
254+
onChannelTruncated,
255+
onChannelUpdated,
256+
onChannelVisible,
257+
onNewMessage,
258+
onNewMessageNotification,
259+
onRemovedFromChannel,
260260
onSelect,
261261
options = DEFAULT_OPTIONS,
262262
Preview = ChannelPreviewMessenger,
@@ -274,8 +274,36 @@ export const ChannelList = <
274274
const [forceUpdate, setForceUpdate] = useState(0);
275275
const { client, enableOfflineSupport } = useChatContext<StreamChatGenerics>();
276276
const createChannelManager = useCallback(
277-
() => client.createChannelManager({ options: { lockChannelOrder } }),
278-
[client, lockChannelOrder],
277+
() =>
278+
client.createChannelManager({
279+
eventHandlerOverrides: {
280+
channelDeletedHandler: onChannelDeleted,
281+
channelHiddenHandler: onChannelHidden,
282+
channelTruncatedHandler: onChannelTruncated,
283+
channelUpdatedHandler: onChannelUpdated,
284+
channelVisibleHandler: onChannelVisible,
285+
newMessageHandler: onNewMessage
286+
? (setChannels, event) => onNewMessage(lockChannelOrder, setChannels, event)
287+
: undefined,
288+
notificationAddedToChannelHandler: onAddedToChannel,
289+
notificationNewMessageHandler: onNewMessageNotification,
290+
notificationRemovedFromChannelHandler: onRemovedFromChannel,
291+
},
292+
options: { lockChannelOrder },
293+
}),
294+
[
295+
client,
296+
lockChannelOrder,
297+
onAddedToChannel,
298+
onChannelDeleted,
299+
onChannelHidden,
300+
onChannelTruncated,
301+
onChannelUpdated,
302+
onChannelVisible,
303+
onNewMessage,
304+
onNewMessageNotification,
305+
onRemovedFromChannel,
306+
],
279307
);
280308
const clientManagerRef = useRef(createChannelManager);
281309
const [channelManager, setChannelManager] = useState<ChannelManager<StreamChatGenerics>>(

0 commit comments

Comments
 (0)