-
Notifications
You must be signed in to change notification settings - Fork 832
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add notifications feature * Hide notification on cypress tests * Fix ts errors
- Loading branch information
1 parent
b56d184
commit 761282c
Showing
6 changed files
with
149 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[ | ||
{ | ||
"id": "52f96d17-8316-4fba-bd3e-dfd237c5fb39", | ||
"title": "We plan to significantly improve this package. [Share you thoughts in our survey](https://www.surveymonkey.com/r/5XHDL76)" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import * as React from 'react'; | ||
import ReactMarkdown from 'react-markdown'; | ||
import notifications from '../notifications.json'; | ||
import { useSnackbar } from 'notistack'; | ||
import { makeStyles } from '@material-ui/core'; | ||
|
||
const useStyles = makeStyles({ | ||
notificationContainer: { | ||
'& > p': { | ||
margin: 4, | ||
}, | ||
}, | ||
}); | ||
|
||
export function useNotification() { | ||
const styles = useStyles(); | ||
const { enqueueSnackbar } = useSnackbar(); | ||
|
||
React.useEffect(() => { | ||
// @ts-ignore | ||
if (window.Cypress) { | ||
return; // hide for visual regression and tests | ||
} | ||
|
||
const viewedNotifications: string[] = JSON.parse( | ||
localStorage.getItem('viewedNotifications') || '[]' | ||
); | ||
|
||
const notificationToShow = notifications.find( | ||
notification => !viewedNotifications.some(viewedId => viewedId === notification.id) | ||
); | ||
|
||
if (notificationToShow) { | ||
enqueueSnackbar( | ||
<ReactMarkdown | ||
className={styles.notificationContainer} | ||
source={notificationToShow.title} | ||
/>, | ||
{ | ||
anchorOrigin: { | ||
vertical: 'top', | ||
horizontal: 'center', | ||
}, | ||
} | ||
); | ||
|
||
localStorage.setItem( | ||
'viewedNotifications', | ||
JSON.stringify([...viewedNotifications, notificationToShow.id]) | ||
); | ||
} | ||
}, [enqueueSnackbar, styles.notificationContainer]); | ||
} | ||
|
||
export const NotificationManager: React.FC = () => { | ||
useNotification(); | ||
return null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters