@@ -12,12 +12,14 @@ import {
1212 RouterContextProvider ,
1313} from "tabler-react" ;
1414
15+ import type { NotificationProps } from "tabler-react" ;
16+
1517type Props = { |
1618 + children : React . Node ,
1719| } ;
1820
1921type State = { |
20- unreadCount : number ,
22+ notificationsObjects : Array < NotificationProps > ,
2123| } ;
2224
2325type subNavItem = { |
@@ -118,37 +120,6 @@ const navBarItems: Array<navItem> = [
118120 } ,
119121] ;
120122
121- const notificationsObjects = [
122- {
123- avatarURL : "demo/faces/male/41.jpg" ,
124- message : (
125- < React . Fragment >
126- < strong > Nathan</ strong > pushed new commit: Fix page load performance
127- issue.
128- </ React . Fragment >
129- ) ,
130- time : "10 minutes ago" ,
131- } ,
132- {
133- avatarURL : "demo/faces/female/1.jpg" ,
134- message : (
135- < React . Fragment >
136- < strong > Alice</ strong > started new task: Tabler UI design.
137- </ React . Fragment >
138- ) ,
139- time : "1 hour ago" ,
140- } ,
141- {
142- avatarURL : "demo/faces/female/18.jpg" ,
143- message : (
144- < React . Fragment >
145- < strong > Rose</ strong > deployed new version of NodeJS REST Api // V3
146- </ React . Fragment >
147- ) ,
148- time : "2 hours ago" ,
149- } ,
150- ] ;
151-
152123const accountDropdownProps = {
153124 avatarURL : "./demo/faces/female/25.jpg" ,
154125 name : "Jane Pearson" ,
@@ -166,11 +137,47 @@ const accountDropdownProps = {
166137
167138class SiteWrapper extends React . Component < Props , State > {
168139 state = {
169- unreadCount : 2 ,
140+ notificationsObjects : [
141+ {
142+ unread : true ,
143+ avatarURL : "demo/faces/male/41.jpg" ,
144+ message : (
145+ < React . Fragment >
146+ < strong > Nathan</ strong > pushed new commit: Fix page load performance
147+ issue.
148+ </ React . Fragment >
149+ ) ,
150+ time : "10 minutes ago" ,
151+ } ,
152+ {
153+ unread : true ,
154+ avatarURL : "demo/faces/female/1.jpg" ,
155+ message : (
156+ < React . Fragment >
157+ < strong > Alice</ strong > started new task: Tabler UI design.
158+ </ React . Fragment >
159+ ) ,
160+ time : "1 hour ago" ,
161+ } ,
162+ {
163+ unread : false ,
164+ avatarURL : "demo/faces/female/18.jpg" ,
165+ message : (
166+ < React . Fragment >
167+ < strong > Rose</ strong > deployed new version of NodeJS REST Api // V3
168+ </ React . Fragment >
169+ ) ,
170+ time : "2 hours ago" ,
171+ } ,
172+ ] ,
170173 } ;
171174
172175 render ( ) : React . Node {
173- const unreadCount = this . state . unreadCount || 0 ;
176+ const notificationsObjects = this . state . notificationsObjects || [ ] ;
177+ const unreadCount = this . state . notificationsObjects . reduce (
178+ ( a , v ) => a || v . unread ,
179+ false
180+ ) ;
174181 return (
175182 < Site . Wrapper
176183 headerProps = { {
@@ -194,10 +201,24 @@ class SiteWrapper extends React.Component<Props, State> {
194201 notificationsTray : {
195202 notificationsObjects,
196203 markAllAsRead : ( ) =>
197- this . setState ( { unreadCount : 0 } , ( ) =>
198- setTimeout ( ( ) => this . setState ( { unreadCount : 4 } ) , 5000 )
204+ this . setState (
205+ ( ) => ( {
206+ notificationsObjects : this . state . notificationsObjects . map (
207+ v => ( { ...v , unread : false } )
208+ ) ,
209+ } ) ,
210+ ( ) =>
211+ setTimeout (
212+ ( ) =>
213+ this . setState ( {
214+ notificationsObjects : this . state . notificationsObjects . map (
215+ v => ( { ...v , unread : true } )
216+ ) ,
217+ } ) ,
218+ 5000
219+ )
199220 ) ,
200- unread : unreadCount > 0 ,
221+ unread : unreadCount ,
201222 } ,
202223 accountDropdown : accountDropdownProps ,
203224 } }
0 commit comments