1
- import React , { useContext , useEffect } from 'react' ;
1
+ import { Channel } from 'chatkitty' ;
2
+ import React , { useContext , useEffect , useState } from 'react' ;
2
3
import {
3
4
FlexRow ,
4
5
Heading ,
@@ -11,6 +12,7 @@ import { usePaginator } from 'react-chat-ui-kit';
11
12
12
13
import { ChatAppContext } from '../providers/ChatAppProvider' ;
13
14
15
+ import DisplayNotification from './DisplayNotification' ;
14
16
import MyChannelListItem from './MyChannelListItem' ;
15
17
16
18
const MyChannels : React . FC = ( ) => {
@@ -20,9 +22,12 @@ const MyChannels: React.FC = () => {
20
22
onLeftChannel,
21
23
loading,
22
24
currentUser,
25
+ currentNotification,
23
26
showChat,
24
27
showJoinChannel,
25
28
} = useContext ( ChatAppContext ) ;
29
+ const [ notificationView , setNotificationView ] = useState < boolean > ( false ) ;
30
+ const [ channelList , setChannelList ] = useState < Channel [ ] > ( [ ] ) ;
26
31
27
32
const {
28
33
items : channels ,
@@ -35,6 +40,7 @@ const MyChannels: React.FC = () => {
35
40
onInitialPageFetched : ( items ) => {
36
41
if ( items ) {
37
42
showChat ( items [ 0 ] ) ;
43
+ setChannelList ( items ) ;
38
44
}
39
45
} ,
40
46
dependencies : [ currentUser ] ,
@@ -52,11 +58,42 @@ const MyChannels: React.FC = () => {
52
58
} ) ;
53
59
} , [ currentUser ] ) ;
54
60
61
+ useEffect ( ( ) => {
62
+
63
+ if ( currentNotification ) {
64
+ setNotificationView ( true ) ;
65
+
66
+ const interval = setTimeout ( ( ) => {
67
+ setNotificationView ( false ) ;
68
+ clearTimeout ( interval ) ;
69
+ } , 10000 ) ;
70
+ }
71
+ } , [ currentNotification ] ) ;
72
+
73
+ const onClick = ( ) => {
74
+ setNotificationView ( false ) ;
75
+ if ( currentNotification ?. channel ) {
76
+ if ( channelList ) {
77
+ const currentNotificationChannelId = currentNotification . channel . id ;
78
+ channelList . find ( ( currentChannel ) => {
79
+ if ( currentChannel . id === currentNotificationChannelId ) {
80
+ showChat ( currentChannel ) ;
81
+ }
82
+ } ) ;
83
+ }
84
+ }
85
+ } ;
86
+
55
87
return loading ? (
56
88
< div > Loading...</ div >
57
89
) : (
58
90
< >
59
- < FlexRow justifyContent = "space-between" mx = { 6 } marginBottom = { 1 } >
91
+ < FlexRow
92
+ justifyContent = "space-between"
93
+ mx = { 6 }
94
+ marginBottom = { 1 }
95
+ display = "relative"
96
+ >
60
97
< Heading variant = { HeadingVariants . INVERSE } > Channels</ Heading >
61
98
< Icon
62
99
icon = { Icons . Add }
@@ -75,6 +112,13 @@ const MyChannels: React.FC = () => {
75
112
) ) }
76
113
< div ref = { boundaryRef } />
77
114
</ ScrollView >
115
+ { notificationView && currentNotification && (
116
+ < div onClick = { onClick } >
117
+ < DisplayNotification
118
+ notification = { currentNotification }
119
+ />
120
+ </ div >
121
+ ) }
78
122
</ >
79
123
) ;
80
124
} ;
0 commit comments