11import React , { PureComponent , RefObject } from 'react' ;
2- import { v4 as uuidv4 } from 'uuid' ;
32
43import { Center } from './Center' ;
54import { ConnectionStatus } from './ConnectionStatus' ;
@@ -71,11 +70,6 @@ class MessageListWithContext<
7170 MessageListWithContextProps < At , Ch , Co , Ev , Me , Re , Us > ,
7271 {
7372 newMessagesNotification : boolean ;
74- notifications : Array < {
75- id : string ;
76- text : string ;
77- type : 'success' | 'error' ;
78- } > ;
7973 messageListRect ?: DOMRect ;
8074 }
8175> {
@@ -87,7 +81,6 @@ class MessageListWithContext<
8781
8882 bottomRef : RefObject < HTMLDivElement > ;
8983 messageList : RefObject < HTMLDivElement > ;
90- notificationTimeouts : Array < NodeJS . Timeout > ;
9184 closeToTop : boolean | undefined ;
9285 scrollOffset : number | undefined ;
9386
@@ -96,12 +89,10 @@ class MessageListWithContext<
9689
9790 this . state = {
9891 newMessagesNotification : false ,
99- notifications : [ ] ,
10092 } ;
10193
10294 this . bottomRef = React . createRef ( ) ;
10395 this . messageList = React . createRef ( ) ;
104- this . notificationTimeouts = [ ] ;
10596 }
10697
10798 componentDidMount ( ) {
@@ -114,10 +105,6 @@ class MessageListWithContext<
114105 } ) ;
115106 }
116107
117- componentWillUnmount ( ) {
118- this . notificationTimeouts . forEach ( clearTimeout ) ;
119- }
120-
121108 getSnapshotBeforeUpdate (
122109 prevProps : MessageListWithContextProps < At , Ch , Co , Ev , Me , Re , Us > ,
123110 ) {
@@ -270,35 +257,6 @@ class MessageListWithContext<
270257 }
271258 } ;
272259
273- /**
274- * Adds a temporary notification to message list.
275- * Notification will be removed after 5 seconds.
276- *
277- * @param notificationText Text of notification to be added
278- * @param type Type of notification. success | error
279- */
280- addNotification = ( notificationText : string , type : 'success' | 'error' ) => {
281- if ( typeof notificationText !== 'string' ) return ;
282- if ( type !== 'success' && type !== 'error' ) return ;
283-
284- const id = uuidv4 ( ) ;
285-
286- this . setState ( ( { notifications } ) => ( {
287- notifications : [ ...notifications , { id, text : notificationText , type } ] ,
288- } ) ) ;
289-
290- // remove the notification after 5000 ms
291- const ct = setTimeout (
292- ( ) =>
293- this . setState ( ( { notifications } ) => ( {
294- notifications : notifications . filter ( ( n ) => n . id !== id ) ,
295- } ) ) ,
296- 5000 ,
297- ) ;
298-
299- this . notificationTimeouts . push ( ct ) ;
300- } ;
301-
302260 onMessageLoadCaptured = ( ) => {
303261 // A load event (emitted by e.g. an <img>) was captured on a message.
304262 // In some cases, the loaded asset is larger than the placeholder, which means we have to scroll down.
@@ -319,6 +277,7 @@ class MessageListWithContext<
319277
320278 render ( ) {
321279 const {
280+ addNotification,
322281 Attachment = DefaultAttachment ,
323282 Avatar = DefaultAvatar ,
324283 DateSeparator = DefaultDateSeparator ,
@@ -329,6 +288,7 @@ class MessageListWithContext<
329288 messageActions = Object . keys ( MESSAGE_ACTIONS ) ,
330289 messages = [ ] ,
331290 MessageSystem = EventComponent ,
291+ notifications,
332292 noGroupByUser = false ,
333293 pinPermissions = defaultPinPermissions ,
334294 t,
@@ -370,7 +330,7 @@ class MessageListWithContext<
370330 internalMessageProps = { {
371331 additionalMessageInputProps : this . props
372332 . additionalMessageInputProps ,
373- addNotification : this . addNotification ,
333+ addNotification,
374334 Attachment,
375335 Avatar,
376336 channel : this . props . channel ,
@@ -411,7 +371,7 @@ class MessageListWithContext<
411371 />
412372 </ div >
413373 < div className = 'str-chat__list-notifications' >
414- { this . state . notifications . map ( ( notification ) => (
374+ { notifications . map ( ( notification ) => (
415375 < CustomNotification
416376 active = { true }
417377 key = { notification . id }
0 commit comments