@@ -5,6 +5,8 @@ import makeStyles from '@material-ui/core/styles/makeStyles';
5
5
import Drawer from '@material-ui/core/Drawer' ;
6
6
import Toolbar from '@material-ui/core/Toolbar' ;
7
7
import Divider from '@material-ui/core/Divider' ;
8
+ import Badge from '@material-ui/core/Badge' ;
9
+ import NotificationsIcon from '@material-ui/icons/Notifications' ;
8
10
import IconButton from '@material-ui/core/IconButton' ;
9
11
import MenuIcon from '@material-ui/icons/Menu' ;
10
12
import SvgIcon from '@material-ui/core/SvgIcon' ;
@@ -19,6 +21,7 @@ import ConnectedLinks from './common/connected-links';
19
21
import Footer from './footer' ;
20
22
21
23
import dynamic from 'next/dynamic' ;
24
+ import NotificationPanel , { lastMessageId } from './notification-panel' ;
22
25
const DocSearch = dynamic ( import ( './docsearch' ) , {
23
26
ssr : false
24
27
} ) ;
@@ -121,11 +124,18 @@ const Layout = ({ children }) => {
121
124
const [ open , setOpen ] = useState ( router . pathname !== '/' ) ;
122
125
const [ links , setLinks ] = useState ( { } ) ;
123
126
const searchRef = useRef ( null ) ;
127
+ const anchorRef = useRef ( null ) ;
128
+ const [ openNotification , setOpenNotifiation ] = useState ( false ) ;
129
+ const [ lastCheck , setLastCheck ] = useState ( '' ) ;
124
130
125
131
useEffect ( ( ) => {
126
132
setLinks ( findConnectedLinks ( router . asPath , flatSchema ) || { } ) ;
127
133
} , [ router . asPath ] ) ;
128
134
135
+ useEffect ( ( ) => {
136
+ setLastCheck ( localStorage . getItem ( 'data-driven-forms-last-checked' ) || '' ) ;
137
+ } , [ ] ) ;
138
+
129
139
const handleDrawerOpen = ( ) => {
130
140
setOpen ( true ) ;
131
141
setTimeout ( ( ) => searchRef . current . focus ( ) , 500 ) ;
@@ -135,6 +145,12 @@ const Layout = ({ children }) => {
135
145
setOpen ( false ) ;
136
146
}
137
147
148
+ const handleToggle = ( ) => {
149
+ localStorage . setItem ( 'data-driven-forms-last-checked' , lastMessageId ) ;
150
+ setLastCheck ( lastMessageId ) ;
151
+ setOpenNotifiation ( ! openNotification ) ;
152
+ } ;
153
+
138
154
return (
139
155
< MenuContext . Provider value = { links } >
140
156
< div className = { classes . root } >
@@ -172,6 +188,12 @@ const Layout = ({ children }) => {
172
188
} ) }
173
189
>
174
190
< DocSearch />
191
+ < IconButton aria-label = "show new notifications" onClick = { handleToggle } color = "inherit" ref = { anchorRef } className = { clsx ( classes . menuButton ) } >
192
+ < Badge badgeContent = { lastMessageId - lastCheck } color = "secondary" >
193
+ < NotificationsIcon className = { classes . menuIcons } />
194
+ </ Badge >
195
+ </ IconButton >
196
+ < NotificationPanel isOpen = { openNotification } anchorRef = { anchorRef } onClose = { ( ) => setOpenNotifiation ( false ) } />
175
197
< a href = "https://github.com/data-driven-forms/react-forms" rel = "noopener noreferrer" target = "_blank" >
176
198
< IconButton color = "inherit" aria-label = "gh repository" edge = "start" className = { clsx ( classes . menuButton ) } >
177
199
< SvgIcon >
@@ -180,7 +202,6 @@ const Layout = ({ children }) => {
180
202
</ IconButton >
181
203
</ a >
182
204
</ div >
183
-
184
205
< main
185
206
className = { clsx ( classes . content , {
186
207
[ classes . contentShift ] : open ,
0 commit comments